5

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.

incorrect and correct normals


edit

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.

Normals of pipes in blender


edit

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.

Joey Dewd
  • 1,804
  • 3
  • 20
  • 43
  • Have you tried adding `aiProcess_FixInfacingNormals` to your bit mask? – Andon M. Coleman Jan 16 '14 at 20:44
  • @AndonM.Coleman did not work unfortunately. Still the same problem – Joey Dewd Jan 16 '14 at 21:04
  • By default blender creates a cylinder with ngon caps, have you tried changing them to triangles before scaling or export? – sambler Jan 17 '14 at 07:00
  • @sambler yeah I always export to wavefront with the `triangulate` option set. I'll edit that into the question. – Joey Dewd Jan 17 '14 at 09:11
  • But what about manually triangulating and setting normals? the exporter may mix up normals as it triangulates. – sambler Jan 17 '14 at 09:31
  • @sambler I tried triangulating them in Blender and checking their normal values and for a weird reason one of my pipes has correct lighting, but the other pipes still have incorrect lighting while their normals are the same. I will edit in a picture to show the issue – Joey Dewd Jan 17 '14 at 10:05
  • Can this be the classical case of normal distortion with non-uniform scales? – mlvljr Sep 22 '14 at 12:58
  • 1
    @mlvljr It's a rather old question and I believe I've solved the issue, but appareantly not created an answer to this question. Non-uniform scales was not the issue. The issue was that inverse scaling the objects (which was not visible in the scene, since an inversed cylinder is still the same cylinder) caused the normals to ivnerse as well. I'll create an answer for this question. – Joey Dewd Sep 22 '14 at 13:47
  • 1
    ok, interesting to know – mlvljr Sep 22 '14 at 13:55

1 Answers1

2

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).

Joey Dewd
  • 1,804
  • 3
  • 20
  • 43