Non-uniform scaling produces incorrect vertex normals

When applying a non uniform scale to an object, the vertex normals are keeping their original orientations, which does not reflect the shape of the scaled object and causes it to be lit incorrectly. For example, placing a sphere into the world and setting it’s scale along the z-axis to 0.01 should flatten it into a circle, however the normals will not be flattened and will cause the circle to be lit as if it was still a sphere.

The following links describe the problem in more detail.
Link 1
Link 2

Also this problem does not occur if the mesh is imported with a non uniform scale.

Recalculation of normals via the non-uniform scaling in the viewport is a feature that has not been implemented. This may be something that is added in a future build though. For the time being if you need to have your mesh recalculate normals you would want to do this via the build settings in the mesh editor and also set your build scale there as well.

As an example, if you go to the build settings > Build Scale > Set the z to 0.01 as you’ve explained > apply changes, the mesh scale will adjust and recalculate normals for the mesh.

I’ve gone ahead and entered a request for this to be considered by our engineers. The reference number is UE-8751.

Thank you!

Tim

This problem is gating a project at my company. However, this is a very simple problem to solve and is well understood in the realtime graphics literature. I suspect it should only require about three lines of code to change, albeit buried somewhere deep within the UE4 shader generation code.

When normals are transformed inside the body of a shader, they should be multiplied by the INVERSE TRANSPOSE of whatever matrix is used to transform the vertex coordinates. This can typically be computed once and passed into a shader uniform variable. This will correctly account for nonuniform scaling of meshes, and does not require any CPU-side recomputation of anything.

Please see the following references which explain how to solve this problem:
http://web.archive.org/web/20120228095346/http://www.arcsynthesis.org/gltut/Illumination/Tut09%20Normal%20Transformation.html
http://www.lighthouse3d.com/tutorials/glsl-12-tutorial/the-normal-matrix/
https://en.wikibooks.org/wiki/GLSL_Programming/Applying_Matrix_Transformations#Transforming_Normal_Vectors