tavli
diff sdr/shadow.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 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/sdr/shadow.p.glsl Mon Jun 29 01:29:36 2015 +0300 1.3 @@ -0,0 +1,32 @@ 1.4 +/* vi: set ft=glsl */ 1.5 +uniform sampler2D tex; 1.6 +uniform sampler2DShadow shadowmap; 1.7 + 1.8 +varying vec3 vdir, ldir, normal; 1.9 +varying vec4 shadow_tc; 1.10 + 1.11 +#define KD gl_FrontMaterial.diffuse.rgb 1.12 +#define KS gl_FrontMaterial.specular.rgb 1.13 +#define SPOW gl_FrontMaterial.shininess 1.14 + 1.15 +void main() 1.16 +{ 1.17 + float shadow = shadow2DProj(shadowmap, shadow_tc).x; 1.18 + vec4 texel = texture2D(tex, gl_TexCoord[0].st); 1.19 + 1.20 + vec3 n = normalize(normal); 1.21 + vec3 v = normalize(vdir); 1.22 + vec3 l = normalize(ldir); 1.23 + vec3 h = normalize(l + v); 1.24 + 1.25 + float ndotl = max(dot(n, l), 0.0); 1.26 + float ndoth = max(dot(n, h), 0.0); 1.27 + 1.28 + vec3 albedo = KD * texel.rgb; 1.29 + vec3 diffuse = albedo * gl_LightSource[0].diffuse.rgb * ndotl; 1.30 + vec3 specular = KS * gl_LightSource[0].specular.rgb * pow(ndoth, SPOW); 1.31 + 1.32 + vec3 ambient = gl_LightModel.ambient.rgb * albedo; 1.33 + gl_FragColor.rgb = ambient + (diffuse + specular) * shadow; 1.34 + gl_FragColor.a = gl_FrontMaterial.diffuse.a * texel.a; 1.35 +}