Jump to content
  • Advertisement
Sign in to follow this  
Guoshima

Shadow projection question

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

Hello, I have perhaps a stupid question about the clipping which happens during my shadow pass for a directional light, because of near clipping. When I try to create a rather detailed shadow map for the object close to the camera, I try to offset the camera from where I render my shadow map as least as possible (to preserve some depth accuracy, which is very important for VSM to not have to much light bleeding). The problem is of course that I can cull the objects which are not onscreen but casting shadows correctly (trees, mountains, ..), but during the rendering, parts of the objects are culled away because they are in front of the near plane. Isn't it possible to simple clamp all the vertices which are in front of the near plane to depth 0 or something .. this would really help me out here Regards, Kenzo

Share this post


Link to post
Share on other sites
Advertisement
hmm, nodody has any clues about this :(

I just tried something but it didn't really work out as I expected, but this should have worked .. at least I though so.

When I have created the camera from where I want to render my shadow map, I calculate the near plane with the normal and distance (normal being my lightdir), and set this float4 as a global shader variable.

Then in my vertex shader I perform a dot with my position in worldspace and the plane data. This gives me the distance to the near plane. If the vertex is behind the near plane I add the distance multiplied with the normal to the world position, to move my vertex "in front of" the near plane. Like this it shouldn't be culled.

But euh .. this doesn't work. Any ideas on this

Regards,
Kenzo

Share this post


Link to post
Share on other sites
If you're not using the non-linear "z" value for your VSM depth metric, where you put the near and far planes while rendering the shadow map is largly irrelevant. You don't *have* to scale [near, far] into [0, 1]... you can easily put [0, far] into [0, 1] for example in your variance shadow map.

Thus you can make your near plane closer and as long as you're using a suitably high precision DEPTH buffer, you'll probably be fine.

The only other real option is to create geometry near plane "caps" as is done in some implementations of shadow volumes... but this is kind of ugly and part of the reason why shadow volumes suck ;)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
For shadow maps using an orthographic projection (such as directional lights), you can simply clamp the Z value to 0 in the vertex shader. That way you don't need to worry about adjusting the near or far planes to include all the geometry casting shadows onto the view frustum.

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!