Sign in to follow this  
Lithic

Variance Shadow Mapping With Expensive Terrain

Recommended Posts

Looking for some advice on shadow mapping algorithms. Currently working on this game, shadowing is a very important visual effect for the planet-based levels. I recently implemented variance shadow mapping with cascaded shadow maps. To my dismay I'm struggling with some awful visual artifacts: I believe the primary cause of this is that I'm not rendering the terrain into the shadow map. While I've found some ways to mask these effects, I have not found a silver bullet and the shadows are often detracting from the visual fidelity of the planet.

 

The terrain is generated from a ridiculous fractal noise equation, thus actually drawing the terrain into the shadow maps is impractically expensive. I suspect due to these issues VSM is ill-suited for my game. Are there similar soft shadow mapping approaches that do not require drawing the terrain into the shadow map that might be better choices?

Share this post


Link to post
Share on other sites

Do you have the terrain represented in any other fashion? EG can you get it into a heightmap?

 

Not at the moment, although i've considered precalculating areas where the player gets close for other reasons.

Share this post


Link to post
Share on other sites

Before doing anything else just draw the terrain to shadow map and see if the artifacts is even related to that. If that fix it then you either need to prebake terrain to some cheaper form or pick some another shadow map algorithm. Personally I have never been satisfied for VSM in real scenes.

Share this post


Link to post
Share on other sites

I've never been able to get VSM to work nicely... It's quick, and it looks nice in theory, but I think you need to have just the right geometry in order not to get strong artifacts.

 

Can you try just regular shadowmapping, maybe with PCF to provide some softness? You shouldn't need to draw your terrain into the shadowmap as long as you clear the shadow map to the "maximum depth value".

Share this post


Link to post
Share on other sites

Instead of using a shadowmap for shadows, you could bake the visibility between the terrain and the main light in an occlusion map. For each texel, cast a ray between the corresponding terrain sample towards the light, and store 0 or 1 depending on whether the ray hits the terrain or not. The intersection code can be optimized in several ways, for instance by precaching the terrain geometry instead of evaluating the fractal function on the fly.

An occlusion map has many advantages: it filters correctly, takes little memory (an 8 bit format is enough), gives you soft shadows for free and it's view independent. Of course you can tweak its resolution depending on your memory and runtime budget.

That's the approach I used more than 10 years ago for shadowing my terrains (on the CPU) and it worked very well. You should be able to prototype it on the GPU rather quickly.

Just an idea!

Share this post


Link to post
Share on other sites

Sorry for the slow response, just got back from my honeymoon!

 

Before doing anything else just draw the terrain to shadow map and see if the artifacts is even related to that. If that fix it then you either need to prebake terrain to some cheaper form or pick some another shadow map algorithm. Personally I have never been satisfied for VSM in real scenes.

 

I switched to ESM and I was able to reduce some artifacts. Even still, the terrain artifact is still there to a lesser degree. Prebaking the terrain is probably a solution, although it introduces a lot of complexity to solve a relatively minor artifact.

 

You shouldn't need to draw your terrain into the shadowmap as long as you clear the shadow map to the "maximum depth value".

 

Already cleared to max depth. The artifact I'm referring to is caused by blurring between max depth and occluders with much lower depth value. A blur with a very large depth difference produces shadows with sharp edges and reduces the ability of the blur kernel to eliminate discretization artifacts. This produces an artifact where shadows that project onto the far plane are sharp and discrete, but the blur antialiasing works well when the shadow is projected onto a non-terrain surface and the shadow edges there are soft.

 

Instead of using a shadowmap for shadows, you could bake the visibility between the terrain and the main light in an occlusion map. For each texel, cast a ray between the corresponding terrain sample towards the light, and store 0 or 1 depending on whether the ray hits the terrain or not. The intersection code can be optimized in several ways, for instance by precaching the terrain geometry instead of evaluating the fractal function on the fly.

An occlusion map has many advantages: it filters correctly, takes little memory (an 8 bit format is enough), gives you soft shadows for free and it's view independent. Of course you can tweak its resolution depending on your memory and runtime budget.

That's the approach I used more than 10 years ago for shadowing my terrains (on the CPU) and it worked very well. You should be able to prototype it on the GPU rather quickly.

Just an idea!

 

Not sure I follow what you're describing, if you could cite a whitepaper perhaps?

 

Another possibility I was looking at was ESSM, looks like it selects the blur kernel sizes variably, perhaps a solution might lie in a soft-shadowing algorithm like that.

Edited by jsuffolk

Share this post


Link to post
Share on other sites


Already cleared to max depth. The artifact I'm referring to is caused by blurring between max depth and occluders with much lower depth value. A blur with a very large depth difference produces shadows with sharp edges and reduces the ability of the blur kernel to eliminate discretization artifacts. This produces an artifact where shadows that project onto the far plane are sharp and discrete, but the blur antialiasing works well when the shadow is projected onto a non-terrain surface and the shadow edges there are soft.

 

Right, but that's only true if you're filtering the shadow map itself. You were asking about alternatives to VSM. It won't be an issue with PCF, where the filtering is done on the results of the depth comparison instead of the depth itself.

Share this post


Link to post
Share on other sites

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