Sign in to follow this  

ShadowMap problem

This topic is 3598 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 am following the DXSDK ShadowMap Tutorial, how should I remove these banding lines in my shadow map as shown in the image: The banding lines only appear when I use a 3x3 PCF filter. With no filter, the shadow is jagged but looks normal. My shadow map texture is a D3DFMT_R32F and I am storing the depth using the method:
#define SHADOW_EPSILON 0.00005f

void PixelShader (float4 Pos       : TEXCOORD0,
                  out float4 Color : COLOR0)
{
   color = (Pos.z / Pos.w) + SHADOW_EPSILON;
}
edit: something seems wrong with image shack, I can't seems to view the image myself... [Edited by - littlekid on February 8, 2008 2:06:42 AM]

Share this post


Link to post
Share on other sites
PCF exacerbates shadow map biasing issues unfortunately... you'll have to increase your shadow map bias if you increase your PCF filter size. That'll in turn potentially cause "peter pan" artifacts (shadows pulling away from castors) but that's just a disadvantage of PCF.

Share this post


Link to post
Share on other sites
Thanks AndyTX. After reading your post and past topics on VSM by you, I decided to try out with VSM.

However I don't understand what they meant by storing the depth as the linear distance from the light being a better metric?

I am already drawing from the light viewprojection space. Which means my light camera is now at (0.0, 0.0, 0.0). Hence does it mean the z value of a point would be the linear distance from light?


void vs_shadowmap(float3 Position : POSITION0,
out float4 oPosition : POSITION0,
out float oDepth : TEXCOORD0)
{
oPosition = mul(float4(Position, 1.0f), mul(g_World,
g_LightViewProjection));
Depth.x = oPosition.z;
}

void ps_floor_shadowmap(float2 Depth : TEXCOORD0,
out float4 oColor0 : COLOR0)
{
oColor0 = float4(Depth , Depth * Depth , 0.0f, 0.0f);
}


[Edited by - littlekid on February 8, 2008 2:41:59 AM]

Share this post


Link to post
Share on other sites
you output the clip position z value, which is not linear (because of the projection).

what he means is, in pseudo code:


float4 vPosWorld = mul(IN.vPos, matWorld);
float4 vPosLight = mul(vPosWorld , matLightView);

OUT.fDepth = vPosLight.z / fZFarLight;


fZFarLightbeing the max value of Z in light view space.

Hope I helped.

Share this post


Link to post
Share on other sites
Yeah with a spot-light (perspective matrix) I actually use "length(PosInViewSpace)" in the fragment shader as the depth metric, although your mileage may vary with vertex shader linear outputs. With directional (ortho matrix) lights you can just use the "z" output of position directly as it is already linear.

Share this post


Link to post
Share on other sites
Thanks alot to gjaegy and AndyTX, my VSM is currently working however there seems to be some weird artifacts. Portions of the torus that is supposed to be self shadowed is lit-up fully.

http://img209.imageshack.us/my.php?image=vsmnr0.png

I am currenly rendering on a D3DFMT_A32B32G32R32F, with a gaussian blur of the shadow map using a kernel size of 13.

current card GeForce 8500
Texture filter = trilinearly (also tried anisotropic).
NumMultiSamples = 8
MultiSampleQuality = 0

The artifact goes away if I am to create my device without MultiSampleAntiAlias, once I turn it on, the artifact appears.

Another problem that appear is that as I move light higher and higher up, the bottom self shadowed region of the torus have greyish streaks appearing in it

How should I try and eliminate the artifacts? does increasing the VSM_EPSILON helps?

Share this post


Link to post
Share on other sites
That's an odd artifact... rather than using a vsm_epsilon as in the original VSM demo code, try just clamping the minimum variance to a small number before plugging it in to Chebyshev's Inequality (as per the GPU Gems 3 chapter/source). Decrease the clamped value until artifacts appear (surface acne) and then set it somewhere a bit higher.

Share this post


Link to post
Share on other sites
Thanks AndyTX, what do you mean by clamping the minimum variance?

Correct me if I am wrong, did you mean clamp the value at this line:
float Variance = min(max(E_x2 - Ex_2, 0.0f) + LIGHT_VSM_EPSILON, 1.0f);

so i clamp something like:
Variance = clamp(Variance, 0.0f, 0.00001f);

Another thing i noted is, if I rotate my light to shine directly from under the torus, it seems as if there is no occluder and the light would just shine to the other side. Which makes me wonder if there is also problem with my light direction. You can see it in this picture:
http://img120.imageshack.us/img120/1493/vsm3kj9.png

Would you want me to post my shader code for the VSM? I was wondering could the error originate from other place.

Here is a screenshot of the the other greystreaks error that I mentioned:
http://img254.imageshack.us/img254/6320/vsm2je3.png

Share this post


Link to post
Share on other sites
Quote:
Original post by littlekid
Correct me if I am wrong, did you mean clamp the value at this line:
float Variance = min(max(E_x2 - Ex_2, 0.0f) + LIGHT_VSM_EPSILON, 1.0f);

Replace that line with something like:
float Variance = clamp(E_x2 - Ex_2, 0.00001f, 1.0f);

Quote:
Original post by littlekid
Another thing i noted is, if I rotate my light to shine directly from under the torus, it seems as if there is no occluder and the light would just shine to the other side. Which makes me wonder if there is also problem with my light direction.

You'll have to look at your shadow map, etc. to debug that. Ensure that you have a working shadow map implementation before you play with VSM too much as it'll simplify your life. This is as easy as just looking at the simple "df < shadow_map_df" test and disabling all mipmapping, filtering, etc.

I don't have time to go through your code unfortunately, but it shouldn't be too hard to track down what's going on if you look at what's getting rendered into the shadow map, etc.

Just a note that the "grey streak" may be correct for what you're doing. Blurring the shadow map is simulating a simple area light (perceptually, not mathematically) and thus some of the penumbrae is now going to fall on the far side of the torus.

Share this post


Link to post
Share on other sites

This topic is 3598 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.

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