r/GraphicsProgramming • • Jul 19 '24

Deferred rendering with 1500 lights.

162 Upvotes

25 comments sorted by

16

u/gomkyung2 Jul 19 '24

I’ve created a minimal deferred rendering demo using Vulkan (no loading any models or textures). Vulkan’s sophisticated and explicit resource management ensures that G-buffer memory consumption is incredibly low! I’ve uploaded the source code and detailed explanations of the render pass, including data flow visualizations, to my GitHub repository. Feel free to check it out!

2

u/TomClabault Jul 19 '24

Can you explain why memory usage is very low for the g buffer even though your g buffer has at least positions and normals (which should be float3 * 2 * image size bytes right?).

How does it work in Vulkan?

2

u/gomkyung2 Jul 19 '24

I am assuming the TBGPU environment for everything I am about to say.

After passing through the vertex shader, the rasterized fragments are divided into very small tiles (4x4 to 16x16 AFAIK) by the tiler. The fragment shader processes these tiles. Since it processes only one tile at a time, the GPU can allocate an image corresponding to the size of the tile, rather than the entire size of the attachment, and reuse it for each tile.

Maybe https://github.com/KhronosGroup/Vulkan-Samples/blob/main/samples/performance/subpasses/README.adoc#transient-attachments this article will help you

1

u/TomClabault Jul 19 '24

Hummm makes sense I see. That's nice!

1

u/Public-Slip8450 Jul 19 '24

If u didn’t load any models or textures where’s the spheres coming from the shader?

3

u/gomkyung2 Jul 19 '24

Sorry for the inaccurate explanation. What I mean was no runtime model (like obj or gltf) loading. Sphere vertices and indices are embedded as array in meshes.cppm file.

1

u/Public-Slip8450 Jul 19 '24

Ahhh gotchu!

2

u/Ershany Jul 19 '24

Awesome resource!

5

u/ImrooVRdev Jul 19 '24

Not casting shadows, or is it too many lights to see any shadows?

7

u/gomkyung2 Jul 19 '24

I didn't implement the shadow rendering. I think the conventional shadow mapping for many lights scene is infeasible.

2

u/EclMist Jul 19 '24

Time to implement ReSTIR DI!

2

u/TomClabault Jul 19 '24

This.

For many light rendering, ReSTIR DI is the state of the art.

1

u/The__BoomBox Jul 20 '24

Why aren't shadows a natural consequence of deferred lighting though? We initially start out with a dark scene and then light it up with lights right?

Whatever remains are the shadowed regions right?

3

u/Schnauzercorp Jul 20 '24

The deferred pass only knows the position of the light , the position of the fragment being rendered, and the direction it’s facing in. need more than that to know if there’s a shadow caster blocking between the surface and the light.

1

u/The__BoomBox Jul 20 '24

Oh right, forgot about that ty!

0

u/[deleted] Jul 19 '24

[deleted]

4

u/gomkyung2 Jul 19 '24

Although this video shows all 1,500 light sources, the number of light sources visible within the user’s view frustum in most rendering scenes is limited. Deferred rendering effectively reduces computation by removing lights that do not affect the view. This can also be achieved with forward plus rendering. Deferred rendering handles this in the graphics pipeline, while forward plus handles it in the compute pipeline.

Additionally, the G-buffer used in deferred rendering is utilized in post-processing stages such as SSAO (Screen Space Ambient Occlusion).

4

u/Botondar Jul 20 '24

Not that I agree with the original commenter (even though they deleted it, I can imagine what they said), but you're conflating material evaluation strategies with accelerating (culling/binning) the shading. The two are independent and you can mix and match them in many ways.

Forward/Deferred/Visibility rendering are simply different ways of decoupling the material evaluation from the shading evaluation.

  • With forward rendering there's no decoupling,

  • with deferred you first evaluate the materials for each visible pixel and then only do the shading on that,

  • and with visibility rendering you first evaluate which triangle/instance belongs to which pixel, and only do the material and shading evaluation on those.

Notice how all this deals with is what geometry/triangles and fragments to evaluate the material and shading on, and not which light sources should participate in the shading. For the latter you also have multiple options such as:

  • using proxy geometries - which is what your demo does, and is mostly suited for deferred, but can be used with visibility rendering,

  • tiled/clustered light binning - which can be used with all three rendering strategies,

  • only submitting light sources together with a mesh whose bounding volume intersect the mesh's bounding volume - which is forward only

  • Redrawing (parts of) the scene for each light sources using the scissor rectangle to cull pixels that can't be affected by the light - which is the cousin of using proxy geometries, but for forward rendering specifically.

Obviously all of these techniques and their combinations have different tradeoffs, and some of them aren't viable with today's triangle and light counts, but I thought I'd give them as examples to highlight that the shading evaluation and the lighting acceleration make up two separate parts of a renderer's architecture.

14

u/obp5599 Jul 19 '24

Pack it up boys (every major game engine) some random on reddit says deferred rendering is stupid. No need to be an asswipe brother

2

u/Reaper9999 Jul 19 '24

(every major game engine)

Except idTech actually, they don't use deferred (well, deferred lighting at least, idTech 6 has some g-buffers, idTech 7 has none AFAIK).

1

u/obp5599 Jul 19 '24

I did a gpu capture on Doom Eternal around when it came out in 2020 and I thought I remembered seeing a gbuffer but I could be wrong here since it was awhile ago

2

u/moonshineTheleocat Jul 19 '24

Doom Eternal doesn't use a deferred renderer. Its forward. But it does use a lightweight gbuffer for Z-prepass, mesh-decal IDs, and velocity for motion blur.

After that they shade via forward.

https://simoncoenen.com/blog/programming/graphics/DoomEternalStudy

0

u/[deleted] Jul 19 '24

[deleted]

5

u/obp5599 Jul 19 '24

Every game from EA in the last 10 years uses a modified deferred pipeline or forward+. It also changes per platform. Unreal defaults to it as well on lower end platforms with lumen disabled

0

u/[deleted] Jul 19 '24

[deleted]

2

u/[deleted] Jul 19 '24 edited Jul 19 '24

[removed] — view removed comment

1

u/moonshineTheleocat Jul 19 '24

Both has pros and cons.

Forward tends to better for lower memory bandwidths and cost at the cost of register pressure. But it makes handling decals and screen space techniques trickier.

Deferred has easier screen space techniques. But has a massive increase in memory consumption and bandwidth