tavli

annotate sdr/shadow-notex.p.glsl @ 18:986c0b76513f

shadows, not completed
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 29 Jun 2015 01:29:36 +0300
parents
children
rev   line source
nuclear@18 1 /* vi: set ft=glsl */
nuclear@18 2 uniform sampler2DShadow shadowmap;
nuclear@18 3
nuclear@18 4 varying vec3 vdir, ldir, normal;
nuclear@18 5 varying vec4 shadow_tc;
nuclear@18 6
nuclear@18 7 #define KD gl_FrontMaterial.diffuse.rgb
nuclear@18 8 #define KS gl_FrontMaterial.specular.rgb
nuclear@18 9 #define SPOW gl_FrontMaterial.shininess
nuclear@18 10
nuclear@18 11 void main()
nuclear@18 12 {
nuclear@18 13 float shadow = shadow2DProj(shadowmap, shadow_tc).x;
nuclear@18 14
nuclear@18 15 vec3 n = normalize(normal);
nuclear@18 16 vec3 v = normalize(vdir);
nuclear@18 17 vec3 l = normalize(ldir);
nuclear@18 18 vec3 h = normalize(l + v);
nuclear@18 19
nuclear@18 20 float ndotl = max(dot(n, l), 0.0);
nuclear@18 21 float ndoth = max(dot(n, h), 0.0);
nuclear@18 22
nuclear@18 23 vec3 diffuse = KD * gl_LightSource[0].diffuse.rgb * ndotl;
nuclear@18 24 vec3 specular = KS * gl_LightSource[0].specular.rgb * pow(ndoth, SPOW);
nuclear@18 25
nuclear@18 26 vec3 ambient = gl_LightModel.ambient.rgb * KD;
nuclear@18 27 gl_FragColor.rgb = ambient + (diffuse + specular) * shadow;
nuclear@18 28 gl_FragColor.a = gl_FrontMaterial.diffuse.a;
nuclear@18 29 }