Sign in to follow this  

Basic Shadow Mapping Question

This topic is 2546 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 trying to implement basic shadow mapping for a terrain and of course I am getting alot of artifacts, because terrain is fairly big.
Should I use orthogonal projection instead of perspective projection?
How do I create the orthogonal projection matrix if I want to use it for terrain shadowing.
I also try to understand cascaded shadow maps, does this work with orthogonal projection?
do I need multiple shadow textures or can I pack them together into one texture?
after rendering the shadows maps how do I decide in the shader which texture to use, is there an efficient way of doing this?

Thanks in advance

Share this post


Link to post
Share on other sites
Should I use orthogonal projection instead of perspective projection?

This depends on the light source, if you are trying to represent the sun then yes you should use orthogonal projection.

How do I create the orthogonal projection matrix if I want to use it for terrain shadowing.

You would create it using the appropriate function to create an orthogonal projection matrix. D3DXMatrixOrthoLH if you are using directx would probably be the easiest way.

I also try to understand cascaded shadow maps, does this work with orthogonal projection?

Yes cascaded shadow maps work with an orthogonal projection.

do I need multiple shadow textures or can I pack them together into one texture?
after rendering the shadows maps how do I decide in the shader which texture to use, is there an efficient way of doing this?


This is up to you, you could pack them all into one texture, or into a texture array or upload them as individual shadow maps.

Share this post


Link to post
Share on other sites
Thanks,
Yes I am using directional light which represents the sun and right now I am trying to implement an orthogonal projection based standard shadow mapping, first.
When comparing the value of the shadow map and value calculated in the shader, I have to use an "epsilon bias", right?
I dont know how to choose that bias value.
Can anyone explain this, please?

Thanks

Share this post


Link to post
Share on other sites
I used to use ddx/ddy to calculate the shadow bias based on the surface angle with respect to the light.

Googling "shadow bias ddx" should help.

[Edited by - jameszhao00 on December 24, 2010 6:41:59 PM]

Share this post


Link to post
Share on other sites
Hi,
I think that calculation using ddx/ddy is too expensive. I just wanted to use a constant value too reduce the artifacts.
What I am currently getting as result looks very unnatural. I think I am doing something wrong when creating the projection matrix or when I projecting the shadow map on the terrain surface.

I am using R32F format texture and setting the near clipping plane as far as possible, but still I am getting crappy results.
Any idea how to fix this?

I want to look into cascaded shadow mappig later, but first I need to understand how to do standard orthogonal projected shadow mappig.

Thanks

Share this post


Link to post
Share on other sites
If you can, check out the articles in ShaderX6 and ShaderX7 regarding cascaded shadow maps. There's also a comprehensive sample in the DirectX SDK, as well as a companion article.

But definitely get a single orthographic projection working first before moving on to CSM. The easiest way to do this is to calculate the 8 corners of your view frustum in world space (you can start with the 8 clip-space positions and transform by the inverse of your view * projection), and then fit a bounding sphere to it. Then you just create a "shadow caster camera" for your light source by backing up from the bounding sphere center in the opposite direction of the light source, and then creating a view matrix with a lookAt function using the sphere center as the lookAt point. Then the width and height of your orthographic projection are just 2x your bounding sphere radius.

Share this post


Link to post
Share on other sites
Quote:
Original post by Hiyar
Hi,
I think that calculation using ddx/ddy is too expensive. I just wanted to use a constant value too reduce the artifacts.
What I am currently getting as result looks very unnatural. I think I am doing something wrong when creating the projection matrix or when I projecting the shadow map on the terrain surface.

I am using R32F format texture and setting the near clipping plane as far as possible, but still I am getting crappy results.
Any idea how to fix this?

I want to look into cascaded shadow mappig later, but first I need to understand how to do standard orthogonal projected shadow mappig.

Thanks


@"very unnatural"

Screenshot please :)

Also just a general tip (when I was really new I spent a lotta hours debugging errors caused by this):

If you do mul(vector, matrix) and the matrix has a translation component, don't forget the vector has to be vector(*, *, *, 1). The 1 is required to take the translation into account (If you went 'huh?' do the matrix multiplies out on paper)

Share this post


Link to post
Share on other sites
@jameszhao00
By "very unnatural" I mean there are strong artifacts

@MJP
LookAt point is the sphere center, what is the eyePoint? Is it sphere center + radius * (-lightDirection)?
Maybe I misunderstood, how do I create the view matrix?

Thanks

Share this post


Link to post
Share on other sites
I have this orthographic projection working now.
Now, I am not sure how to split the frustum properly and I also want to avoid branching in the shader if possible.
And currently I am using 4 textures but this not a good idea in my case, because my shader already uses too many texture samplers.
Is there a more efficient way of doing this. I need more details please.

Thanks in advance

Share this post


Link to post
Share on other sites

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