Directional Light Following the Camera Movement

I’m new to Panda3D, and have been experimenting with creating a CAD interface using it. I looked around and saw similar posts on what I’m trying to do, but am still struggling to understand how this should work.

I would like for a directional light to mirror the pos and lookAt of the camera, so that the part of the model that the camera is looking at is always directly illuminated (regardless of how the mouse moves the camera). I’m not concerned about creating shadows (and probably don’t even want to), and the posts I think are regarding this are about shadows.

What’s the right way to accomplish what I’m trying to do?

I think that you should be able to simply attach the light to the camera (i.e. via the “reparentTo” method), causing it to inherit its position and–more importantly for a DirectionalLight–orientation from the camera.

@Thaumaturge Thank you, that worked.

At first I thought reparentTo was used in place of render.setLight(), which is wrong. Here’s a snippet of what I ended up with in case it helps someone in the future.

dlight = DirectionalLight('dlight')
dlight.setColor(VBase4(1, 1, 1, 1))
dlnp = render.attachNewNode(dlight)
render.setLight(dlnp)
dlnp.reparentTo(self.cam)
1 Like

I’m glad that you got it working! :slight_smile:

A minor touch-up–just as a matter of clarification, rather than functionality: I’m pretty sure that you don’t need to initially attach the light to “render” (in the line “render.attachNewNode(dlight)”). I think that you should be able to simply create a new NodePath. Something like this:

dlight = DirectionalLight('dlight')
dlight.setColor(VBase4(1, 1, 1, 1))
dlnp = NodePath(dlight)
render.setLight(dlnp)
dlnp.reparentTo(self.cam)
1 Like