Problem when using many lights

Hi, folks.

I was doing some experiments with lighting and i have hit a wall…

i was trying to setup a big number of lights in my chessboard:

    for i in range(8):
        for j in range(8):
            pointLight = PointLight("PointLight"+str(i)+str(j))
            pl = self.secondRender.attachNewNode(pointLight)
            pos = Vec3(i-3.5, j-3.5, 1)

I know that they are too many lights but, i repeat, this was only an experiment. What has disturbed me is that, when doing this, i have seen that only the last lights you setup seem to be active; all the previous ones (and all the lights i had previously set up, seems to be inactive).

So my questions are… who is stablishing the limit on the number of active lights? and how could i change it?



It’s your graphics card.

other possibilities :

  1. your lights are separated only 1 panda unit away from each other, and if your model is quite far away from them, it might looks like there’s only 1 point light source (moreover, you use same color on them, so it’s hard to distinguish them). PointLight also has attenuation range you might want to consider.
  2. perhaps your model doesn’t have enough vertices. Try to tesselate it.
    But first try this scene :
import direct.directbase.DirectStart
from pandac.PandaModules import CardMaker,Mat4,NodePath,PointLight,Vec3,Vec4
from direct.gui.DirectGui import OnscreenText
from random import random

OnscreenText( text='MAX LIGHTS : %s',
              scale=.05, fg=(1,1,1,1), shadow=(0,0,0,1))


for i in range(num):
    for j in range(num):
        c.setPos(2*(i-numHalf), 2*(j-numHalf), -2)

for i in range(8):
    for j in range(8):
        pointLight = PointLight("PointLight"+str(i)+str(j))
        pl = render.attachNewNode(pointLight)
        pos = Vec3(10*(i-3.5), 10*(j-3.5), 1)

camera.setPos(50, -100, 200)


screenshot :

I see… and what’s a reasonable limit on the number of lights so that a relatively modern graphic card hasn’t problem with it? 4?

I’m trying something in this line. Thanks.


As the code tells you, your graphics card supports a maximum of 8 lights. You cannot have more than that, unless you use shaders for every object (which is probably not what you would want)

Yeah, i see. But i was now wondering if that ( 8 ) is a normal limit or i should limit more the number of lights to avoid having problems with other cards.

I think i will probably use 5 lights finally.

12 fps ??? Are you running on software mode ?
I got 140+ fps on GeForce FX5200. Even GF2 isn’t that bad I guess.

I got 15 fps without flattenStrong.

I was wondering that too…

My config.prc seems right:

framebuffer-hardware #t
framebuffer-software #f

The program gave me around 22 FPS in medium (it went down to 12 when activating the screenshot capture program). I was running around other 10 desktop programs at the same time, but nothing that should use intensively the system resources.

I’m running Kubuntu 7.04 on a laptop (1Ghz, 512 MB RAM), and glxgears give, in the same conditions, 730 FPS, so OpenGL programs seems to be working…

I was wondering just it this morning, as the scene i was originally trying was composed of around 100 models totalizing <125.000 polygons (they had textures and materials) and panda3D was going horribly slow (i didn’t had the FPS counter activated, but i guess i was around 1 FPS); i had to trim the scene to around 15.000 polygons for it to be working acceptably (most of the time, there is no movement in the scene, so you don’t notice the FPS rate as long as you don’t move anything).

This is, indeed, the first time i try to do something serious with a 3D engine, so i’m not knowledgeable about how many polygons can manage a graphic card… i would appreciate a little help here. Do you think this is too slow? In case you think i’m running in software mode after all, how can i confirm it?


That’s way slower than it should work. What speed do you get when running the sample programs?


When running GreetingCard in the same conditions, i got 5-7 FPS. When shutting down the 4 programs i had active that could be eating some resources, FPS count rise to 7-10 FPS. Definitively something is going wrong here… :stuck_out_tongue:

How can i discover what’s going on?

I have set “notify-level” to debug in Config.prc and run the command
python 2> /home/joseluis/panda3ddebug.txt

but i’m not seeing anything clearly wrong in the output: