dbf-halloween2015

view sdr/spot.p.glsl @ 0:50683c78264e

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 01 Nov 2015 00:09:12 +0200
parents
children
line source
1 uniform sampler2D tex;
3 varying vec3 lpos, wpos, vpos, norm, ldir;
5 #define KD gl_FrontMaterial.diffuse.rgb
6 #define KS gl_FrontMaterial.specular.rgb
7 #define LTCOL gl_LightSource[0].diffuse.rgb
9 void main()
10 {
11 vec4 texel = texture2D(tex, gl_TexCoord[0].st);
13 float dist = length(wpos.xz);
14 float spot = 1.0 - smoothstep(4.0, 10.0, dist);
16 vec3 n = normalize(norm);
17 vec3 v = -normalize(vpos);
18 vec3 l = normalize(ldir);
19 vec3 h = normalize(v + l);
21 float ndotl = max(dot(n, l), 0.0);
22 float ndoth = max(dot(n, h), 0.0);
24 vec3 ambient = gl_LightModel.ambient.rgb * texel.rgb;
25 vec3 diffuse = KD * LTCOL * ndotl * texel.rgb;
26 vec3 specular = KS * LTCOL * pow(ndoth, gl_FrontMaterial.shininess);
28 gl_FragColor.rgb = (ambient + diffuse + specular) * spot;
29 gl_FragColor.a = gl_FrontMaterial.diffuse.a * texel.a;
30 }