uniform sampler2D texunit0; uniform sampler2D texunit1; uniform sampler2D texunit2; uniform vec3 lpos; varying vec4 pos; varying vec3 normal; varying vec3 lightVec; varying vec3 viewVec; void main( void ) { float blur_spread[5]; blur_spread[0] = -0.003; blur_spread[1] = -0.001; blur_spread[2] = 0.000; blur_spread[3] = 0.001; blur_spread[4] = 0.003; float samples=1.0/25.0; gl_TexCoord[2] = gl_TexCoord[2]/gl_TexCoord[2].w; gl_TexCoord[2]=(gl_TexCoord[2]+ 1.0) * 0.5; gl_TexCoord[2].z -=0.005; vec4 base = texture2D(texunit0, gl_TexCoord[0].xy); vec3 norm = texture2D(texunit1, gl_TexCoord[0].xy).xyz*2.0-1.0; float shade=0.0; float shadow=0.0; int x=0; int y=0; for(x=0;x<4;x++) { for(y=0;y<4;y++) { shadow = texture2D(texunit2,gl_TexCoord[2].xy+vec2(blur_spread[x],blur_spread[y])); if(shadow > gl_TexCoord[2].z) shade+=samples; } } norm = normalize(gl_NormalMatrix * norm); float fresnel =max((norm.z-0.6)*-1.0,0.0); float diffuse = max(dot(lightVec, norm),0.0); float specular = max(dot(reflect(lightVec,norm), viewVec), 0.0)*1.7; specular=pow(specular,8.0); shade*=diffuse; shade*=0.8; shade+=0.2; gl_FragColor = (base* shade)+(vec4(0.0,0.1,0.3,0.0)*fresnel)+(vec4(0.5,0.5,0.4,0.0)*specular*shade); //gl_FragColor = vec4(pow(length(fwidth(pos).rgb),4.0),0.0,0.0,1.0); //gl_FragColor = vec4(0.0,0.5,1,0.0)*fresnel; //gl_FragColor = base *(shade*diffuse+0.2); }