Render to multiple Framebuffers at once

Viewed 400

I want to get one Scene FBO with scene color texture and depth texture, and one Depth FBO with depth texture with specific size (1024x1024) for shadow mapping. and I have a code like this:

Renderer::begin()
drawCube();
drawSphere();
Renderer::end();

in Renderer::begin() I bind the Scene FBO and in Renderer::end() I unbind it. So how can I render scene to Depth FBO as well so I can get the depth map in this situation?

1 Answers

You cannot render to two separate and incompatible FBOs. And what you're trying to do amounts to rasterizing triangles twice, using different viewports for different depth buffers.

You can achieve something similar to what you're trying to do by using layered rendering. You can create an array texture for your depth buffer, attach it to the FBO as a layered image, and set multiple viewports for them, then use a GS to output multiple copies of the same triangle to the different layers that will be differently rasterized for the layered depth buffers.

But this also requires a layered color buffer, even though you're not using the color component for the other rasterized image. And the layers in your depth array texture cannot be of different sizes, so you'll have to pick the union of the dimensions and just ignore stuff outside of that area.

Of course, there's one snag: you can't read from your shadow map before you finish building it. This means that if your scene needs to actually use the shadow map (for, you know, shadowing), this is totally not going to work.

So basically this conversation is entirely academic.

Related