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