Sign in to follow this  
cyber_wiz_2007

shadow mapping

Recommended Posts

I have problems with depth biasing on my shadow map. I keep getting either banded circles and rings or shadows appearing in the wrong place - can anyone direct me to a link that shows how this problem is solved?

Share this post


Link to post
Share on other sites
I would check out the numerous threads here. Just search for depth bias or surface acne and you should find what you are looking for. You probably also want to search for variance shadow maps.

Share this post


Link to post
Share on other sites
thanks, the technique I had in mind was a gradient shadow map. heres a section of code that I have been using, its based on the directX sdk:


//transform from RT space to texture space.
float2 ShadowTexC = 0.5 * vPosLight.xy / vPosLight.w + float2( 0.5, 0.5 );
ShadowTexC.y = 1.0f - ShadowTexC.y;

// transform to texel space
float2 texelpos = SMAP_SIZE * ShadowTexC;

// Determine the lerp amounts
float2 lerps = frac( texelpos );

float4 spotlight = tex2D( g_samSpotlight, ShadowTexC );


//
// This ensures that the spotlight faces fowards only
//
if( spotlight.z > vPosLight.z ) spotlight.xyzw= 0.0f;

//
// compute the linearized depth value
//
float depth = (vPosLight.z +fNear) / (fFar-fNear);

//
// compute the shadow map bias
//
SHADOW_EPSILON = fz( depth );

depth -= SHADOW_EPSILON;



however I am not sure about the contents of the function fz().

The problem is that I get surface acne on objects for a large SHADOW_EPSILON setting and shadows that don't appear in the correct place for a different value. Edit: Also if the objects are further away from the light the shadow seems more offset from the correct position, hence the need for a function.
thanks I'll search for gradient shadow maps.

I'll probably attempt to implement variance shadow mapping a bit later, since my first attempt to run the effect in my demo failed.

Share this post


Link to post
Share on other sites
The usual method is to use two parameters: depth bias and slope bias. Basically depth bias is a constant factor offset and slope bias is a multiplier based on the "slope" of the polygon with respect to the depth (i.e. a near-silhouette polygon will have a high value here). It's basically trial and error for your scene though and it's certainly possible to construct a scene that will break any given values.

A decent explanation of the above is found in the GL documentation.

Variance shadow maps help since by adding a small epsilon to the compute variance (rather than the computed depth), one can pretty much fully eliminate surface acne without "pulling the shadows away" from the bases very much - if at all. However VSMs currently have their own set of issues (mainly light bleeding) that may be a problem depending on your scene. Hybrid techniques certainly look promising!

Share this post


Link to post
Share on other sites
Quote:

It's basically trial and error for your scene though and it's certainly possible to construct a scene that will break any given values.


I thought slope scale and depth bias could be tuned in the function fz(...) and silhouette polygons could be handled dynamically.

Quote:

one can pretty much fully eliminate surface acne without "pulling the shadows away" from the bases very much - if at all.


the variance shadow map would solve both problems then ... (edit: next on my todo list).
I wonder if the "light-bleeding" problem could be solved using a depth related function.

My first idea for a hybrid is to implement "percentage closer soft shadows" with variance shadow mapping, and also to revert back to spotlight textures for the pixel shader.

[Edited by - cyber_wiz_2007 on October 1, 2006 6:56:16 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by cyber_wiz_2007
I thought slope scale and depth bias could be tuned in the function fz(...) and silhouette polygons could be handled dynamically.

There's no perfect solution - there's finite precision in the shadow map and a scene can be constructed with arbitrarily large precision requirements, regardless of any depth transformation functions.

Quote:
Original post by cyber_wiz_2007
I wonder if the "light-bleeding" problem could be solved using a depth related function.

It can only be solved with either 1) more information about the depth distribution stored or 2) a hybrid method that falls back on a conservative solution. Chebyshev's inequality is a *tight* upper bound for arbitrary distributions and thus cannot be improved upon with only two moments.

Quote:
Original post by cyber_wiz_2007
My first idea for a hybrid is to implement "percentage closer soft shadows" with variance shadow mapping...

You should be able to do something like that, i.e. #2 above. Seems like a promising approach to me.

Share this post


Link to post
Share on other sites
In addition to aforesaid:
1. Usage of the 'max filter'. After rendering, shadow map postprocessed with the max filter (radius = 1 texel). It's an interesting method, but it has some disadvantages: Decrease of a shadow (one texel) on a silhouette. And small artifacts in 'inner corners'.
2. Instead depth - save more detailed information. For example - save per fragment plane (four coefficients), and using appropriate calculations. It gives good quality, but demands additional memory and more per fragment calculations. (Plane-map shadows).

VSM (or just depth bilinear interpolation) also not completely resolve depth aliasing. It's give false shadowing artifacts in 'inner corners' (in such situations, depth interpolation - incorrect).

Share this post


Link to post
Share on other sites
Quote:
Original post by _sav_
VSM (or just depth bilinear interpolation) also not completely resolve depth aliasing. It's give false shadowing artifacts in 'inner corners' (in such situations, depth interpolation - incorrect).

Maybe I'm just misunderstanding what you're saying, but VSM is not simply "depth bilinear interpolation" - it's probabilistically based and guaranteed to give an upper bound. Simply interpolating depth and comparing is *always* incorrect, not just in "inner corners".

That said, VSM does not completely solve depth biasing issues (as I explained, nothing can as long as we have finite precision :)), but it can easily make it a non-issue in all but the most bizarre cases.

Share this post


Link to post
Share on other sites
Quote:
Original post by AndyTX
Maybe I'm just misunderstanding what you're saying, but VSM is not simply "depth bilinear interpolation" - it's probabilistically based and guaranteed to give an upper bound. Simply interpolating depth and comparing is *always* incorrect, not just in "inner corners".

If forget about 'soft' shadows, - we can simply interpolate depth (no variance calculation). In this case the depth bias issues will be solved identical VSM. You agree?

Quote:

That said, VSM does not completely solve depth biasing issues (as I explained, nothing can as long as we have finite precision :)), but it can easily make it a non-issue in all but the most bizarre cases.

When I speak about VSM problems I do not mean numerical precision (usage small bias for resolve this - not criminally). I mean concrete algorithmic limitations. The example with 'inner corners' - shows it.

Share this post


Link to post
Share on other sites
Quote:
Original post by _sav_
If forget about 'soft' shadows, - we can simply interpolate depth (no variance calculation).

No - interpolating depth without something like the VSM calculations is wrong. In particular, interpolating before doing a depth comparison is incorrect.

Quote:
Original post by _sav_
I mean concrete algorithmic limitations. The example with 'inner corners' - shows it.

I don't know what you mean... VSM doesn't really have any sort of geometry limitations - it's the same as shadow maps that way. Also the currentversions of VSM do not attempt to create plausible soft shadows (although a hybrid that does could be very cool), merely to reduce aliasing.

Share this post


Link to post
Share on other sites
I oppose this statement: interpolation of the depth before comparing helps alot. Tried it, it works well. The problem is that most of the pixel formats you use to store the depth are not interpolated on present graphics hardware. For cube shadow mapping, fixed point 16Bit like G16R16 is fine. For parallel shadow maps the large value range calls for R32F which is not interpolated on any gfx board I know of.

Basic self shadow reason is: you have a depth, it's equal for the whole area of a shadow map texel, the surface influenced by this shadow map texel has different depths. There's no perfect solution to this, but a bias consisting of "constant * distance * (1 / cos( angle))" works well for most cases. The correct geometric formula for a given shadow texel width is "(sin( angle) * width) / cos( angle)" but this still needs some tweaking on the remaining constants.

Bye, Thomas

Share this post


Link to post
Share on other sites
Quote:
Original post by AndyTX
No - interpolating depth without something like the VSM calculations is wrong. In particular, interpolating before doing a depth comparison is incorrect.

Why?

Quote:
I don't know what you mean... VSM doesn't really have any sort of geometry limitations - it's the same as shadow maps that way. Also the currentversions of VSM do not attempt to create plausible soft shadows (although a hybrid that does could be very cool), merely to reduce aliasing.

I tried to illustrate it - http://dl3.ohshare.com/v/6861580/inner_corner_problem.png.html

Share this post


Link to post
Share on other sites
Nice illustration. But self shadowing happens everywhere, not only in the corner. For example, look at one texel on the lower wall. Light comes from above, right side. So every wall part that is on the left of the texel center has a larger depth then the wall at the texel center, thus being shadowed incorrectly. If the shadow depth is interpolated linearly, the sampled depth would increase as well for places left to the texel center, reducing false self shadowing.

Share this post


Link to post
Share on other sites
Quote:
Original post by Schrompf
Nice illustration. But self shadowing happens everywhere, not only in the corner. For example, look at one texel on the lower wall. Light comes from above, right side. So every wall part that is on the left of the texel center has a larger depth then the wall at the texel center, thus being shadowed incorrectly. If the shadow depth is interpolated linearly, the sampled depth would increase as well for places left to the texel center, reducing false self shadowing.

You are right. But interpolation doesn't help in a corner.

Share this post


Link to post
Share on other sites
Quote:
Original post by Schrompf
I oppose this statement: interpolation of the depth before comparing helps alot. Tried it, it works well.

It can "round" the edges of the shadow projection a bit for the reason that you describe, but it doesn't make it more correct. In particular, it is totally improper to interpolate over depth discontinutities in the shadow map (such as object edges). You're now doing a true/false comparison with a spurrious virtual fragment sitting somewhere in space between one occluder and another one. By storing the second moment of the distribution these cases can be properly handled.

Quote:
Original post by Schrompf
Basic self shadow reason is: you have a depth, it's equal for the whole area of a shadow map texel, the surface influenced by this shadow map texel has different depths.

That's correct, although there are numerical precision problems involved too, even with fp32 (hence the constant depth bias). Note that with VSMs you also have the ability to vary the variance of the distribution of a single projected texel (which is in-effect what is happening).

Share this post


Link to post
Share on other sites
Sorry, got on the wrong path here. I was under the impression that the false self shadowing is the problem. Linear interpolation helps there. Meanwhile the thread moved on to Variance Shadow Mapping, which is an entirely different problem and solution, but based on linear interpolation, too. Guess that's where the misunderstanding came from.

Bye, Thomas

Share this post


Link to post
Share on other sites
Quote:
Original post by Schrompf
Sorry, got on the wrong path here.

Maybe I got on the wrong path... in any case, we seem to be on different paths :) I guess the initial thread was about biasing in any case, and someone mentioned VSM as a potential way to solve that. Linear interpolation can also help as you mention. Edges may still be a problem (mathematically), but normally people won't notice what's actually going on.

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