spotlight problem

Hi there,
I am new to panda3d and i have difficulties implementing a Spotlight. The spotlight is attached to the camera and the HPR angles are updated whenever the camera is rotated. All the models loaded from an egg file get illuminated independently of the viewing angle but the walls, which were built using Geom objects get illuminated only when the camera is STRICTLY in the same direction as the wall normal. Otherwise, the walls remain dark. Do you have any suggestions please?
Thanks in advance :slight_smile:

Maybe your walls consist of only 4 vertices and you are using per-vertex lightning?

Hi Anon,
I think you’re right :slight_smile:. Here is the code i use to build a wall:

def createFace(x1, y1, z1, x2, y2, z2, rgba,n1=0,n2=0,n3=1):
    print "createFace: ",x1,",",y1,",",z1,",",x2,",",y2,",",z2
    format = GeomVertexFormat.getV3n3cpt2()
    vdata = GeomVertexData('square', format, Geom.UHStatic)
    vertex = GeomVertexWriter(vdata, 'vertex')
    normal = GeomVertexWriter(vdata, 'normal')
    color = GeomVertexWriter(vdata, 'color')
    texcoord=GeomVertexWriter(vdata, 'texcoord')
    
    #make sure we draw the sqaure in the right plane
    vertex.addData3f(x1, y1, z1)
    if x1 != x2:    
        vertex.addData3f(x2, y1, z1)
        vertex.addData3f(x2, y2, z2)
        vertex.addData3f(x1, y2, z2)
    else:        
        vertex.addData3f(x2, y2, z1)
        vertex.addData3f(x2, y2, z2)
        vertex.addData3f(x1, y1, z2)
          
    for i in xrange(4):
        normal.addData3f( Vec3(n1,n2,n3) )
        color.addData4f(rgba[0], rgba[1], rgba[2], rgba[3])    
    
    texcoord.addData2f(0.0, 1.0)
    texcoord.addData2f(0.0, 0.0)
    texcoord.addData2f(1.0, 0.0)
    texcoord.addData2f(1.0, 1.0)
    
    #quads aren't directly supported by the Geom interface
    #you might be interested in the CardMaker class if you are
    #interested in rectangle though
    tri1 = GeomTriangles(Geom.UHStatic)
    tri2 = GeomTriangles(Geom.UHStatic)
    
    tri1.addVertex(0)
    tri1.addVertex(1)
    tri1.addVertex(3)
    
    tri2.addConsecutiveVertices(1, 3)
    
    tri1.closePrimitive()
    tri2.closePrimitive()
    
    
    square = Geom(vdata)
    square.addPrimitive(tri1)
    square.addPrimitive(tri2)
    
    return square

Is there a way to put more that 4 vertices in the wall?
Thanks :slight_smile:

Hmm, perhaps the vertex normals aren’t correctly specified?

Why don’t you subdivide each wall before exporting it…
you may also use pointLight or directionalLight with the spotlight and make its RGB value equal to the Spotlight values

Why don’t you try enabling per-pixel lighting? Simply turn the shader generator on:

render.setShaderAuto()

See if that helps.

It worked guys! I had to enable per-pixel lighting.
Thanks everyone :slight_smile:

No problem. Remember, per-pixel lighting takes longer to render then per-vertex lighting. To enable per-pixel lighting on only one node, you can use:

node.setShaderAuto()

This way you don’t have to use per-pixel lighting on the whole scene.