RTM_bind_layered doesn't seem to work with RTP_color

The problem is almost in the title :slight_smile:

When rendering to 3D texture using RTM_bind_layered, I have no issue with the aux attachments. However, when trying to use the main color attachment, no valid data is stored in the texture in any layer but no errors are reported.

I’m not sure if it is a bug or a limitation though, but as far as I understand OpenGL spec this should be allowed. The only thing I could find in the code / doc is that it’s not possible to use RTM_bind_layered with target that will be copied.

The current workaround for me is to bind a dummy texture to the color attachment (as otherwise Panda3D builds a framebuffer with no color attachment 0, which is rejected by OpenGL) and shift the shader output layout.

I attached a demo code, which tries to fill the main color attachment with a solid green color and the first aux attachment with a solid blue color. Only the aux attachment is filled with blue, and when looking at the dumped files, only the aux attachment has the right content.

test_layered.zip (1.7 KB)

Side remark, when trying to extract the texture data with get_ram_image_as("RGBA") I get an assertion error :

Traceback (most recent call last):
  File "test_layered.py", line 147, in do_render
    t1_data = t1.get_ram_image_as("RGBA")
AssertionError: data.size() == (size_t)(cdata->_component_width * cdata->_num_components * imgsize) at line 7499 of panda/src/gobj/texture.cxx

The root cause of that error is trivial, see Can not use get_ram_image_as() with 3D textures · Issue #1277 · panda3d/panda3d · GitHub

The last-rendered slice does, in fact, have the correct colour, but the other slices don’t.

I think what’s happening is that there is a clear color applied by default to the color bitplane. This will clear all layers every time you do a render pass. (I think this is the right behaviour as the main use of layered rendering is to render all layers at once - and besides, Panda can’t possibly know what layer your shader is going to write to.)

So, just disable the clear color, and it should work.

That was the problem :slight_smile: I did call disable_clears() on the display region, but not on the render buffer ! And so it was “cleared” with a random value.

If I don’t call disable_clears() the texture is cleared with LVecBase4d(0.41, 0.41, 0.41, 0) unless I explicitly call set_clear_color(LColor(0, 0, 0, 0)) and I have no idea where this value comes from!

I think it’s from the background-color Config.prc value.

Indeed, that’s the default value, I naively thought it would be all 0 for an off-screen buffer :slight_smile:

Thank you for your always invaluable help !