only one light "shines" but they all light up

Edit, I solved this with a David DRDW technique,
that guy is a genius! Attach to the camera!

[Edit] I just realized everything is lit up now,
with the attach to camera technique
but i still only have one light :slight_smile:

Hi I’ve run into a problem with having multiple lights in a scene.
The only thing i can think of is that they’re named the same, the nodes,
but in the manual there’s an example of lighting two pandas
with 2 direction lights that were almost identical.
http://panda3d.org/manual/index.php/Example
So I don’t know…I was thinking maybe i would have to have
separate names like “directionalLight_3=directionalLight” for example.
I’m using a shader, so maybe thats it?
Yesterday i thought maybe also it was because i was trying to link
the lights up to the light nodes in the egg file,but they all light up!
Out of three only one casts shadow lighting though. The only thing
i can think is the setshaderinput is only adding the top node because
they’re named the same, or maybe i need to import a stray vector
or something, like the terrain set position maneuver. :slight_smile:
Also i notice in the direct sessions panel that there are only
one ambient and directional “main” type nodes, so maybe thats it.
Hopefully you get more than one light though!
I read a lot of “oh you can do that with a switch texture instead of a light”
type forum replies, so hopefully not :slight_smile: I shoiuld also add that they’re
different geometry stand-ins too, for the lights.
Its not the same polygon model loaded into the three different locations.
I tried to group all the stand-ins together also as well
as the three separate light groups and the terrain group.
These damn nodes! Tonight my experiment is to scale a light
up and see if that will at least light everything up.
I can live with one light if it lights everything,
even though it kind of sucks…
For another question, is there a way to save the work from the direct session panel?
Here’s what i mean, these are two different lights,
(they’re not very deftly crafted)
one shines and one doesn’t. Does this look like
a familiar lighting mishap/scenario to anyone(the one working light)?
Thanks for any help also!



i just did the lighting tutorial, so i’m going to experiment with this.

[/url]

I’ve been experimenting with the normal map demo,
here’s the code for two lights, that denotes my problem.
I added another slower rotating light, but only one radiates.

#
# Normal mapping is a way of making polygonal surfaces look
# less flat.  Another word for normal mapping is "bump mapping."
#
# This is a tutorial to show how to do normal mapping
# in panda3d using Cg.  This is probably the simplest possible
# version of normal mapping: just one point light, one ambient
# light, and no shadows.

import direct.directbase.DirectStart
from pandac.PandaModules import WindowProperties
from pandac.PandaModules import Filename,Shader
from pandac.PandaModules import AmbientLight,PointLight
from pandac.PandaModules import TextNode
from pandac.PandaModules import Point3,Vec3,Vec4
from direct.task.Task import Task
from direct.actor.Actor import Actor
from direct.gui.OnscreenText import OnscreenText
from direct.showbase.DirectObject import DirectObject
import sys,os

# Figure out what directory this program is in.
MYDIR=os.path.abspath(sys.path[0])
MYDIR=Filename.fromOsSpecific(MYDIR).getFullpath()

# Function to put instructions on the screen.
def addInstructions(pos, msg):
    return OnscreenText(text=msg, style=1, fg=(1,1,1,1),
			pos=(-1.3, pos), align=TextNode.ALeft, scale = .05)

# Function to put title on the screen.
def addTitle(text):
    return OnscreenText(text=text, style=1, fg=(1,1,1,1),
	                pos=(1.3,-0.95), align=TextNode.ARight, scale = .07)


class NormalMapDemo(DirectObject):

    def __init__(self):

	# Post the instructions
	self.title = addTitle("Panda3D: Tutorial - Normal Mapping (aka Bump Mapping)")
	self.inst1 = addInstructions(0.95, "Press ESC to exit")
	self.inst2 = addInstructions(0.90, "Move mouse to rotate camera")
	self.inst3 = addInstructions(0.85, "Left mouse button: Move forwards")
	self.inst4 = addInstructions(0.80, "Right mouse button: Move backwards")
	self.inst5 = addInstructions(0.75, "Enter: Turn normal maps Off")

        # Load the 'abstract room' model.  This is a model of an
        # empty room containing a pillar, a pyramid, and a bunch
        # of exaggeratedly bumpy textures.

        #Load the panda actor, and loop its animation 
	self.room=Actor()
	self.room.loadModel('models/abstractroom')
	self.room.reparentTo(render)
	
 
       # Make the mouse invisible, turn off normal mouse controls
     
        props = WindowProperties()
        props.setCursorHidden(True)
        base.win.requestProperties(props)

        # Set the current viewing target
        self.focus = Vec3(48,0,25)
        self.heading = 180
        self.pitch = 0
        self.mousex = 0
        self.mousey = 0
        self.last = 0
        self.mousebtn = [0,0,0]

        # Start the camera control task:
        taskMgr.add(self.controlCamera, "camera-task")
        self.accept("escape", sys.exit, [0])
        self.accept("mouse1", self.setMouseBtn, [0, 1])
        self.accept("mouse1-up", self.setMouseBtn, [0, 0])
        self.accept("mouse2", self.setMouseBtn, [1, 1])
        self.accept("mouse2-up", self.setMouseBtn, [1, 0])
        self.accept("mouse3", self.setMouseBtn, [2, 1])
        self.accept("mouse3-up", self.setMouseBtn, [2, 0])
        self.accept("enter", self.toggleShader)
        self.accept("j", self.rotateLight, [-1])
        self.accept("k", self.rotateLight, [1])
        self.accept("arrow_left", self.rotateCam, [-1])
        self.accept("arrow_right", self.rotateCam, [1])

        # Add a light to the scene.
        self.lightpivot = render.attachNewNode("lightpivot")
        self.lightpivot.setPos(0,0,25)
	self.lightpivot.hprInterval(10,Point3(360,0,0)).loop()
        plight = PointLight('plight')
        plight.setColor(Vec4(1, 1, 1, 1))
        plight.setAttenuation(Vec3(0,0.05,0))
        plnp = self.lightpivot.attachNewNode(plight.upcastToPandaNode())
        plnp.setPos(45, 0, 0)
        self.room.setLight(plnp)
        self.room.setShaderInput("light", plnp)


        # Add a light to the scene.
        self.lightpivot = render.attachNewNode("lightpivot1")
        self.lightpivot.setPos(0,0,25)
	self.lightpivot.hprInterval(5,Point3(360,0,0)).loop()
        plight_1 = PointLight('plight')
        plight_1.setColor(Vec4(1, 1, 1, 1))
        plight_1.setAttenuation(Vec3(0,0.05,0))
        plnp2 = self.lightpivot.attachNewNode(plight.upcastToPandaNode())
        plnp2.setPos(45, 0, 0)
        self.room.setLight(plnp2)
        self.room.setShaderInput("light", plnp2)




        
        # Add an ambient light
        alight = AmbientLight('alight')
        alight.setColor(Vec4(0.2, 0.2, 0.2, 1))
        alnp = render.attachNewNode(alight.upcastToPandaNode())
        self.room.setLight(alnp)

        # create a sphere to denote the light
        sphere = loader.loadModel("models/sphere")
        sphere.reparentTo(plnp)

        # create a sphere to denote the light
        sphere = loader.loadModel("models/sphere")
        sphere.reparentTo(plnp2)

        # load and apply the shader.
        self.shader = Shader.load(MYDIR+"/bumpMapper.sha")
        self.room.setShader(self.shader)
        self.shaderenable = 1
        
    def setMouseBtn(self, btn, value):
        self.mousebtn[btn] = value

    def rotateLight(self, offset):
        self.lightpivot.setH(self.lightpivot.getH()+offset*20)

    def rotateCam(self, offset):
        self.heading = self.heading - offset*10

    def toggleShader(self):
        self.inst5.destroy()
        if (self.shaderenable):
            self.inst5 = addInstructions(0.75, "Enter: Turn normal maps On")
            self.shaderenable = 0
            self.room.setShaderOff()
        else:
            self.inst5 = addInstructions(0.75, "Enter: Turn normal maps Off")
            self.shaderenable = 1
            self.room.setShader(self.shader)

    def controlCamera(self, task):
        # figure out how much the mouse has moved (in pixels)
        md = base.win.getPointer(0)
        x = md.getX()
        y = md.getY()
        if base.win.movePointer(0, 100, 100):
            self.heading = self.heading - (x - 100)*0.2
            self.pitch = self.pitch - (y - 100)*0.2
        if (self.pitch < -45): self.pitch = -45
        if (self.pitch >  45): self.pitch =  45
        base.camera.setHpr(self.heading,self.pitch,0)
        dir = base.camera.getMat().getRow3(1)
        elapsed = task.time - self.last
        if (self.last == 0): elapsed = 0
        if (self.mousebtn[0]):
            self.focus = self.focus + dir * elapsed*30
        if (self.mousebtn[1]) or (self.mousebtn[2]):
            self.focus = self.focus - dir * elapsed*30
        base.camera.setPos(self.focus - (dir*5))
        if (base.camera.getX() < -49.0): base.camera.setX(-49)
        if (base.camera.getX() >  49.0): base.camera.setX( 49)
        if (base.camera.getY() < -49.0): base.camera.setY(-49)
        if (base.camera.getY() >  49.0): base.camera.setY( 49)
        if (base.camera.getZ() <   1.0): base.camera.setZ(  1)
        if (base.camera.getZ() >  49.0): base.camera.setZ( 49)
        self.focus = base.camera.getPos() + (dir*5)
        self.last = task.time
        return Task.cont


if (base.win.getGsg().getSupportsBasicShaders()):
    t=NormalMapDemo()
else:
    t=addTitle("Normal Map Demo: Video driver reports that shaders are not supported.")

run()