1
\$\begingroup\$

I need to render a 3D scene and then several 2D panels that i need to compose on top of the 3D render. I looked on the web for some resource that would show how people do that but couldn't find any. In my case, I don't want to use the fixed pipeline but shaders. So here is what I do:

Create FBO and 2 textures (say)
Attach texture1 to COLOR_ATTACHMENT0 and texture2 to COLOR_ATTACHMENT1
Render-loop {
    bind FBO
    draw into COLOR_ATTACHMENT0
    clear buffers (depth and color) 
    render objects

    draw into COLOR_ATTACHMENT1
    clear buffers
    render the objects that will be the 2D overlay

    draw into default frame buffer
    draw quad to display combination of texture1 and texture2
}

in the quad shader I get the 2 textures and do an alpha blending using the alpha channel of the second texture.

So my question (simple):

Is this how you typically draw different scenes/content into different textures that you can combine into a final pass before displaying the results to the frame buffer? More specifically do you use the mechanism of attaching textures to different color attachment points in the render loop, then active the point you want to draw to (COL0, COL1, etc.) and then combine the textures in the end? Is that how it's typically done?

\$\endgroup\$
  • \$\begingroup\$ To be sure I understood correctly, is this the kind of rendering you want to achieve ? (the 2D overlays on top of the 3D rendering) \$\endgroup\$ – CpCd0y Feb 3 '17 at 20:55
  • \$\begingroup\$ @CpCd0y It's not obvious when I look at the image you give, but probably yes. In this case it seems like a multipass where you rendered the same scene. In my case, I need to render different scenes (different geometry) and combine all these different elements to display them on the final "screen" or buffer. My case is more like adding 2D elements of UIs on top of a 3D render, if this helps. \$\endgroup\$ – user18490 Feb 3 '17 at 22:43
1
\$\begingroup\$

The technique you seam to be referring to in your pseudo-code is deferred shading.

It's a technique where you defer shading to a later stage by rendering to intermediary render targets and finally combine them to produce the final image.

You pseudo-code is correct and correctly uses FBOs.

In fact what you're trying to do is using MRT (Multiple Render Target) a common technique that works by attaching multiple textures to an FBO and in your shader outputing to several textures at once. This is often used for G-buffer rendering where you output normals, color, position and such to several other textures at once.

When you're done drawing to your FBO, you can then use the textures associated with it and bind them to your shader to combine them to obtain the final image.

Also, don't forget to bind your shaders (using glUseProgram or alternatives) to actually draw what you want correctly.

I can give more details if needed. Hope this helps.

\$\endgroup\$

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.