Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Simplified version of my deferred rendering looks like this:

  • bind fbo1
  • clear color and depth buffers
  • gbuffer stage (gbuffer contains only these pixels which pass a depth test)
  • unbind fbo1

  • bind fbo2

  • clear color buffer
  • draw a full screen quad, shading stage (render to the texture for some post processing effects)
  • unbind fbo2

  • clear color and depth buffers

  • draw a full screen quad and render to the default framebuffer

How to combine that with the forward rendering ?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

Copy the depth information to the la-buffer and then render normally to the la-buffer using forward shading. All you need to do to copy over the depth information is add this to the light accumulation fragment shader:

gl_FragDepth = texture(depthBuffer, texCoord).r;
share|improve this answer
    
The gbuffer(fbo1) contains a depth texture and a depth attachment. When fbo1 is bound I set glDrawBuffers and I use a gbuffer shader. So after that (when fbo1 is still bound) I should switch a shader program and use a forward rendering !? –  Irbis Feb 4 '13 at 18:18
    
No, you need to render to the la-buffer or the default framebuffer. You need to make sure that the la-buffer has a depth attachment. –  Boreal Feb 4 '13 at 18:23
    
Ok, now the la-buffer has a depth attachment. I render (forward rendering) to the default framebuffer at the end (after a full screen quad) but the result of the forward rendering is behind a full screen quad. I checked that using glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); How the depth data is moved from fbo1 to fbo2 ? Maybe here something is wrong. –  Irbis Feb 4 '13 at 22:35
    
In the light accumulation shader, read in the depth value from the g-buffer and output it to the la-buffer using gl_FragDepth. –  Boreal Feb 5 '13 at 0:39
    
You shouldn't need to copy the depth value anywhere. Just attach the same depth buffer to both FBOs. –  Nathan Reed Feb 5 '13 at 1:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.