The GLSL definition for “gl_NormalMatrix” is “the transpose of the inverse of the gl_ModelViewMatrix.” We might need to add this into the Programmable Renderer as a default. It should be really simple as you just have to invert and transpose the modelViewMatrix. Thoughts @arturo?
the view matrix is the transformation of the camera and is uploaded by default to the shaders as the uniform viewMatrix you probably want that instead of the modelViewMatrix to do light calculations. the normal matrix is not uploaded unless there’s a material binded but can be recovered with the function ofGetCurrentNormalMatrix() and uploaded to your own shaders or you can implement ofBaseMaterial which already uploads the normal matrix as the uniform normalMatrix when it’s binded.
btw, the normal matrix is not always uploaded because it implies calculating a matrix inverse which is relatively expensive and is not needed in most basic cases. so materials upload it themselves in the base class method uploadMatrices which can be overriden and you can get it through a function call and upload it manually to a plain shader if you prefer
I didn’t know about ofGetCurrentNormalMatrix but that may be because I still use a rather old version of OF (and it doesn’t seem to be in the documentation yet).
If it works my use of the normal matrix will be much simpler. Thanks
@Pando Using of_v0.8.4 The code you posted above works for me in terms of converting from OpenGL coordinates to OF coordinates, but when I light the object it’s clearly using its local normals. For example, using this vertex shader: