This topic is 4488 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 on other sites

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 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 on other sites
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.

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5
JoeJ
19

• 13
• 10
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632998
• Total Posts
3009808
• ### Who's Online (See full list)

There are no registered users currently online

×