AmbientLight strange behavior


#1

When adding AmbientLight, I don’t see the colors of the object, they appear only when using a different color source. The same AmbientLight effect appears only on the shaded side of the object.
This is not entirely correct, because when we add AmbientLight we should get uniform coverage.

from direct.showbase.ShowBase import ShowBase

from panda3d.core import DirectionalLight, AmbientLight, LVector4

class Light(ShowBase):

    def __init__(self):
        ShowBase.__init__(self)
        
        base.cam.setPos(0, -10, 0)
        
        '''dlight = DirectionalLight('dlight')
        dlight.setColor(LVector4(1.0, 1.0, 1.0, 1))
        dlight.setColorTemperature(4000)
        dlnp = render.attachNewNode(dlight)
        dlnp.setHpr(0, -60, 0)
        render.setLight(dlnp)'''
        
        alight = AmbientLight('alight')
        alight.setColor(LVector4(0.2, 0.2, 0.2, 1))
        alnp = render.attachNewNode(alight)
        render.setLight(alnp)

        self.cube = loader.loadModel("cube")
        self.cube.setColor(LVector4(1, 0, 0, 1))
        self.cube.reparentTo(render)

        self.sphere = loader.loadModel("sphere")
        self.sphere.setColor(LVector4(0, 1, 0, 1))
        self.sphere.reparentTo(render)

demo = Light()
demo.run()

sphere.egg.pz (106.2 KB)

cube.egg.pz (375 Bytes)


#2

The diffuse color of a material will show up under normal lights, the ambient color of the material will show up under ambient lights.

To avoid this behaviour, set your ambient color to the same as your diffuse color in your material, or specify the base color instead (which affects ambient and diffuse).


#3

The problem is that I did not use the material for export.


#4

I honestly do not understand the work of the panda lately. I checked this code for 1.8.0, and a miracle occurred.


#5

Looks like a bug. Panda disables lighting if only an ambient light is present. I’ll fix this for 1.10.1, which should be released soon.