Currently I'm trying to get lighting working on a cylinder object made in blender (a basic cylinder scaled on the z-axis, no further processing done) and load this object in via Assimp with the following options aiProcess_GenSmoothNormals | aiProcess_Triangulate | aiProcess_CalcTangentSpace | aiProcess_FlipUVs
. In blender's wavefront export options the triangulate
option is set.
The problem is with some scaling done on the cilinder (usually above a certain scaling treshold) my OpenGL implementation shows the normals inversed (I have a geometry shader that shows the normals) and because it inverses the normals, the lighting is inversed as well. This only happens with these cylinder-like objects with certain scaling (at least, only then it occured to me). Every other object in my scene works fine, except these cylinders.
I have no idea if this has to do with how Assimp loads .obj files, or the way blender handles normals when exporting or maybe it has to do with a large z-scale in that it destroys normal interpolation or anything? Below you'll find an image of the inversed normals (left) and the correct normals (right) where the inverse-normal object has a large z-scale done via blender.
I manually triangulated the cylinders in blender this time and validated their normals. The normals of all the cylinders are correct and then exported as they are. However, one pipe now has correct lighting, but the other pipes still have their normals inversed while they have the same triangulation as the working pipe, which is confusing. The following image shows the normals of the cylinders.
Oké I figured something out. Once I started scaling the correctly lighted pipe to the exact same scale as the incorrect pipe (left one) then the normals of the correct pipe were inversed again (inversed in my OpenGL program, in Blender the normals still look fine). So a scale in the length of the cylinders definitely has something to do with their normals getting inversed, although I don't know what that could be.
The problem with the inversed normals was caused by an inverse scale in Blender. When downscaling below the 0
treshold the object starts to grow again (with negative scale), which wasn't immediately visible due to the fact that an inverse-scaled cylinder looks the same as a normal scaled cylinder.
Due to how blender scaling works, some mouse movements tend to suddenly jump from a positive scale to a negative scale when scaling which caused some of my cylinders to be negatively scaled. A negatively scaled cylinder has inversed normals when exporting the object to .obj
. I would call this a bug in blender, since this wasn't visible from the normals Blender itself was showing (they looked correct).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With