Jump to content
  • Advertisement
Sign in to follow this  
Nairou

Ambient lighting with deferred shading

This topic is 2522 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
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.

D3D9:
http://msdn.microsoft.com/en-us/library/windows/desktop/bb174352(v=vs.85).aspx

D
3D11:
http://msdn.microsof...8(v=vs.85).aspx

OpenGL: (Scroll down to "Clearing")
http://glprogramming.../chapter10.html


Edit: My apologies, I hadn't realised you tagged "GLSL", I'll leave this here though.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!