Incorrect vertex normals on mesh imported from Blender

Godot Version

v4.2.1.stable.mono.official [b09f793f5]

Question

I have been trying to create a certain effect in a spatial shader, which relies on having correct vertex normals within the vertex shader. But I kept getting confusing results. So I eventually went to the very basics, with a cube whose normals I was absolutely sure of. I found that vertex normals are apparently just not being imported correctly by Godot. But I don’t understand why this is happening or how to fix it.

I have a test cube in Blender. I have used a Python script to verify, beyond doubt, that the cube’s normals are correct, within Blender’s representation of the mesh. In this image, I have assigned vertex (specifically loop/face corner) colors to visualize normals. Using Blender’s “Standard” color space, the face colors are (255, 0, 0), (0, 255, 0), and (0, 0, 255) as expected. I have also used print to show the vectors in Blender’s console to be absolutely certain.

image

I imported the cube *.blend file in Godot, and placed it in a scene. Here’s Godot’s import settings for the cube asset:

I wrote a shader that sets colors based on vertex normals. I found that the normals for the vertices on the top and bottom faces of the cube were not correct.

Here’s images to demonstrate:

Here, the left face color is (0, 0, 255) as expected. The right face color is (255, 0, 0) as expected. The top face color is (0, 248, 217), which is not expected. The top face color should have been (0, 255, 0).

Here, you can see that the vertex normals on the top face are approximately (0, 0.866, -0.5).

On the bottom face, approximately (0, -0.866, -0.5).

Somehow, these normal vectors have ended up with an unwanted negative Z component.

How is this happening, and what can I do to fix it?

I’d check this mode:

and see if they are being smoothed in any way, and if they are I’d check the import settings and toggle things like ‘Generate Tangents’, ‘Optimize Mesh’ off and on and see if that helps.

Also I’d check your settings out of Blender, I know in Maya there are some FBX export settings that can be a pitfall.

Ah, it did actually end up being related to tangents, although I don’t understand why changing how tangents are imported affected how normals are imported. The normals are fixed after checking “Ensure tangents” in the *.blend file import settings and re-importing.

I don’t actually intend to use the tangents for anything, though, and so it seems like just extra needless buffers. It would be nice to be able to just import the normals as they are defined in the *.blend file without also creating tangents.