View Full Version : Intermediate lighting buffer for deferred shading

12-18-2008, 01:06 PM
Ive read various papers on deferred shading, some blend lighting directly into back buffer, others build a summed lighting buffer to be used later in post processing, plus an additional specular buffer.

What are some options for providing these intermediate lighting buffers when using a framebuffer object gbuffer, assuming the gbuffer already has a depth texture, and 3 - 4 render targets attached and being used. I ask because the number of fullscreen texture buffers seems to be mounting the more I read, which obviously gets worse as the screen res goes up.

DepthTexture, RenderTexture0, RenderTexture1, RenderTexture2, RenderTexture3, SummedLightingTarget, SpecularLightingTarget

Would it be an expensive operation to detach a couple of the gbuffer rendertextures temporarily and replace them with lighting textures to fill? Then reattach the orginal buffers.
Or would it make more sense to use a entirely different FBO for the intermediate lighting? Or something else?

12-18-2008, 04:43 PM
Yea you need like 4-5 textures, but i am not sure you need a specular accumulation buffer, instead use a fp16 lighting accumulation buffer and use any values above 1.0f as it's own color when multiplying with the albedo.
kinda like this(i have never tested this though).

Anyway as i said, i find it better do use a lightaccum FBO instead of the backbuffer, mainly because of post processing.

Also to your last point, you would still have to switch the rendering target in order to use these buffers as textures, so why detach individual ones when you could use something new.

12-19-2008, 03:58 PM
Thx, now I see that I will have to extend the process to use more targets if I want to do any extra post processing, which I will probably use another FBO for.
I have read numerous times floating point blending cant be done, when does this specifically become a problem? I ask because an optimization for adding up the lighting contribution is done using blended screen quads with a stencil buffer attached to isolate the area affected. If the FBO target is a 16 or 32 float target (kinda like what was suggested in the last post), does that mean blending cant be done? Which means all the lights would have to be summed in one shader which would make the limit 8, which would kinda defeat the purpose of deferred shading...

12-20-2008, 04:56 AM
Floating point blending CAN be done but only on newer cards. The first cards that supported floating point render targets were those SM 2.0 cards (Radeon 9700 series, GeForceFX series). For deferred shading with HDR you'll need floating point blending so you must use a SM 3.0 or later card (Radeon X1000 series, GeForce 7 series) as I know. For SM 2.0 cards you must forget HDR or you should use a specular render target as you said, but the later is only hacking.