Advertisement

Depth Fail Stencil Shadow Volume (Carmack's Reverse)

Started by February 18, 2019 06:31 AM
4 comments, last by Vilem Otte 5 years, 10 months ago

I'm adding shadow volume support into my engine (graphics backend written in OpenGL 4.5).

Depth Pass was working fine and to deal with shadows when the camera placed inside a shadow volume - I've decided to use Carmack's Reverse (Depth Fail).

I'm getting weird errors and I wanted to make sure I'm working with a good model (I'm using the Stanford Bunny / Dragon) before I continue to debug my algorithm.

Depth Pass (working fine):
image.png.f96aabb0d3c8f754259e76e3a5eb8311.png

Depth Fail (artifacts):
image.png.5777026fbcfbad98d20295cfec0fce31.png

I then positioned the camera inside the bunny and realized that the artifacts are actually triangles that aren't being culled (they facing the camera and the light source so they shouldn't be culled):
Note: The bunny in this picture is the 2nd bunny behind the one in the previous picture - the camera is inside the first bunny in the picture above!
image.png.0fd7b555d294dfd1e180b77324f68d23.png

I added a simple geom shader to paint front faces in green and back faces in blue. As you can see, This "patch" looks weird as some of the triangles facing the camera and some facing away from it - which might explain the artifact...
image.png.840892d25837396c1204c7d552091d60.png

Maybe the model is incorrect? I'm adding here the gltf I'm using (Bunny.gltf).
Bunny.gltf

I'm using silhouette extrusion to calculate the shadow volumes. I calculate the silhouette by using adjacency triangle toplogy (I'm calculating it once when loading the model) - and find edges that go around the light facing triangles (I'm using face normals for this calculation - I found it to yield better results then interpolated model normals). Would love to hear your thoughts about this method.

Thank you for your help!

As far as i know, this kind of shadow method is pretty obsolete, why didn't you jump into fbo shadow mapping ?

Anyways, i see that normals get corrupted in some ways, and also, you should render backfaces , plus there is the problem of the camera inside the shadow volume itself

Advertisement
On 3/20/2019 at 12:46 PM, Programmer71 said:

As far as i know, this kind of shadow method is pretty obsolete, why didn't you jump into fbo shadow mapping ?

Well, it does have its uses. Zero superpixel aliasing no matter the distance or perspective. The sharpness is realistic if you imagine that we have a dwarf-sized Wolf-Rayet star in place of our sun... Okay, it's not realistic.

Yes your green/blue image looks suspicious... For this technique to work, you need to make sure that all the faces are facing the right way and that the mesh is completely watertight and has no edges where the normal flips.

We would often export a model twice - the normal version of it, and then a slightly different version that would be used for casting shadows...

34 minutes ago, silikone said:

Well, it does have its uses. Zero superpixel aliasing no matter the distance or perspective. The sharpness is realistic if you imagine that we have a dwarf-sized Wolf-Rayet star in place of our sun... Okay, it's not realistic.

I last shipped a game using it in 2014, which is probably more recent than you think ?

We used the stencil technique for sunlight shadows cast by characters. To make them soft, we did a screen-space bilateral blur, tile-culled to only run on 16x16px regions of the screen that contained a shadow. This was cheaper than shadow mapping and didn't have any quality issues regarding resolution, or biasing/acne/peter-panning/etc. We even worked in distance based fading and penumbra sizes too ?

1 hour ago, Hodgman said:

For this technique to work, you need to make sure that all the faces are facing the right way and that the mesh is completely watertight and has no edges where the normal flips.

My memory might not be the best (it's been a long time since I've used shadow volumes), but doesn't z-fail shadow volumes need to also be capped?

To the OP - can you show us how the silhouette and extruded geometry looks like?

My current blog on programming, linux and stuff - http://gameprogrammerdiary.blogspot.com

This topic is closed to new replies.

Advertisement