Misunderstanding how PointLight works

Hello everyone I’m new to panda3d, so my question might be stupid. I create a model in Blender and try to light it with PointLight and face unexpected effects. Here is my code

class MyApp(ShowBase):

    def __init__(self, scale=0.1):
        self.model_scale = scale
        kitchen = self.loader.loadModel('/home/stanismorozov/python3d/models/kitchen.bam')
        for t in kitchen.children:
            if t.name == 'Walls':
                self.room_box = t
                mn, mx = t.getTightBounds()
                self.room_abs_sizes = mx - mn                
        self.light_model = self.loader.loadModel('models/misc/sphere')
        self.light_model.setScale(0.1, 0.1, 0.1)
        self.room_box.setScale(self.model_scale, self.model_scale, self.model_scale)
        self.room_box.setHpr(0, 0, 0)
        self.room_box.setPos(0, 0, 0)
        self.ptlight = PointLight('plight')
        self.plnp = self.light_model.attachNewNode(self.ptlight)
        self.taskMgr.add(self.move_light, 'move-light')
    def move_light(self, task):
        ft = globalClock.getFrameTime()

        self.light_model.setPos(self.room_abs_sizes[0] / 2 * self.model_scale + cos(ft) * 5,
                         self.room_abs_sizes[1] / 2 * self.model_scale  + sin(ft) * 5,
                         (self.room_abs_sizes[2] + 10) * self.model_scale)
        return task.cont

app = MyApp()

Here’s an example of how it looks like

The first unexpected thing for me is that the box is lit from the inside, although the light should not pass there. The second is that the sphere corresponding to the point source is only half illuminated. It seemed to me that point light should shine equally in all directions. The third thing is that the upper side of the box is almost black, although it has a white texture, that is, it is almost not lit.

Also the change of light color

self.plnp.setColor((0, 0, 10, 1))

has no effect.

I didn’t find any documentation describing my problems, so I would be grateful for any tips and materials!

Here is another example when the light source is inside

The sides are lit, but the top is not. And the sphere is only half lit again.

Here is an example of how it looks like without lighting sources. I expected that the colors would not differ much with the lighting.

Sorry for many replies the system says: “Sorry, new users can only put one embedded media item in a post”.

Hm-m, at the first look I would say that your point light source is located under the sphere, but very-very close to it. So, your light lits only one side of the sphere. And ceiling is black because of a sphere shadow.

If you want to lit the source itself (like it is a lamp), you better use Emission parameter of the model material (can be set with Blender): https://docs.panda3d.org/1.10/python/reference/panda3d.core.Material#panda3d.core.Material.setEmission

1 Like

Firstly, I would recommend enabling per-pixel lighting, such as via self.render.setShaderAuto(). On models with low vertex count, it can make it easier to see what is going on, because by default the lighting is only calculated per vertex. Or, instead of setShaderAuto, I can recommend the use of simplepbr, which is designed to better match the shading in Blender.

Secondly, you should check the polygon normals. If the normals are inverted, then the lighting will look incorrect.

As for the lighting affecting the inside: by default, no shadow-mapping is performed (this is an expensive operation), so Panda does not prevent light from passing through objects. You can enable the light as a shadow caster if you do want this.

Setting the color of a light should definitely work. Are you using blend2bam? Perhaps it converted a light that was specified in Blender and your light in Panda is not actually having significant effect.

Setting the emission color of a material does not affect lighting.

PS. I’ve bumped your trust level on the forum.

1 Like

Thank you for your quick response! Yes, I use blend2bam, but I specifically select only the model of interest and do not add the light source from Blender.

Adding self.render.setShaderAuto() made the whole model completely black.

I will check the normals, but it seems to me that if there were problems with them, the upper side of the box would be lit when the light source is located on at least one side, but it is not lit nor from above nor from below.

Please try calling self.room_box.ls() (before creating your PointLight), this will confirm on the command-line whether there is indeed no light in the model itself.

I do recommend that you try the simplepbr package. It is designed to work well with blend2bam and match the lighting behaviour of Blender much better than the built-in shaders.

1 Like

self.room_box.ls() prints nothing and returns None. OK, I’ll try simplepbr package.

Adding simplepbr.init() in the beginning also makes the model completely black.

ls() should print something. If it doesn’t, that suggests that the model doesn’t contain anything. That’s clearly not the case.

If the model is completely black, even with simplepbr (assuming you removed setShaderAuto, which would otherwise override simplepbr), then that suggests the light isn’t active or too weak. I would suggest ramping up the brightness of the light using self.ptlight.setColor((1000, 1000, 1000, 1)).

If you can’t get it to work, please share your bam file (privately if necessary) so I can take a look.

1 Like

Sorry, actually ls() prints
PandaNode Walls T:(scale 0.1)
GeomNode Cube (3 geoms: S:(CullFaceAttrib MaterialAttrib TextureAttrib))

And thank you very much, actually simplepbr and inverting normals fixed the problem, now it looks just like I expected!