Apply default scene as a texture?

I know you can create a custom scenegraph, buffer and camera and apply that as a texture but can you do the same with the default base.camera and base.render?

Thanks.

You can do this, you just need to assign base.camera to your newly created buffer’s DisplayRegion, and in the original window’s display region, you can reassign the camera to something else instead, so that it renders a different scene.

In fact, this is exactly what FilterManager does, so if your use case involves postprocessing effects on the rendered scene image, I recommend using that.

If you don’t want to show a window at all, you can set windowType='offscreen' in the ShowBase constructor.

Thanks. The way you worded the answer it sounds like the same camera can’t be assigned to different DisplayRegions.

I did not mean to imply that. You absolutely can have the same camera in different display regions at the same time, that should work just fine, if you want to render the scene both to a texture and to the window.

Sure, just to clarify for others.

That said the below code does not seem to work. I see a gray background and loaded models don’t show up,

test_buffer = base.win.make_texture_buffer("test_buffer", 640,480)
test_buffer.set_sort(-100)
test_buffer.get_display_region(0).set_clear_color_active(True)
test_buffer.get_display_region(0).set_clear_color((0,0,0,1))
test_buffer.get_display_region(0).set_camera(base.cam)
test_texture = test_buffer.get_texture()
# my_frame was created elsewhere
my_frame.set_texture(test_buffer_texture)

I still haven’t managed to figure out how to change the background color here. Sorry for double-posting.

Try creating a new display region with test_buffer.make_display_region() instead.

Hi rdb,
Do I need a DisplayRegion if I don’t want it visible on the Window and just want to apply the texture from the TextureBuffer to a quad in the default 3d scene (render)?

Yes. A DisplayRegion is needed whether you are rendering into a buffer or into a window. A DisplayRegion in Panda is a fundamental unit of rendering that tells Panda what to render and where to render it to.

1 Like

I see, thank you.
Out of curioisity, any ideas what test_buffer.get_display_region(0) references in my original code? It does not seem to raise any error or warning and it does seem to return a DisplayRegion but which does not react to trying to change its background color.
print( test_buffer.get_display_region(0) )
>>DisplayRegion(0 1 0 1)=pixels(0 480 0 360)

By default, there is an “overlay” display region created, that is used internally for clear operations affecting the entire buffer. It is marked inactive by default. In theory, perhaps you could use it by calling set_active(True) on it, but I don’t recommend it.

I’m personally inclined to remove this wart from the API, but it’s hard to do so without breaking existing applications in subtle, non-obvious ways.

Perhaps it could however be marked as “inactive” when printing it, to make this clearer.

I see. Thanks for the clarification.
You could probably get rid of it for 2.0.