Jump to content
  • Advertisement
Sign in to follow this  
Calefaction

OpenGL OpenGL lighting issue...

This topic is 5448 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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).

Share this post


Link to post
Share on other sites
Advertisement
Normals facing in the wrong direction? Where is the lightsource placed? Which colour is specified in glColor?

Just brainstorming here ;-)

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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 :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!