stk-code_catmod/data/shaders/pointlight.frag
vincentlj 45db87de8a Merge normals and depth RTT into a single one
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@14754 178a84e3-b1eb-0310-8ba1-8eac791a3b58
2013-12-23 16:59:55 +00:00

37 lines
856 B
GLSL

uniform sampler2D ntex;
uniform vec3 center;
uniform vec3 col;
uniform float r;
uniform float spec;
uniform vec2 screen;
uniform mat4 invproj;
void main() {
vec2 texc = gl_FragCoord.xy / screen;
float z = texture2D(ntex, texc).a;
vec4 xpos = 2.0 * vec4(texc, z, 1.0) - 1.0f;
xpos = invproj * xpos;
xpos /= xpos.w;
float d = distance(center, xpos.xyz);
if (d > r) discard;
float att = 1.0 - smoothstep(0.0, r, d);
vec3 norm = texture2D(ntex, texc).xyz;
norm = (norm - 0.5) * 2.0;
// Light Direction
vec3 L = normalize(xpos.xyz - center);
vec3 eyedir = normalize(xpos.xyz);
vec3 H = normalize(-L + eyedir);
float NdotL = max(0.0, dot(norm, -L)) * att;
float NdotH = max(0.0, dot(norm, H));
NdotH = pow(NdotH, spec);
NdotH += 0.05; // offset so that the alpha test doesn't kill us
gl_FragColor = NdotL * vec4(NdotL * col, NdotH);
}