Jump to content
  • Advertisement
Sign in to follow this  

Variance Shadow Mapping Acne?

This topic is 3889 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

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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!