r/GraphicsProgramming • u/miki-44512 • 23h ago
Question Do you really need g-buffer in your renderer?
Hello everyone hope you have a lovely day.
I was Reading learnopengl ssao chapter to support ambient occlusion after setting up my pbr renderer, but the one thing I found very strange was that It used g-buffer in this tutorial, I don't use g-buffer or deferred rendering technique in my renderer I use clustered forward+ rendering technique so I didn't need the g-buffer.
And Here I started to ask myself this question, Is there on the long run any advantage of implementing g-buffer? like really do I need it?
Does any strong engine like unreal or unity use g-buffer?
Thanks appreciate your help and your time!
21
u/aleques-itj 23h ago
You don't NEED it but I think it's generally cleaner and often convenient IMO, like you just found out with SSAO.
Forward can get a little awkward and you wind up reimplementing some stuff that kind of just easily falls out of deferred. And you usually wind up eating another geometry pass as well.
20
u/obp5599 23h ago
You need a gbuffer to do deferred rendering. Thats basically it. It depends on the needs and goals of your renderer/engine.
Unreal is deferred, not sure about unity since i don't work in it
8
10
u/sirpalee 23h ago
There are techinques that depend on a full or partial g-buffers. If you are not using any of them, then no, you don't need a g-buffer and it doesn't make sense to build one.
The issue with SSAO that it typically requires normal and depth information and should not multiply lighting contributions. If you are doing depth prepass, then that should be enough.
1
u/EC36339 22h ago
I asked a similar question a while ago and got some interesting answers. You may want to have a look at the replies here:
0
u/miki-44512 22h ago
Sorry to ask I have read many comments just quickly but I got lost now 😂
Like unreal use deferred, but it costs a lot of memory, but not many people are talking about clustered forward, what is the caveat of using clustered forward+? Is there any thing I'm missing regarding gbuffer like does it provide an optimization I'm not aware of because I feel it is just a waste of a render cycle for rendering positions and all other informations and then passing it again to the last pipeline, while you could use it directly in one feel swoop with clustered rendering, or am I missing something?
3
u/NorberAbnott 20h ago
The problem with trying to do SSAO in a forward renderer is that part of the technique wants to look at nearby pixels in a certain radius for the depth and maybe normal information but that is simply information you don’t have access to in a fragment shader unless you do something like depth prepass which submits your geometry twice and is basically a lightweight gbuffer
2
u/MedusaFrontier 19h ago
I've never implemented forward+ but my instincts like the idea of depth pre-pass.
It seems like a very handy buffer to have in several cases.1
u/MidnightClubbed 18h ago
It can be but sending your geometry twice (zprepass and main rendering pass) can also be expensive.
The rasterization pass of nanite is essentially a fat zbuffer prepass (but it writes depth plus geometry data so you dont have to rasterize everything twice).
2
u/EC36339 16h ago
But can't a depth prepass also be used to eliminate geometry (occlusion culling?) and therefore reduce the amount of geometry you have to send in the main pass?
But I guess this matters more in indoor scenes or generally scenes where a small number of objects occlude large numbers of objects?
2
u/MidnightClubbed 14h ago
Yes but it doesn’t occlude the geometry in the prepass!  Traditionally a prepass would lay down the depth then you would re-render with z compare set to equals (and full materials) and only the rendered pixels would run their fragment shaders.  This falls apart when you have a lot of materials, or a lot of geometry (everything up to running the fragment shaders is still happening).
So then using a z buffer prepass to cull draws using compute shaders to process the depth and drive draw indirect calls became popular. Â
If you look at state of the art commercial games they are likely not doing a depth prepass, instead they are reprojecting the previous frame’s depth and conservatively culling draws based on that.  Nanite does this for its geometry pass (depth+triangleid) and I believe some games are doing similar for their forward+ renderers (maybe idtech?)
0
2
u/MedusaFrontier 19h ago edited 19h ago
Deferred and Forward+ are approaches to handling massive numbers of light sources and overdraw. Upsides and downsides exist for both.
A depth pre-pass is needed in Forward+ but that's probably cheaper than the massive GBUFFERSThe part you might be missing.
Forward+ uses less bandwidth and has high Shader complexity and register pressure
Deferred uses more memory or bandwidth, but has ultra high occupancy and layers available for effects.
2
u/cybereality 20h ago
you don't *need* anything, but deferred rendering has many advantages, particularly when you are doing a lot of screen space effects. if you prefer to use forward rendering, and want modern post processing, then you can do a depth prepass (which can also have some performance benefits on it's own) and then reconstruct postion/normals from the depth buffer
1
u/LoneWolf6062 23h ago
A Gbuffer lets you implement screen space effects easier, although you could always approximate normals by reconstructing them from the depth buffer.
Unreal uses deferred rendering by default but does have forward rendering as a fallback and for VR.
1
u/Electromasta 19h ago
Most modern engines used deferred rendering with a gbuffer. Most older engines used forward rendering without.
1
1
u/OkAccident9994 15h ago
UE uses deferred (g-buffer) and Unity may use it if you want.
It is more costly with forward, as you need position + normals (same as g-buffer) to do it - on top pf your forward renderer - but others have done so as well, and there are tricks like a depth pre-pass to get positions, which one can utilize for multiple effects and some optimizations (eg. cull based on visibility using the depth info).
But ssao really is built with deferred in mind.
1
u/Bekwnn 13h ago
Last I checked, most engines (Unreal, Godot, Unity) disable SSAO if you're using their forward rendering modes.
You can technically just pull the depth buffer, delinearize it, and calculate normals from the depth values themselves.
Technically AO is meant to be part of the ambient factor in the lighting equation itself, but if you're doing SSAO as post process, you can sample shadow maps in your SSAO shader and scale how much is applied based on whether a lies in shadow or not.
Still wouldn't necessarily recommend it.
1
u/Rorybabory 1h ago
if you want to do ssao with a clustered forward+ renderer, you can still do it, you just calculate the view space normals based on the depth buffer.
Deferred rendering has its pros and cons, some engines use it some don't. Deferred rendering doesn't handle transparency very well, and you can't really do MSAA. You also run into memory bandwidth issues with the really huge g-buffers, so many games use a very thin g-buffer.
1
•
u/AutoModerator 23h ago
Recently updated rules. Please check that your post is in compliance with Rules 1, 4, 5, and 6 on the sidebar. TL;DR:
No showcases.
Disclose AI usage in post or project.
Present a topic to talk about, e.g. how something works.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.