openframeworks / openFrameworks

openFrameworks is a community-developed cross platform toolkit for creative coding in C++.
http://openframeworks.cc
Other
9.94k stars 2.55k forks source link

ofDrawBox() scales normals. #2559

Open neilmendoza opened 11 years ago

neilmendoza commented 11 years ago

ofDrawBox() uses scaling for it's size so normals are also scaled and any scene with lighting will end up looking wrong.

arturoc commented 11 years ago

ofEnableLighting is enabling GL_NORMALIZE which should fix that.

neilmendoza commented 11 years ago

I just assumed that ofDrawBox should produce a box with correct normals. If people are writing their own lighting code they may not enable GL_NORMALIZE as there's a performance hit to it.

tgfrerer commented 11 years ago

Hey Neil!

This is a tricky one: if we don't use scaling for ofDrawBox, we'd have to get a new mesh primitive for every box drawn, which would totally zilch any performance gains for not using GL_NORMALIZE.

You can, however, use glEnable(GL_RESCALE_NORMAL) which is more performant in case your modelView Matrix is orthogonal (= as long as there is no shearing).

I'm seeing another issue with ofBoxPrimitive; is it possible that the normals are inverted? If you have a normal shader at hand, could you check the normals you get drawn by comparing ofDrawBox to ofDrawSphere, @neilmendoza ?

Also note that if you are using the ofGLProgrammableRenderer, the normals in an ofVbo are submitted in a more modern way, where they will automatically be normalized when submitted to GPU memory.

See: https://github.com/openframeworks/openFrameworks/blob/master/libs/openFrameworks/gl/ofVbo.cpp#L689

arturoc commented 11 years ago

we could have a normalizeNormals method in of3dPrimitive that way the default will be fast enough to draw lots of primitives using ofDrawBox but you can define your own primitives for using them with custom settings