Render the whole scene to texture with texturing and lighting disabled

Hi,

I’m using Panda3D for a Robotics application and I need to figure out which object on screen is which. I achieved that by applying materials with different colors to objects and just grabbing data from the offscreen texture.

Now I’m wondering is there another way to do so? Maybe I can disable texturing and lighting only for offscreen render? Use different alpha values for different objects? Or another way?

Panda3D, an amazing engine in terms of possibilities for implementing ideas. I came to this solution, which does not require shaders or customizing materials, most importantly, you also do not need to have a second copy of the object.

from panda3d.core import Camera, NodePath, RenderState, TextureAttrib, MaterialAttrib, LightAttrib, ColorAttrib,\
ColorScaleAttrib, TransparencyAttrib, ShaderAttrib, LColor

from direct.showbase.ShowBase import ShowBase

class MyApp(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)

        model = loader.load_model("box")
        model.reparent_to(render)
        model.set_tag("color", "color")

        self.camera_color = Camera("camera_color")
        self.camera_color.tag_state_key = "color"
        lens = self.camera_color.get_lens()
        lens.set_aspect_ratio(base.win.size[0]/base.win.size[1])
        self.camera_color_node = NodePath(self.camera_color)
        self.camera_color_node.reparent_to(self.camera)

        slot_1 = RenderState.make_empty().add_attrib(TextureAttrib.make_all_off(), 1)
        slot_2 = slot_1.add_attrib(MaterialAttrib.make_off(), 1)
        slot_3 = slot_2.add_attrib(LightAttrib.make_all_off(), 1)
        slot_4 = slot_3.add_attrib(ColorAttrib.make_flat( LColor(1.0, 0.0, 0.0, 1.0)), 1)
        slot_5 = slot_4.add_attrib(ColorScaleAttrib.make_off(), 1)
        slot_6 = slot_5.add_attrib(TransparencyAttrib.make(TransparencyAttrib.M_none), 1)
        slot_7 = slot_6.add_attrib(ShaderAttrib.make_off(), 1)

        self.camera_color.set_tag_state("color", slot_7)

        base.accept("1", self.set_cam, [self.camera_color_node])
        base.accept("2", self.set_cam, [base.cam])

    def set_cam(self, camera):
        base.win.get_display_region(1).camera = camera

app = MyApp()
app.run()

Use buttons 1 and 2 on your keyboard to switch the rendering type.

1 Like

This is pure awesome, it worked! Of course I had to specify colors for objects like this:
child.set_color(…)

Many thanks!