Home | History | Annotate | Download | only in shaders
      1 #ifdef GL_ES
      2 precision highp float; 
      3 #endif
      4 
      5 varying vec4 v_lightSpacePosition;
      6 varying vec4 v_color;
      7 
      8 uniform sampler2D s_shadowMap;
      9 
     10 float unpack(vec4 packedZValue)
     11 {	
     12 	const vec4 unpackFactors = vec4( 1.0 / (256.0 * 256.0 * 256.0), 1.0 / (256.0 * 256.0), 1.0 / 256.0, 1.0 );
     13 	return dot(packedZValue,unpackFactors);
     14 }
     15 
     16 float getShadowFactor(vec4 lightZ)
     17 {
     18 	vec4 packedZValue = texture2D(s_shadowMap, lightZ.st);
     19 	float unpackedZValue = unpack(packedZValue);
     20 	return float(unpackedZValue > lightZ.z);
     21 }
     22 
     23 void main(void) 
     24 {	
     25 	float shadowFactor=1.0;				
     26 	vec4 lightZ = v_lightSpacePosition / v_lightSpacePosition.w;
     27 	lightZ = (lightZ + 1.0) / 2.0;
     28 	shadowFactor = getShadowFactor(lightZ);	
     29 	gl_FragColor = v_color * shadowFactor;
     30 }