PDA

View Full Version : Problems with dynamic lighting



Neals Shnyder
05-01-2001, 02:58 AM
Hello there,

I'm currently writing a 3D Studio MAX exporter for models. Both, my models and my scenes use the same mesh system. What I first did was to transform the meshes in my exporter to have absolute coordinates in my engine. My engine then created the face and vertex normals itself to pass them through glNormal3f() for every vertex for lighting. That doesn't work any longer because the transformation matrix for every mesh for my model changes. What I now do is to export the meshes in relative coordinates and to export the transformation matrices separately. The exported matrices work well with opengl, they're converted correctly, all meshes are at the positions where they should be, but the problem: dynamic lighting doesn't work any longer because of wrong face normals. I tried both for the normal creation: First, to create the normals for the relative meshes. Second: to transform all vertices temporarely and then create the normals. Both methods don't work, the lighting is wrong, too dark (how can this be, I normalized the normals?!?), and from the wrong direction.

The commands in pseudo-code:

--------------------------------------

glLightfv(...) // positions and rgb values are correct

// for every mesh

glPushMatrix()
glMultMatrixf() // this command is new!

// for every polygon
glTexCoord2f(...)
glNormal3f(...)
glVertex3f(...)

glPopMatrix()

---------------------------------------

Any ideas?

thanks,
Meals

Eric
05-01-2001, 03:36 AM
It happened to me when I started doing exactly what you are doing !

The problem was that some of the matrices introduced a scaling factor... As you probably know, this means the normals are rescaled as well and hence it corrupts the lighting...

So, try glEnable(GL_NORMALIZE) before trying anything else ! It is free on T&L cards, afaik...

Regards.

Eric

Neals Shnyder
05-01-2001, 04:08 AM
Wow thanx man, that's it!!!!

Eric
05-01-2001, 05:48 AM
Pleasure !

At least, you didn't fill in a bug report for Matt saying that you had a problem with driver x.yy... (which I did when this occured to me http://www.opengl.org/discussion_boards/ubb/smile.gif !).

Regards.

Eric

Korval
05-01-2001, 08:06 AM
BTW, you can fix this by glEnabling GL_NORMALIZE (or something like that). It's supposedly free on GeForce hardware.

Eric
05-02-2001, 12:16 AM
Originally posted by Korval:
BTW, you can fix this by glEnabling GL_NORMALIZE (or something like that). It's supposedly free on GeForce hardware.

Isn't that EXACTLY what I said two posts (and some hours) before ???????

I guess you need some rest ! http://www.opengl.org/discussion_boards/ubb/wink.gif

Regards.

Eric