Please, more explanation on spotlight

The setting: one actor (Ralph) standing on big textured and normal-mapped square plane (with 4 vertices in four angles), plus static Eva model near.
I have turned on the per-pixel lighting, and turned on the only lightsource - a spotlight. I positioned it above the actor, and pointed downwards. Then I set an interval moving the spotlight up and down. All four are parented to render.
As you can imagine the circle of light on the ground becomes bigger and smaller as light moves. But what a surprise: Ralph and Eva are always lit, doesn’t matter if they in this circle or not, doesn’t matter if the ground under them is lit or not! How could this be?
Few screenshots:

Another thing that bugs me about the spotlight. Why can’t I light the objects that are close to light source? In the above example it is moves from 100 to 200 units above the scene! And the circle of light disappears already close to 100…

I have played with the automatic shader and spotlights as well and they are not really nice yet… you could try using some of the other light shaders available, they may give better results.

for example:

Using custom shader is nice idea but it is still worthy to fix the native Panda shader. It is much easier to use (at least for me, I am just learning Panda, and Cg is out of my comprehension at all).
Josh, David, your opinion on this subject is highly appreciated :wink:

Is it a shader generator issue or something else? Does the spotlight work correctly when you turn off per-pixel lighting and the shader generator? (Without per-pixel lighting, it may not illuminate the floor properly unless it has a lot of vertices. But you should see it work properly on the characters at least.)


Right. If it works with the shader generator turned off, then it’s a shader generator bug, and you should send me a copy of the code. Otherwise, it’s probably that you didn’t do set_light on the two models. :slight_smile:

Hard to say, really, since when I switch off the shader generator, the ground plane is not lit at all. I am going to make another plane, with more vertices.

I have just tested spotlight on another plane with 1024 vertices with shader generator off. Spotlight work as it is supposed to work. Character are lit appropriately. So, this is bug in shader generator.

Is this a small program that you could possibly send me a copy of it?

Not really small (it has lots of stuff, but they can be switched on/off using variables, like “useAmbientLight = 0/1” and so on). Better I make another program for you to test.

Here is the zip file with the code, models and textures:
The spotlight point downward, and is located 200 units above the scene. Press spacebar to make spotlight move down, and watch. Press it again to stop.
Esc closes the example, as usual.
Also, in the beginning of the code, there is a variable “useShaderGenerator = True”. Change it to False to switch off per-pixel lighting, and see the difference in spotlight behavior.

OK, I’m going to work on this today.

I just spent about a half-hour stripping that program down to its essentials:

from direct.showbase.DirectObject import DirectObject
from pandac.PandaModules import *
import direct.directbase.DirectStart
import sys

class World(DirectObject):
    def __init__(self):

        self.staticWorld = loader.loadModel("gfx/floor2")

        base.disableMouse(), -30, 30), -45, 0) = Spotlight("spot"), 1, 1, 1))
        self.lens = PerspectiveLens()
        self.spotNP = render.attachNewNode(
        self.spotNP.setPos(0, 0, 150)
        self.spotNP.setHpr(0, -90, 0)

        self.accept("escape", sys.exit)
        self.accept("p", self.perPixel)
        self.accept("v", self.perVertex)

    def perPixel(self):
    def perVertex(self):

# Now let's make everything.
world = World()


Time to start debugging.

Sorry, I am learning python, and I am not as good you. I tried my best anyway.

Well, guess what… you’ve discovered a MAJOR design flaw in the shader generator. I’m doing my lighting calculations in model space. That works as long as the model isn’t scaled or sheared. But your model is scaled.

I really screwed this one up. I’m going to need to rewrite most of the lighting code in the shader generator - and that’s a lot of code. CRAP!

Wow! I couldn’t think it is so serious…
But anyway, I am the coolest Panda beta tester then! :laughing:

I have this problem too…i attached a light(spotlight) to my camera in freelook mode and when i get close to my models they get darker(the light fades away)

My models have color pass,lightmap pass and normal pass

Is this the part of the same MAJOR design flaw? :slight_smile:

Probably the same thing, if you’re using setScale anywhere. It’s not measuring distances for the attenuation calculations correctly.

Actually, you did provide me with a sample program, which means I can actually debug it. A lot of people just describe the bug verbally - when they do that, all I can do is make unconfirmable guesses. So I don’t know about “coolest,” but certainly one of the most valuable.

Update: I’ve fixed the problem. However, it will be another day or two before I can get panda3d 1.5.3 distributed.