OpenGL lighting issue...

Started by
6 comments, last by Calefaction 19 years, 6 months ago
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).
Matt Holmes[ aka Calefaction ]Wildfire Games - General Programmerhttp://www.wildfiregames.com
Advertisement
Normals facing in the wrong direction? Where is the lightsource placed? Which colour is specified in glColor?

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?
Matt Holmes[ aka Calefaction ]Wildfire Games - General Programmerhttp://www.wildfiregames.com
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?
Matt Holmes[ aka Calefaction ]Wildfire Games - General Programmerhttp://www.wildfiregames.com
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...
Matt Holmes[ aka Calefaction ]Wildfire Games - General Programmerhttp://www.wildfiregames.com
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.

____________________________________________________________www.elf-stone.com | Automated GL Extension Loading: GLee 5.00 for Win32 and Linux

I seem to have cleared up most of the problems :) It was color issues, I wasn't setting proper ambient colors in all places. So shading was appearing very dark and blotchy when it shouln't have. This all seems to be working as expected now :)

Next up, dark maps for the terrain :)
Matt Holmes[ aka Calefaction ]Wildfire Games - General Programmerhttp://www.wildfiregames.com

This topic is closed to new replies.

Advertisement