2
\$\begingroup\$

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 ?

\$\endgroup\$
3
\$\begingroup\$

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;
\$\endgroup\$
  • \$\begingroup\$ 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 !? \$\endgroup\$ – Irbis Feb 4 '13 at 18:18
  • \$\begingroup\$ 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. \$\endgroup\$ – jmegaffin Feb 4 '13 at 18:23
  • \$\begingroup\$ 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. \$\endgroup\$ – Irbis Feb 4 '13 at 22:35
  • \$\begingroup\$ In the light accumulation shader, read in the depth value from the g-buffer and output it to the la-buffer using gl_FragDepth. \$\endgroup\$ – jmegaffin Feb 5 '13 at 0:39
  • \$\begingroup\$ You shouldn't need to copy the depth value anywhere. Just attach the same depth buffer to both FBOs. \$\endgroup\$ – Nathan Reed Feb 5 '13 at 1:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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