Lighting

A common mistake when working with Panda3D is putting a lot of work into making your models look completely perfect, but when you load them into the scene graph, they don't look the way they're supposed to. This might be because you haven't added any lights into your 3D scene, so none of the colors/textures that you worked so hard will show up. Every project you create in Panda3D should have lights somewhere.

The types of lights in Panda3D are:

  • Point Lights
  • Directional Lights
  • Ambient Lights
  • Spotlights

We will only go over the simplest and most versatile of the lights, the Point Light. If you want to have more sophisticated lighting, check out this page of the Panda3D manual!

The way you treat a light is similar to how you treat models. You need to load them in, render them, and you have the power to change their location & orientation. A Point light is basically a tiny sun - it will emit light in all directions, so it's orientation (or HPR) doesn't actually matter! However, the location does matter - make sure you put the light where you actually need it so your other models are properly illuminated. Somewhere at the beginning of your project (probably in the init method), include the following code to add a point light:

plight = PointLight('plight')
plight.setColor(VBase4(r, g, b, a))
plightNodePath = render.attachNewNode(plight)
plightNodePath.setPos(x, y, z)
render.setLight(plightNodePath)

First you initialize a light by creating an instance of the PointLight class. Then you set the color of it with your preferred r, g, b, a values. The next few lines are a little confusing, but you don't need to have an incredibly deep understanding of them to create a light. Essentially, you create a path for the light to find the render, set the position to your preferred x, y, z, and finally connect it to the render.

results matching ""

    No results matching ""