Casting shadows without being visible

Hey again!

Is it possible to have an object cast shadows without being visible in the end in the scene?

Thanks for any help!

It is, I do believe!

Generally speaking, lights in Panda cast shadows by virtue of being cameras. (I daresay so that they can render the scene from the position of the light.)

Further, when using the “show” and “hide” methods, there is an optional parameter that allows one to specify to which camera the object should be shown or hidden.

Thus one can “hide” the object to the main camera, or “show” it to the light-camera!

Something like this (untested):

# Set up a mask by which to distinguish the main camera
self.mainCameraMask = BitMask32.bit(1)

# Assign that mask to the camera
self.cam.node().setCameraMask(self.mainCameraMask)

# And hide an object from said camera!
myObject.hide(self.mainCameraMask)

(I’m not sure offhand of whether you would also have to explicitly “show” the object to the light-camera; if so, that part should be just the same, but using “show” instead of “hide”, the light instead of the main camera, and a different mask-value.)

2 Likes

hm doesn’t seem to work. I still see the object in the window

        # Set up a mask by which to distinguish the main camera
        self.mainCameraMask = BitMask32.bit(1)
        # Assign that mask to the camera
        self.cam.node().setCameraMask(self.mainCameraMask)
        # And hide an object from said camera!
        self.plane.hide(self.mainCameraMask)
       
        # Set up a mask by which to distinguish the main camera
        self.lightCameraMask = BitMask32.bit(0)
        # Assign that mask to the camera
        slight.setCameraMask(self.lightCameraMask)
        # And hide an object from said camera!
        self.plane.show(self.lightCameraMask)

slight is the spotlight

Hmm… Strange. Trying it in a simple test-program on my end, it seems to work as expected.

Do you have any off-screen rendering in place? Are you rendering your scene to a buffer, or using CommonFilters, etc.?

If so, then you likely have more than one camera, and it may be that in your case “self.cam” isn’t the one that actually renders the object in question. (It may, for example, be the camera that renders the final quad after post-processing.)

[edit]
The test-program, in case it helps:

from direct.showbase.ShowBase import ShowBase

from panda3d.core import BitMask32

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

        self.model = loader.loadModel("sphere")
        self.model.reparentTo(render)
        self.model.setY(10)

        mask = BitMask32.bit(0)

        self.cam.node().setCameraMask(mask)

        self.accept("1", self.setMask, [mask])


    def setMask(self, maskVal):
        self.model.hide(maskVal)

        mask2 = BitMask32.bit(1)
        self.model.show(mask2)


app = Game()
app.run()

Note that I don’t have a light-camera present there, but that shouldn’t cause a problem, I would imagine.

1 Like

Ah yes! I render the scene with a cube map and of course had to set the mask for each cube camera.
Thanks!

2 Likes