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?
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?
- 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.