PDA

View Full Version : glScale and Normals



mr_coolio
02-26-2003, 04:34 AM
What effect does glScale have on Normals?
Because if it affects them, then they aren't going to be unit length any longer.

Bob
02-26-2003, 05:22 AM
Normals are transformed by, if I remember correct, the transpose of the inverse of the modelview matrix. Meaning, if you scale your object by 2, your normals are scaled by 0.5. You can enable GL_NORMALIZE to tell OpenGL to renormalize your normals after transformation.

mikael_aronsson
02-26-2003, 05:56 AM
Hi !

Yes GL_NORMALIZE fixes some problems, but if I remeber correct it does not work with non uniform scaling, not much you can do about it though.

On most modern hardware GL_NORMALIZE does not cost anything in performance so there is no reason to have it disabled.

Mikael

mr_coolio
02-26-2003, 06:30 AM
Originally posted by mikael_aronsson:
Hi !

On most modern hardware GL_NORMALIZE does not cost anything in performance so there is no reason to have it disabled.

Mikael

Hi! Why does it cost nothing to have it?

mr_coolio
02-26-2003, 06:36 AM
Originally posted by Bob:
Normals are transformed by, if I remember correct, the transpose of the inverse of the modelview matrix. Meaning, if you scale your object by 2, your normals are scaled by 0.5. You can enable GL_NORMALIZE to tell OpenGL to renormalize your normals after transformation.

OK! So this is really useful then. Correct me if I'm wrong, but this says that gl does the intelligent thing with the normals so that you never need to recalculate their direction, or size.

Bob
02-26-2003, 06:48 AM
I have not used scaling much (OpenGL's scaling that is) so I'm not very experienced with it. But I think you are correct that the normal, after scaling, will still be a vector perpendicular to the surface, although scaled. So it should work correct with non-uniform scaling.

mikael_aronsson
02-26-2003, 01:07 PM
Hi !

It does not cost anything because the hardware can do it in a way that it does not impact speed.

You still have to calculate the normals, GL_NORMALIZE just keeps them correct when you start to scale.

I could be wrong on the non uniform issue, I am not sure.

Mikael

roffe
02-26-2003, 02:58 PM
Originally posted by mikael_aronsson:

You still have to calculate the normals, GL_NORMALIZE just keeps them correct when you start to scale.

I could be wrong on the non uniform issue, I am not sure.


There are two normal "rescaling" operations in opengl. GL_NORMALIZE which does a full recalculation of the vector length and then there is GL_RESCALE_NORMAL. If you only use uniform scaling you can get away with only using GL_RESCALE_NORMAL.

mr_coolio
02-27-2003, 12:42 AM
Originally posted by roffe:
There are two normal "rescaling" operations in opengl. GL_NORMALIZE which does a full recalculation of the vector length and then there is GL_RESCALE_NORMAL. If you only use uniform scaling you can get away with only using GL_RESCALE_NORMAL.

I can't find GL_RESCALE_NORMAL in the headers nor in the msdn library.

roffe
02-27-2003, 12:56 AM
Originally posted by mr_coolio:
I can't find GL_RESCALE_NORMAL in the headers nor in the msdn library.

Microsofts header files are OpenGL 1.1,
GL_RESCALE_NORMAL is OpenGL 1.2.

Locate some updated header files from your gfx card vendor, unless you're software rendering.

To get you started...
#define GL_RESCALE_NORMAL 0x803A



[This message has been edited by roffe (edited 02-27-2003).]

mr_coolio
02-27-2003, 02:22 AM
well, thanks that was very helpful, folks.

[This message has been edited by mr_coolio (edited 02-27-2003).]