OpenGL lighting issue...
So I posted this over in the Graphics Programming forum, was trying to fish for a more general, non-OpenGL answer...but considering I am using OpenGL for this application, perhaps I will fish here for an answer :)
Here is the situation. I am moving our current engine towards using hardware dynamic lighting, rather then spherical harmonics. I am having a wierd problem though. I am pretty sure I have set everything up correctly and that I am passing all the required data, but I am obviously not because I get this effect:
http://www.wildfiregames.com/~matthew/lightprob.jpg
My first thought was that the normals are not being sent correctly, but I have stepped through the code and all the normals are there and being passed to the OpenGL using glNormalPointer. Also, GL_NORMAL_ARRAY is enabled, so OpenGL should be setup to except those normals. I have set up the light model settings, as well as GL_LIGHT0's direction and color. GL_LIGHTING and GL_LIGHT0 are enabled. Also of note is the fact my trees (which are drawn in the second step of rendering, the alpha blend step) are drawing correctly. Odd at best :)
Possibly also of note is that glColorModel is set to GL_AMBIENT_AND_DIFFUSE (such that those colors are taken from a call to glColor).
So, given the screenshot, does anyone have any ideas as to what is causing that?
(Oh, and I would post code, but the various snippets are strewn about the engine and are hard to collate in to anything useful).
Normals facing in the wrong direction? Where is the lightsource placed? Which colour is specified in glColor?
Just brainstorming here ;-)
Just brainstorming here ;-)
The lightsource is directional (I think)...it's basically [at 0.7, 1.0, 0.0, 0.0].
How do I flip the normals back around? I guess I can just invert them, correct?
How do I flip the normals back around? I guess I can just invert them, correct?
Hrm, I think I may see the problem. When using glNormalPointer, should I be giving it each vertex normal, or just the face normals for the faces defined by the vertices passed in via glVertexPointer?
glNormalPointer wants vertex-normals. Normals can be flipped just by inverting them. You might want to try moving the lightsource around to see if there's any reaction. Your lightsource position seems a bit strange to be, but that depends on your geometry of course.
Okay, moved my light position to 1.0, 1.0, 0.0, 0.0 (I read somewhere it is a sane default value). Things appear lit now, but I am getting wierd "splotching" effects with the shading and it's very "unsmooth", especially when models walk. I am guessing this is the normals being incorrectly passed or calculated somehow...
What do you mean by unsmooth? Can you post a screenshot. It sounds like maybe a gauraud shading/tessellation issue, but it's hard to tell without more info.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement