I’ve set up a scene with multiple buffers that get the result of render-to-texture.
I use the following code to set up my texture/buffer/camera
# config is a dumb container that stores properties
# and behaves exactly how you'd expect
film_size = config.intrinsics.get_size()
window_props = p3dc.WindowProperties.size(*film_size)
buffer = self.graphics_engine.make_output(
self.pipe,
f'Buffer[{name}]',
config.render_order,
config.frame_buffer_properties,
window_props,
p3dc.GraphicsPipe.BFRefuseWindow, # don't open a window,
self.win.getGsg(),
self.win
)
texture = p3dc.Texture()
buffer.add_render_texture(texture, p3dc.GraphicsOutput.RTMCopyRam)
buffer.set_clear_color_active(True)
buffer.set_clear_color(config.clear_color)
lens = p3dc.PerspectiveLens()
lens.set_film_size(*film_size)
lens.set_fov(*np.rad2deg(config.intrinsics.get_fov()))
camera = self.make_camera(buffer, lens=lens, camName=f'Camera[{name}]')
camera.reparent_to(self.render)
camera.set_pos(*pos)
camera.set_hpr(*np.rad2deg(hpr))
camera.node().set_initial_state(config.render_state)
Now I can retrieve the results of rendering from the buffer using something like
texture = buffer.get_texture()
data = texture.get_ram_image()
frame = np.frombuffer(data, self._dtype)
What I really want to do (without losing access to the existing buffer/texture that I have, because sometimes I do want to examine the image), is take this texture and compare it to an image I already have.
For example, I want to be able to load an image into a second texture, and then produce a third buffer/texture that gives the difference between the textures at each pixel. I believe I should be using a fragment shader (?) to do this, but am unclear on how to set up the mechanics in Panda3D.
I think I know how to load the image in as the second texture:
second_texture = loader.load_texture("myImage.png")
but am unclear how to set up the third texture. Should I be using filters for this (even though I don’t want anything to appear in the window)?