Fast way to clip non lit pixels in a lightvolume


currently I’m working on a deferred shader engine with dynamic pointlights. To reduce fragment shader invocations I use stencil lightvolumes. However the result shows many lit pixels in areas where the light is completely occluded (below screenshot shows the geometry inside a lightvolume. The lightsource is the red torch. There is light on fragments where it shouldn’t be obviuously.). What is the fastest way to reject fragments that are facing away or are in front of a pointlight source?

I guess I have to apply some sort of shadowmapping from the viewpoint of the lightsource. Or is there a better faster way with the approach described above?


Any thoughts?

Yup, shadowmapping, e.g.

…for point-lights, the easiest is the use a depth-cubemap… slightly harder is doing a dual-paraboloid shadowmap…

Making it fast from there is all pain and suffering for eternity, or a lucrative authorship depending on how you look at it :slight_smile:

Yeah I thought so. found a nice tutorial also
But I’m a little fuzzy on how to combine the shadow cubemaps with deferred stencil lighting.

I guess I have to do the shadowmapping first and in a subsequent pass and sampling the shadow depthbuffer when rendering the pointlight stencil volumes, right?

The basic algorithm goes like this this:

- draw all opaque geometry to gbuffer
- for each light
  - draw all geometry to shadow map
  - draw light volume

In other words, deferred is great for lots of lights but you lose much of that advantage as soon as you start adding shadows, particularly if you want a general-purpose lighting setup where you have lots of lights and each light must cast a shadow.

Shadow mapping is very much it’s own world of pain, and you’ll find yourself spending lots of time tweaking depth bias values and making fine adjustments to shadow map size. The reality is that we just don’t have a 100%-robust-works-all-the-time-and-runs-fast general-purpose lighting and shadowing solution. The whole thing is crutched-up by a bunch of tweaks, approximations and trade-offs, and even the best lighting engines make compromises. The trick is to find the set of compromises that work well for you.