PDA

View Full Version : Slope scale depth bias in OpenGL 3.2 core



somboon
09-25-2010, 03:52 AM
Is it possible to implement slope scale depth bias in OpenGL 3.2 core profile and will it help improve the quality of shadow ?

The thing is I tried to implement shadow map (cascaded) with standard depthmap (GL_DEPTHCOMPONENT32F) as a fall back method when the target machine is not fast enought to use VSM (render 3 split VSM + ping pong blur totally kill the performance).

Since my mesh had many unclosed surface (like leaf,skirt,hair,etc) it not possible to use the render back-face only trick to avoid z fighting.

Also applying too much uniform bias when doing depth comparision will lead to shadow detaching from the ground which I would like to avoid.

Thank in advance

Alfonse Reinheart
09-25-2010, 12:52 PM
Is it possible to implement slope scale depth bias in OpenGL 3.2 core profile

What is a "slope scale depth bias?"

Foobarbazqux
09-25-2010, 03:21 PM
Is it possible to implement slope scale depth bias in OpenGL 3.2 core profile and will it help improve the quality of shadow ?


OpenGL calls it PolygonOffset. Off the top of my head you do something like


glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(someNumber,someOtherNumber);


I vauglely remember reading that glPolygonOffset(0.4,1.0) is a reasonable pair of numbers to start with.

somboon
09-25-2010, 06:39 PM
This is what I am talking about

Quote from "Common Techniques to Improve Shadow Depth Maps" on MSDN website

Slope-Scale Depth Bias

As previously mentioned, self-shadowing can lead to shadow acne. Adding too much bias can result in Peter Panning. Additionally, polygons with steep slopes (relative to the light) suffer more from projective aliasing than polygons with shallow slopes (relative to the light). Because of this, each depth map value may need a different offset depending on the polygon's slope relative to the light.

Direct3D 10 hardware has the ability to bias a polygon based on its slope with respect to the view direction. This has the effect of applying a large bias to a polygon that is viewed edge-on to the light direction, but not applying any bias to a polygon facing the light directly. Figure 10 illustrates how two neighboring pixels can alternate between shadowed and unshadowed when testing against the same unbiased slope.

http://msdn.microsoft.com/en-us/library/ee416324(VS.85).aspx

Look like it Direct3D 10 only for now

NeXEkho
09-26-2010, 03:29 AM
If you wanted this surely you could do it manually in your pixel shader when applying the shadow map? I've been considering making my own squint on the technique using the light distance rather than a depth buffer, should be more accurate and linear.

Foobarbazqux
09-26-2010, 03:24 PM
Look like it Direct3D 10 only for now


I posted a response to this thread yesterday, is it showing up on your computer? This feature is not Direct3D 10 only, it has been in OpenGL in every version from 1.0 to 4.1, it just has a different name Polygon Offset vs. Slope Scaled Bias.

mhagain
09-27-2010, 02:30 AM
Be aware that polygon offset sucks because of a number of factors: The spec allows it to be implementation-dependent (clicky) (http://www.opengl.org/sdk/docs/man/xhtml/glPolygonOffset.xml) so the same values may give different results on different hardware. You may encounter floating point precision problems when moving between 16-bit and 24-bit depth buffers. The depth buffer is non-linear so the same values will give different results at different depths.If you can find values that work well for you, then great, but it's not a general solution and you shouldn't expect it to be one.

somboon
09-27-2010, 05:11 AM
Thank everyone for your answer.

On my HD4670 using "glPolygonOffset(1.0,4096.0)" (taken from NVIDIA cascaded shadowmap source code, doesnt even know what is 4096.0 suppose to mean).

Most of the artifact are gone, except for surface that are dangerously parallel to light view(which I thought those slope scale whatever can autometicly fix).

Still has to be test on my brother GTS250 too, hope the implementation are not much different.

Dark Photon
09-27-2010, 06:54 PM
On my HD4670 using "glPolygonOffset(1.0,4096.0)" (taken from NVIDIA cascaded shadowmap source code, doesnt even know what is 4096.0 suppose to mean).
Check this out:
* http://developer.nvidia.com/object/cedec_shadowmap.html

Description, and recommendation to start with 1.1, 4.0. Tweak to taste. There's also a projection matrix trick that offsets objects ~1 Zbuffer depth unit forward, which gets around PolygonOffset's Achille's Heel (if it even bites you). Pointers:
* http://www.gamedev.net/community/forums/topic.asp?topic_id=335012&whichpage=1%EE%80%8F
* http://www.terathon.com/books/code/Listing9.1.txt
* http://books.google.com/books?id=bfcLeqR...;q=&f=false (http://books.google.com/books?id=bfcLeqRUsm8C&lpg=PP1&dq=Mathematics%20for %203D%20Game%20Programming%20and%20Computer%20Grap hics&pg=PA273#v=onepage&q=&f=false)