PDA

View Full Version : Problem with lighting



fortikur
06-10-2004, 11:12 PM
I don't know if someone has already encountered this problem: I have a big (approx 85 units high) human model which should be lit, while I move the camera around it. The model is loaded from a 3dsmax ASE file with its mapping coords, normals, etc. (y and z flipped of course)...
I created a light source with the following params:
glLightfv(ID, GL_DIFFUSE, rgba);//rgba is 4,4,2
glLightfv(ID, GL_POSITION, pos);//position is set correctly to the coords I want (10,100,50,1)
lighting is enabled, glLight0 too
I also set the ambient value with another light (glLight1), but I don't care about it right now.

So, as you can see, I have a model and a positional light. The problem is, when I try to lit the model, it seems, as the light wouldn't be positional. Imagine a line going from the middle of the screen through the light source and hiting the model. Where it is hit, it is lit, but it doesn't look like (even a little bit), as this light would work as a normal omni light. It doesn't emit light to all directions.
As my code is too big to fit it here, i will just write the concept of displaying things:
- loadidentity
- setting perspective and glulookat (moving cam)
- glMatrixMode( GL_MODELVIEW );
- setting color and position of light
- glPushmatrix
- glTranslate and rotate
- displaying mesh with glCallList

Why doesn't this light work as a real omni one? Does it have anything to do with the normals stored in the ASE file?

06-11-2004, 12:11 AM
problems with lighting are usually reltaed to 2 things:

1) geometry - make sure the normals for all the model's vertices are ok.

2) transformations - make sure you have transformed the model and its normals correctly. when you set a light position, it will be multiplied by the current modelview matrix. if your're doing lighting in eye space, then you want to set light positions after you transform the eye. if you want light in world space, then set light positions with an identity. this is the hardest part of lighting to get used to, getting these pesky matrices right.

3) state - make sure blending, depth test, alpha test, shade model, cull face, and so on are right.

4) things i forgot