Advertisement

Rendering lights in deferred shading

Started by May 30, 2018 03:55 PM
10 comments, last by Vilem Otte 6 years, 8 months ago

As title says, what's the go-to method for reducing the number of pixels processed for every light? Tiles don't seem to work well with shadow-casting lights, so I would still need to render them individually.

Basically I have a choice to render a screen-space quad, or a 3D volume.

The quad has to be calculated "manually", which is simple enough for point lights (though still have to be careful if the light is behind the camera), but for spot lights the calculations are much more complex and result in a lot of "wasted" pixels.

Another approach would be to render, say, a box around a point light. But which faces should be rendered? If I only render front faces, it will not work if the box intersects near plane (i.e. light behind camera). If back faces are rendered, it will fail for back plane in the same manner. If both are rendered, then "normal" lights will affect every pixel twice. Is there a good solution for this, aside from using stencils?

An analytical 2D bound would be better than a 3D bounding box: http://research.nvidia.com/publication/2d-polyhedral-bounds-clipped-perspective-projected-3d-sphere This should work for cones lights as well.

The other option is some spatial method, like a 3D grid of froxels and linking lights to it's cells.

I assume the former is more old school when compute shaders were not there yet, but it may depend on the number of lights which is faster.

Advertisement

The usual method is to render spheres for point lights and cone for spotlights. The simplest way is to render backfaces only, but that can result in more pixels being processed than needed. You can disable depth clipping when rendering lights, so you won't have to worry about the backplane. For a more efficient approach, enable the stencil state depth fail operation to only keep fragments that fail the depth test. This means you filter out pixels which are not behind the depth buffer and wouldn't contribute.

You can also try more advanced stencil trickery when the camera is outside the light like described here: https://kayru.org/articles/deferred-stencil/

Out of curiosity how does one "normally" handle shadow mapping with tiled deferred rendering of one of its variants? Can't lights in the light list be marked with what shadow map to use for this light?  I only ask because the OP seems to imply tile deferred isn't compatible with shadow mapping.

-potential energy is easily made kinetic-

1 hour ago, Infinisearch said:

Can't lights in the light list be marked with what shadow map to use for this light?  I only ask because the OP seems to imply tile deferred isn't compatible with shadow mapping.

Yeah, one could use shadow map atlas or array textures or bindless textures to solve this.

Yeah that would handle multiple shadow maps being "bound to the pipeline" at the same time.  But I was referring to how one knows which lights actually have shadows associated with them?  Is the first N lights dedicated to lights with shadow maps?  Or is there a reference to a shadow map per light?

-potential energy is easily made kinetic-

Advertisement
9 minutes ago, Infinisearch said:

Yeah that would handle multiple shadow maps being "bound to the pipeline" at the same time.  But I was referring to how one knows which lights actually have shadows associated with them?  Is the first N lights dedicated to lights with shadow maps?  Or is there a reference to a shadow map per light?

Maybe even using seperate tile lists (and also passes) for shadowed / unshadowed lights makes sense? But as usual, you'll probably have to try out all options to see what's best :|

15 minutes ago, JoeJ said:

Maybe even using seperate tile lists (and also passes) for shadowed / unshadowed lights makes sense? But as usual, you'll probably have to try out all options to see what's best :|

I was just wondering what was commonly used currently...? seeing as how battlefield 3 was the first game with tile deferred, its been around for a while now.

-potential energy is easily made kinetic-

8 hours ago, Infinisearch said:

Out of curiosity how does one "normally" handle shadow mapping with tiled deferred rendering of one of its variants? Can't lights in the light list be marked with what shadow map to use for this light?  I only ask because the OP seems to imply tile deferred isn't compatible with shadow mapping.

You could do it with texture arrays and storing layer indices in light uniforms, but my point was that you probably can't afford to have enough shadow casting lights to warrant using tiled rendering for them. It probably makes more sense to render them in a separate pass.

Oh I had forgot about a presentation I had that might be of interest to you, I'll attach it here since I couldn't find it on the net with a quick google search.  Its a paper on implementing alot of shadows, at the time they were able to get alot of shadow casting light on the geforce titan of the time. (I think thats a kepler based titan, which equates to a 1060 or 1070 nowadays)

The papers the presentation can be found here: http://www.cse.chalmers.se/~uffe/publications.htm

Just search for shadows.

 

a12-olsson.pdf

-potential energy is easily made kinetic-

This topic is closed to new replies.

Advertisement