I have deferred shading working, and I'm using light volumes to only draw areas that are actually touched by the light sources. However, now I'm looking into adding ambient lighting. Right now, any area not touched by a light volume is completely black, which makes sense. But to add ambient lighting, I'm going to need to render the scene outside of the lights as well.
I assume I will need to add a separate render pass, before the lighting pass, to draw the scene to the screen at a given light level? Or is there a way to add ambient lighting to this sort of deferred shading without an extra pass?
Also, since the lighting stage is blending lit areas onto the backbuffer, won't they appear extra bright if there is already an ambient copy of the scene rendered to the buffer?
I'm unsure if you're using D3D or OpenGL. If you're using D3D, you can clear a render target/surface/resource. (I'm fairly sure there's a feature of OpenGL to do the same.) The clear function also takes in a colour. So, before you render to the light buffer, you could clear the light buffer to your ambient colour. This will have the effect of lighting everything in the scene equally.
Yes, if you're additively blending the lights, the geometry influenced by the lights will get brighter with ambient lighting. If it didn't, the lighting wouldn't look natural.
If you don't want to use the clear method, you could always just render a fullscreen quad (xy -1 -> 1) and output the ambient colour from the pixel shader. This would allow you to apply the ambient lighting at any point in the lighting stage - rather than just the beginning. - However it may require many state changes.
Thanks for the reply. I'm currently using OpenGL. I have tried changing the clear color, but all it does is fill the unlit parts of the scene with a solid color. What I'm looking for is the ability to actually render the entire scene (i.e. the entire diffuse render target) very dimly, so that areas without lighting are still somewhat visible.
The only way I can think to do this so far is to add an extra pass where I output a colorized copy of the diffuse render target to the backbuffer before rendering all of the lights, but I wanted to see if there was a way to do it without the extra pass.
When you're rendering your geometry to the G-Buffer, just bind your lighting render target and render out the ambient lighting contribution along with the other G-Buffer properties. Then you can just sum your dynamic lighting into your lighting render target.