Sign in to follow this  
texel3d

Variance Shadow Mapping: gradient color instead of shadows

Recommended Posts

texel3d    156
hi, i try to implement Variance Shadow Mapping in DirectX 9 and i have strange results. As you can see on this picture, the shadow is not 100% dark but it is a gradient of color. http://texelinside.free.fr/bugs/vsm.jpg http://texelinside.free.fr/bugs/vsm2.jpg The more it is far from the shadow caster, the darker it is. Why ? I have read the VSM paper from GPU Gems 3. I am not an expert in math. I have done some research on google and it seems that the smaller the variance is, the higher is the probability to have something equal. Does it mean that the smaller is my variance the higher is my probability to have no shadows ? I think i am wrong but i don't know how to solve my problem and i don't know how to understand what i do not understand ( and what i have to understand ) :( This is my pixel shader to compute the depth maps:
Quote:
void PS_ShadowMap( float4 Depth : TEXCOORD0, out float4 Color : COLOR ) { // Depth is z / w Color.x = Depth.z / Depth.w; Color.y = Color.x*Color.x; Color.z = 0.0f; Color.w = 0.0f; }
Here is my code to compute shadow contribution
Quote:
float g_MinVariance = 0.00002f; float ChebyshevUpperBound( float2 Moments, float t) { float p = ( t <= Moments.x ); float Variance = Moments.y - ( Moments.x * Moments.x ); Variance = max( Variance, g_MinVariance); float d = t - Moments.x; float p_max = Variance / (Variance + d*d); return max(p,p_max); } float ShadowContribution( float2 LightTexCoord, float DistanceToLight) { float2 Moments = tex2D( g_SamplerShadowMap, LightTexCoord ).xy; return ChebyshevUpperBound(Moments,DistanceToLight); } float ComputeShadow( float2 i_TextCoord, float i_ZReceiver) { if( i_TextCoord.x < 0.0f || i_TextCoord.x > 1.0f ) return 1.0f; if( i_TextCoord.y < 0.0f || i_TextCoord.y > 1.0f ) return 1.0f; float2 Moments = tex2D( g_SamplerShadowMap, i_TextCoord ).xy; return ChebyshevUpperBound(Moments,i_ZReceiver); }

Share this post


Link to post
Share on other sites
AndyTX    806
Lower your min variance until you see any speckling artifacts, then raise it ever-so-slightly. Also make sure to keep your light range (near/far) as tight as possible to maximize the utility of the precision in the shadow map.

You also might want to try using a linear depth metric. If you're using a spotlight, try something like length(point_in_view_space) normalized to [0,1]. If you're using a directional light, the normalized view space Z is fine (don't divide by W). In any case make sure that how you compute this depth is consistent between your shadow generation pass and your rendering w/ shadows pass.

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