dbf-halloween2015

diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/sdr/spot.p.glsl	Sun Nov 01 00:09:12 2015 +0200
     1.3 @@ -0,0 +1,30 @@
     1.4 +uniform sampler2D tex;
     1.5 +
     1.6 +varying vec3 lpos, wpos, vpos, norm, ldir;
     1.7 +
     1.8 +#define KD	gl_FrontMaterial.diffuse.rgb
     1.9 +#define KS	gl_FrontMaterial.specular.rgb
    1.10 +#define LTCOL	gl_LightSource[0].diffuse.rgb
    1.11 +
    1.12 +void main()
    1.13 +{
    1.14 +	vec4 texel = texture2D(tex, gl_TexCoord[0].st);
    1.15 +
    1.16 +	float dist = length(wpos.xz);
    1.17 +	float spot = 1.0 - smoothstep(4.0, 10.0, dist);
    1.18 +
    1.19 +	vec3 n = normalize(norm);
    1.20 +	vec3 v = -normalize(vpos);
    1.21 +	vec3 l = normalize(ldir);
    1.22 +	vec3 h = normalize(v + l);
    1.23 +
    1.24 +	float ndotl = max(dot(n, l), 0.0);
    1.25 +	float ndoth = max(dot(n, h), 0.0);
    1.26 +
    1.27 +	vec3 ambient = gl_LightModel.ambient.rgb * texel.rgb;
    1.28 +	vec3 diffuse = KD * LTCOL * ndotl * texel.rgb;
    1.29 +	vec3 specular = KS * LTCOL * pow(ndoth, gl_FrontMaterial.shininess);
    1.30 +
    1.31 +	gl_FragColor.rgb = (ambient + diffuse + specular) * spot;
    1.32 +	gl_FragColor.a = gl_FrontMaterial.diffuse.a * texel.a;
    1.33 +}