stk-code_catmod/data/shaders/objectpass_rimlit.frag
auria 118705f19a Apply patch by Vlj to put normals in eyespace coordinates and reenable normal mapping, thanks!
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@14737 178a84e3-b1eb-0310-8ba1-8eac791a3b58
2013-12-19 00:13:17 +00:00

47 lines
985 B
GLSL

#version 130
uniform sampler2D tex;
uniform float far;
uniform int hastex;
uniform float objectid;
noperspective in vec3 nor;
noperspective in vec3 eyenor;
noperspective in vec3 viewpos;
const float near = 1.0;
vec4 encdepth(float v) {
vec4 enc = vec4(1.0, 255.0, 65025.0, 16581375.0) * v;
enc = fract(enc);
enc -= enc.yzww * vec4(1.0/255.0, 1.0/255.0, 1.0/255.0, 0.0);
return enc;
}
void main() {
float linear_z = (2.0 * near) / (far + near - gl_FragCoord.z * (far - near));
// Tune for better inside range without losing outdoors
linear_z *= 2.0;
float rim = 1.0 - dot(eyenor, viewpos);
rim = smoothstep(0.5, 1.5, rim) * 0.35;
if (hastex != 0) {
vec4 col = texture2D(tex, gl_TexCoord[0].xy);
if (col.a < 0.5)
discard;
col.xyz += rim;
gl_FragData[0] = col;
} else {
gl_FragData[0] = gl_Color + vec4(vec3(rim), 0.0);
}
gl_FragData[1] = vec4(0.5 * normalize(nor) + 0.5, linear_z);
gl_FragData[2] = vec4(encdepth(gl_FragCoord.z).xyz, objectid);
}