Rendering from different cameras

Hi,

I have a scene I’m rendering to two different windows through two different cameras. I’d like to be able to have some objects in common and some specific to a certain window. Actually most of the things they’re going to render are the same, but there’s a bunch of things that are different. I thought cameras rendered whats reparented to them but that didn’t work out. What’s the best way to achieve this?

Thanks.

Use camera masks.

window1Cam.node().setCameraMask( BitMask32( 1 ) )
window2Cam.node().setCameraMask( BitMask32( 2 ) )

for the two cameras for the different windows, then to hide an object from one window and not the other:

objectForWindow1Only.hide( BitMask32( 2 ) )

Thanks, that should be the solution.

However, I couldn’t get it to work even with this simple code:

        self.model = loader.loadModel("Models/sky.egg")
        self.model.reparentTo(render)
        base.camList[0].node().setCameraMask(BitMask32(1))
        self.model.hide(BitMask32(1))

The model is not hidden at all. Any ideas?

The reparenting thing worked for me but i add to dig in the source of DirectStart to know how to do it.

I use a different scene with it’s own camera and light conditions for the background separated from the play area. Only use masks if your scene is part of an already existing scenegraph and it’s not convenient to separate it.

Theres a lot of linking that needs to be done for your camera to render properly in setupBackgroundCamera.

    def addBackground(self):
        self.minicon.addText("_Add background")
        #The background root and camera.
        self.background = NodePath("Background")
        self.setupBackgroundCamera()

        #Load the skybox.
        self.skybox = loader.loadModel("Skybox")
        self.skybox.reparentTo(self.background)
        if self.BGOFF: self.skybox.hide()
        
        #Load the axis.
        #self.axisCenter = loader.loadModel("AxisCenter")
        #self.axisCenter.reparentTo(self.background)
        #self.axisCenter.hide()

    def setupBackgroundCamera(self):
        self.bg_cam = Camera("BgCam")
        self.bg_cam.setScene(self.background)
        self.bg_camera = self.background.attachNewNode(self.bg_cam)
        self.bg_camera.setName("BgCamera")
        self.bg_camera.setP(-90)
        
        self.bg_lens = PerspectiveLens()
        self.bg_lens.setAspectRatio(base.getAspectRatio())
        self.bg_lens.setFov(self.BGFOV)
        self.bg_cam.setLens(self.bg_lens)
        
        self.bg_dr = base.win.makeDisplayRegion(0, 1, 0, 1)
        self.bg_dr.setSort(-1000)
        self.bg_dr.setClearDepthActive(1)
        self.bg_dr.setCamera(self.bg_camera)

The not so obvious part is to get a display region for the window you want to render to and link it to the camera.

It definitely works for me, so perhaps it’s somewhere else in your code? I tried it loading a different model, but here is the whole of my .py file:

import direct.directbase.DirectStart
from pandac.PandaModules import BitMask32

model = loader.loadModel("smiley.egg")
model.reparentTo(render)
base.camList[0].node().setCameraMask(BitMask32(1))
base.camList[0].setPos(0, -50, 0)
model.hide(BitMask32(1))  	

run()