Jump to content
  • Advertisement
Sign in to follow this  
KaiserJohan

Deferred shading and point lights

This topic is 2144 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'm implementing deferred shading and I'm not sure how to do the deferred shading stage with points lights. After the geometry I have three color buffer attachments for positions, normals and diffuse textures (GL_COLOR_ATTACHMENT_0 - 2). The idea (I believe its called "light volumes"?) is to from the cameras point of view draw actual sphere geometry for each point light in the second pass and then process those fragments and output the combined color from the diffuse buffer with the lighting calculations to some other, final, buffer.

 

Questions:

 

1. Do I need to output from second pass shaders to a "final" color buffer (GL_COLOR_ATTACHMENT_3?), that is then glBlit:ed to the screen?

2. With the above explanation, it is just the fragments that are lit that are drawn to the final buffer, but I want everything from the diffuse buffer aswell since it could be lit by ambient lights. What is the best way to do this? copy the content from diffuse buffer to the "final" buffer before doing the light passes?

Share this post


Link to post
Share on other sites
Advertisement
1: Yes, the lighting pass has to render to a separate render target that has to somehow get put on the screen. The lighting pass could just render directly to the screen, or get rendered to a texture that's copied to the screen, or to a texture that is put on a full screen quad, etc.

One thing, though: the target of the lighting pass shouldn't be GL_COLOR_BUFFER_ATTACHMENT_3. You should have a completely separate framebuffer object, otherwise you'll have a data hazard trying to read the output from your first pass while it's still bound as an output.

2: If you want ambient lighting over the whole screen, then just draw a full screen ambient light volume that adds something to your light accumulation buffer, just like with your point lights. It's no different.

Share this post


Link to post
Share on other sites

I use depth (reconstructing position), normal, and diffuse attachments. After drawing out the g-buffer, I just switch back to the default framebuffer. The lighting pass consists of a non-blended full screen quad for ambient (which also copies over depth, as glBlitFramebuffer requires matching formats), followed by additive blending for the rest of the lighting passes. Directional lights get another quad, while the point lights are as you said. Along with clipping and depth testing, I use discard based on radius to not include pixels that are behind the light but far away. I haven't handled the case of having the camera in the light volume yet. I'll probably batch those up as they occur for another (conditional) full screen pass.

 

So to be specific: 1. The easiest way is to use your FBO's textures as regular textures in passes that write to the default framebuffer.

2. Either use a full screen pass for non-blended ambient setup, or you could have extra knowledge about your scene such as having only a single directional

light (the sun?) which can include ambient in its equation.

Share this post


Link to post
Share on other sites

Given those color attachments, unless you need an offscreen buffer for motion blur or something that is applied as an after effect to the scene, you could simply draw to the framebuffer(screen) itself.

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!