Skip to main content
GameDev.net gamedev.net
🔒 Locked

Omnidirectional shadow maps - overlap artifacts

Started by CainitePrince Jul 28, 2009 at 4:03 AM 6 replies 1.9k views
Original Post
CainitePrince
CainitePrince
I'm currently working on shadows for a design application. Users can place lights themselves so that's why I need true omnidirectional shadows. I've currenly implemented midpoint pcf (specific technique may change later) shadow maps treating point lights as 6 spotlights, however I've run into some problems with artifacts. When I write the depth from the light position I'm using the same frustum as the main camera. However this means that the different sides may have some overlapping areas, because the aspect ratio is not equal to 1 and the field of view not necesarily 90 degrees. But I can't set it to these values either, because then I get artifacts because I'm comparing depths from two different frustums. Does anyone have any ideas on how to solve these issues? Greets Floris
Schrompf
Schrompf
Why is the aspect ratio not 1? If you use 6 spotlights, each of them has to cover one side of a cube, so you have a projection matrix with exactly 90° fov and aspect ratio of 1.

If you use PCF on that setup, you'll still get artifacts at the borders of the 6 projections where the sample distribution fetches values from outside the shadow map. That's where you usually switch to a cubemap where the GPU automatically determines which of the six sides to access for a given sample.

For the cubemap case I'd also suggest changing the depth scale to something like squared_length( position - lightpos). For limited-range point lights even fp16 formats have sufficient precision for this metric, and the calculation is quick - it's basically a simple dot().
----------
Gonna try that "Indie" stuff I keep hearing about. Let's start with Splatter.
MJP
MJP
Quote:
Original post by CainitePrince
When I write the depth from the light position I'm using the same frustum as the main camera.

...

Does anyone have any ideas on how to solve these issues?


Sure! Don't use the same frustum as the main camera. You'll always want to create new view and projection matrices for your shadow casters.
CainitePrince
CainitePrince
Quote:
Original post by MJP
Quote:
Original post by CainitePrince
When I write the depth from the light position I'm using the same frustum as the main camera.

...

Does anyone have any ideas on how to solve these issues?


Sure! Don't use the same frustum as the main camera. You'll always want to create new view and projection matrices for your shadow casters.


I don't think you understand :). Of course I'm not using exactly the same view and projection matrices, because then it wouldn't work at all..

Maybe I'm asking the wrong question. What exactly is the consequence if the aspect ratio and the field of view of both the main and the light camera are not the same? When I put the aspect ratio to 1 and the fov to 90 the shadow maps should never overlap, but I still get weird shadows in some places, like some shadows are being stretched out. What then could be the cause of this?

Greets

Floris
Schrompf
Schrompf
Without a fov of 90° and a aspect ratio of 1, cubemap-like shadow will not work. It's as simple as that. There are advanced frustum optimisation techniques that deter from this claim but I'm pretty sure you're not using one of those. Note that this does not affect your main rendering in any way, though - I still haven't understood why you are worrying about this.

You do this:
a) Set up a frustum with fov 90° and an aspect ratio of 1 for rendering each side of the cubemap. Calculate an appropriate view and projection matrix from it. Render into cubemap. Repeat for all 6 sides.

b) Set up the main view's frustum: set fov to whatever you want, aspect ratio to the value from your present rendering resolution. Calculate view and projection matrix from it. Switch to back buffer, render. While you are rendering, you'll need the light's view and projection matrix, though, so don't forget to upload them to your shaders and make proper use of them.


As for your actual problem: post some screenshots. Or try to describe in much more detail a) what you see and b) what you'd expect to see instead.
----------
Gonna try that "Indie" stuff I keep hearing about. Let's start with Splatter.
CainitePrince
CainitePrince
Here's a screenshot of a simple test scene that clearly shows the problem:

Wrong shadows

At the top and bottom are some weird extensions of the shadows. At first I thought this was due to the wrong fov and aspect ratio, but it's something else, because for this test scene the problem persists...

Greets
Schrompf
Schrompf
Just a shot in the blue: this looks like your sampling hits the shadow map border there, and is clamped to it. Therefore you get shadows stretching out like the last valid line of the shadow map...

are you really really sure that you use a 90° angle of aperture? To me it looks like you use less than 90°, and the missing space at the cube's edges is than filled with values from the shadow map borders - texture addressing set to CLAMP, I suppose.
----------
Gonna try that "Indie" stuff I keep hearing about. Let's start with Splatter.
CainitePrince
CainitePrince
Thanks, Schrompf. Your suggestion gave me an idea of where to look for the problem. It turns out that the problem was caused by texture coordinates outside of the 0..1 range.

I solved the problem for the moment, for the next step I'll try using cube maps.

Some objects still suffer from light bleeding, switching to proper dual layered shadow maps should mostly solve this problem I think.

Thanks for the help, I gave you a positive rating..

Greets

Floris

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.