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