Sign in to follow this  
glmisscelan

Variance Shadow Mapping Acne?

Recommended Posts

Hi, I was trying to implement a simple VSM because i heard that it avoid almost every Shadow Mapping glitches (besides it add others news (light bleding). I fihished a simple implementation a here are the results. When the player is near to light it seems normal: if i move the player away from the light something strange begin to happend. Here is the fragment shader code. First when i stored the moments:
varying vec3 lightVec;

//uniform float far;

void main(void)
{
  
   float lengthlight = length(lightVec)/120.0; //divide by light far to normalize
  
   vec2 fragcomp;
    
   fragcomp.x = lengthlight;
   fragcomp.y = lengthlight * lengthlight;
  
   gl_FragColor = vec4(fragcomp, vec2(0,1));

}




Second when i do the calculus:
uniform sampler2D texture0;
uniform sampler2D texture1;
uniform sampler2D shadowMap;
varying vec4 ecPosition;
varying vec4 lightproj;
//uniform float far;
//uniform float power;
uniform vec3 fpb;
uniform vec3 color;
   
void main(void)
{
        vec3 suma = texture2D(texture0,  vec2(gl_TexCoord[0])).xyz * texture2D(texture1,  vec2(gl_TexCoord[1])).xyz;      
        vec3 pos = lightproj.xyz / lightproj.w;
        vec4 shadmap = texture2D(shadowMap,pos.xy);
   	const float bias = 0.0001;
        float range      = fpb.x; //light far
   	 //get distance
        float lightLen=length(vec3(gl_LightSource[0].position.xyz - ecPosition.xyz)); 

   	//normalizamos la distance
   	float lightDist=(lightLen-bias)/range;
        float epsilon = 0.00001;
        float E_x2 = shadmap.y;
    	float Ex_2 = shadmap.x * shadmap.x;
    	float variance = min(max(E_x2 - Ex_2, 0.0) + epsilon, 1.0);
    	float m_d = (shadmap.x - lightDist);
    	float shadow = variance / (variance + m_d * m_d);
  
   	gl_FragColor= vec4(suma, 1.0) * shadow;
   
}

I can avoid "Acne" if i put lower values for "epsilon" but it reduces "shadow" var to values near 0. Any idea? Thanks in advance.

Share this post


Link to post
Share on other sites
search for threads with Variance Shadow Map in the subject line. There are plenty. Each one deals with light bleeding and depth aliasing errors.

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