[[Deferred Shading]] is a [[Shading Algorithm]] where, unlike [[Single-Pass Lighting]] or [[Multi-Pass Lighting]], lighting calculations are *deferred* to the end. During the main render pass, each [[Triangle]] stores information required for lighting to individiaul GBuffers. ![[Pasted image 20251020163803.png]] Once each GBuffer is complete, each light calculates its strength per pixel, resulting in the final texture which is the sum of all lights. ![[Pasted image 20251020163918.png]] This benefit of this method of shading is that only [[Fragment|fragments]] displayed on the screen (eg. not being obscured) have expensive lighting calculations performed on them. This method of shading allows for a significantly bigger cap of how many lights you can have in a scene. The complexity of this is $O(M+N)$ where $M$ is the number of objects and $N$ is the number of lights. >[!tip] P-Buffer >'*P-buffer*' is a term reserved for the final pixel buffer, while 'G-Buffer' is a Geometry buffer to store render target textures & light info. ### Stages The main stages in a [[Deferred Shading|deferred shader]] are: - Geometry Stage - Lighting stage - Post-procesing stage