Lights Acting Weird

For some reason, my ambient light isn’t working as intended, I have it set at 0.2,0.2,0.2 and the shadows show up pitch black. The spotlight I have set up is also going through parts other than the window, the faces on the models are correct.

        alight = AmbientLight("alight")
        alight.setColor((0.2, 0.2, 0.2, 1))
        alnp = self.render.attachNewNode(alight)

        plight = PointLight("plight")
        plight.setColor((0.3, 0.3, 0.3, 1))
        plight.setShadowCaster(True, 526, 526)
        plnp = self.render.attachNewNode(plight)

        slight = Spotlight('slight')
        slnp = self.render.attachNewNode(slight)

        spotlight = self.loader.loadModel("models/misc/Spotlight")


        # self.render.setLight(plnp)

I’m not sure about your ambient light, but I think that the problem with your spotlight is that you haven’t set it to be a shadow-caster. As a result, no shadows are cast by it onto geometry, and thus all geometry within its reach is illuminated by it.

I set shadow caster to true for the spotlight and the light is still going through the wall.

image from the back

Hmm, I don’t know, I’m afraid! Based on that image, it looks like shadows are being cast, but incorrectly for some reason. Perhaps another forum-member will have a better idea of what’s going on!

This looks like a panda shader bug. One plane repeatedly shades the other plane. It is possible that the shader does not use a depth buffer or something else. I don’t understand this shadow mechanism.

test code.

from direct.showbase.ShowBase import ShowBase
from panda3d.core import AmbientLight, Spotlight, PerspectiveLens

class Game(ShowBase):
    def __init__(self):
        alight = AmbientLight("alight")
        alight.setColor((0.2, 0.2, 0.2, 1))
        alnp = render.attachNewNode(alight)
        slight = Spotlight('slight')
        slight.setShadowCaster(True, 1024, 1024)
        slnp = render.attachNewNode(slight)
        slnp.setPos(0, 4.5, 3.2)
        slnp.setHpr(180, -20, 0)

        model = loader.loadModel("mesh.bam")


game = Game()

mesh.bam (20.7 KB)

Oh, I’m sorry. But the problem is that you need to adjust the size of the lens so that it covers the entire volume of the model.

This is described in detail here.

Only for the spotlight, you still need to take into account the length of the focus.

I messed around with the struct, I want the render to look light the light is only coming through the window, how would I achieve that?

Or is there a method to make it so that a wall isn’t affected by the spotlight but is still affected by other lights?

To do this, you need to build a hierarchy of objects with a division into different branches so that you can customize their lighting individually. You may also have to separate the walls and floor.