# 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?

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

Hi Anon,
I think you’re right . 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
if x1 != x2:
else:

for i in xrange(4):

#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.closePrimitive()
tri2.closePrimitive()

square = Geom(vdata)

return square``````

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

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

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.