• Advertisement
Sign in to follow this  

issue with shadows

This topic is 3268 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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(lightDir1.xyz);
   vec3 flightDir1 = normalize(lightDir1.xyz);
   float fNDot1=0.0;
   if (u_light1)
     fNDot1 = max(dot( normal, flightDir1 ),0.0); 

   float dis2 = length(lightDir2.xyz);
   vec3 flightDir2 = normalize(lightDir2.xyz);
   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
Sign in to follow this  

  • Advertisement