Jump to content

  • Log In with Google      Sign In   
  • Create Account


Ambient lighting with deferred shading


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Nairou   Members   -  Reputation: 418

Like
0Likes
Like

Posted 20 January 2012 - 08:45 AM

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?

Sponsor:

#2 MajorTom   Members   -  Reputation: 714

Like
0Likes
Like

Posted 20 January 2012 - 08:59 AM

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.

Saving the world, one semi-colon at a time.


#3 Nairou   Members   -  Reputation: 418

Like
0Likes
Like

Posted 20 January 2012 - 09:07 AM

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.

#4 MJP   Moderators   -  Reputation: 10223

Like
2Likes
Like

Posted 20 January 2012 - 01:10 PM

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.

#5 Nairou   Members   -  Reputation: 418

Like
0Likes
Like

Posted 20 January 2012 - 02:45 PM

Aha! Perfect, thanks MJP, that's what I was looking for. :)




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS