Scaling problem.

Started by
4 comments, last by karwosts 14 years ago
Hey guys. Im developing an opengl app for the ipad and for some reason when i scale my object down it gets brighter and brighter and when i scale it up it gets darker and darker. Any ideas for why this is happening and how to fix it? Thanks!
Advertisement
Sounds like you aren't normalizing your normals. I assume you are using the default pipeline so just add this line at the start of your code:

glEnable(GL_NORMALIZE);
That did the trick! Thanks a lot! How much better off would I be if I normalized them myself ahead of time?
That's not the problem.

When you scale your models, the normals get multiplied by the matrix so get scaled as well. glEnable(GL_NORMALIZE) tells OpenGL to normalize the normals after this transformation so they are normalized for the lighting equations.

Normalizing before hand is a good habbit but it wouldn't affect this problem.
Ok. Thanks a lot! =)
Just to throw in a tip:

If you are only performing uniform scaling (equally in all dimensions), then you may get higher performance by enabling GL_RESCALE_NORMALS instead of GL_NORMALIZE

With rescale normals the normals are simply divided by the model scale, instead of performing the more expensive normalization function for every vertex.

Source:
Avoiding Common OpenGL Pitfalls
Read section 1


Also if you are concerned with perf you should disable these when you are dealing with objects that you know are unscaled, as this will cause performance hit in your vertex shader.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game

This topic is closed to new replies.

Advertisement