Sign in to follow this  

issue with shadows

Recommended Posts

hello, I am using variance shadow mapping but I get this artifact that a shadow area close to the ocluder is lighter then shadow area far behind the occluder. this is the shader(I use ortho projection so I scale fragment postion from -1,1 to 0,1):
float VSM_FILTER( vec2 moments, float fragDepth )
float lit = 0.0;
float E_x2 = moments.y;
float Ex_2 = moments.x * moments.x;
float variance = E_x2 - Ex_2;
float mD = moments.x - fragDepth;
float mD_2 = mD * mD;
float p = variance / (variance + mD_2);
lit = max( p, float(fragDepth <= moments.x) );
return lit; 
void main()

   float fNDotL           = max(dot( normal, lightDir ),0.0); 
   float dis = length(;
   vec3 flightDir1 = normalize(;
   float fNDot1=0.0;
   if (u_light1)
     fNDot1 = max(dot( normal, flightDir1 ),0.0); 

   float dis2 = length(;
   vec3 flightDir2 = normalize(;
   float fNDot2=0.0;
   if (u_light2)
     fNDot2 = max(dot( normal, flightDir2 ),0.0); 

   vec4 fvDiffuseA = texture2D( baseMap, Texcoord );
   vec4 fvDiffuseB = texture2D( baseMapB, Texcoord );
   vec4 fvDiffuseC = texture2D( baseMapC, Texcoord );
   vec4 fvDiffuseD = texture2D( baseMapD, Texcoord );

   vec4 fvDiffuse = fvDiffuseA*vcolor.x+fvDiffuseB*vcolor.y+fvDiffuseC*vcolor.z+fvDiffuseD*vcolor.w;
   float curr = max(fNDot1,fNDotL);
   curr = max(curr,fNDot2);

   vec2 depthcoord = (positionlghtsp.xy+1.0)*0.5;
   float dp = 1.0;

 float m1 = texture2D( depthMap, depthcoord ).r;
 float m2 = texture2D( depthMap, depthcoord ).g;
float dist = (positionlghtsp.z+1.0)*0.5-0.001;
dp=VSM_FILTER( vec2(m1,m2), dist );

   vec4  fvTotalDiffuse   = dp * curr * fvDiffuse; 
   fvTotalDiffuse.w = 1.0;
   gl_FragColor =  fvTotalDiffuse  ;

I get correct shadows without VSM so the vertex shader is not relevant

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this