I was thinking about implementing multi-pass rendering. However, studying the examples in the OpenGL network, I noticed that it is possible to use different object States for each pass. However, in Panda, I have to duplicate several cameras and objects.
from direct.showbase.ShowBase import ShowBase
from panda3d.core import DirectionalLight, AmbientLight, LVector4, StencilAttrib, NodePath, Camera
from direct.task import Task
class Demo(ShowBase):
def __init__(self):
ShowBase.__init__(self)
self.disableMouse()
self.camera.setPos(0, -10 , 0)
# --- Stage 1 we write the silhouettes of the figures in the stencil buffer.
base.win.setSort(0)
cube_stencil = loader.loadModel("box")
cube_stencil.setColor(LVector4(0, 1, 0, 1))
cube_stencil.reparentTo(render)
# --- In step 2, we render the cube using the stencil mask.
# Create a new scene node.
render2 = NodePath('render2')
# Create a camera and configure the camera.
self.camera2 = render2.attachNewNode(Camera('cam'))
self.camera2.node().setLens(base.cam.node().getLens())
self.camera2.setPos(0, -10 , 0)
# Create a display region.
self.display_my = base.win.makeDisplayRegion()
self.display_my.setSort(1)
self.display_my.setCullCallback(self.Render_display2)
self.display_my.setClearColorActive(True)
self.display_my.setClearColor(base.getBackgroundColor())
self.display_my.setClearDepthActive(True)
self.display_my.setClearDepth(1.0)
# Set the camera for display.
self.display_my.setCamera(self.camera2)
cube_render = loader.loadModel("box")
cube_render.setColor(LVector4(1, 0, 0, 1))
cube_render.reparentTo(render2)
# Press "2" on the keyboard to disable the second stage of rendering.
self.accept("2", self.display_my_active)
self.status = True
#Disable region of the display for stage 2.
def display_my_active(self):
self.status = not self.status
self.display_my.setActive(self.status)
def Render_display2(self, cbdata):
cbdata.upcall()
print ("Render2")
demo = Demo()
demo.run()
The question is simple, how to use one camera. In Discord, RDB told me that this is possible. Also note that I had to create an additional reference to the cube model. While in OpenGL examples, this is not necessary.
There is a second question, how to set up a callback when the green box is rendered?
Hmm, I just noticed that there is a mirror inversion in the texture. I wonder what this might be related to… Oh Yes, with color inversion.