1// Fragment shader for 2D texture with shadow attenuation 2// Brian Paul 3 4 5uniform sampler2D tex2d; 6uniform vec3 lightPos; 7 8void main() 9{ 10 // XXX should compute this from lightPos 11 vec2 shadowCenter = vec2(-0.25, -0.25); 12 13 // d = distance from center 14 float d = distance(gl_TexCoord[0].xy, shadowCenter); 15 16 // attenuate and clamp 17 d = clamp(d * d * d, 0.0, 2.0); 18 19 // modulate texture by d for shadow effect 20 gl_FragColor = d * texture2D(tex2d, gl_TexCoord[0].xy, 0.0); 21} 22