Non-Uniform Scaling Mesh breaks World-Space Normals, am I using ensure_correct_normals Wrong?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By path9263

When I scale a mesh in a non-uniform way the Normals get broken. From what I understand using ensure_correct_normals / flags_ensure_correct_normals is supposed to fix this but it doesn’t seem to do anything for me. It seems to be only the angled face that is broken.

You can download this Godot project here.

In the image below there are 4 meshes with a shader that colors the surface red based on the world X-axis normal value: surfColor.r = world_norm.x;, see the full shader code below. I do want this in world space!

In the Image below:

  • The cube mesh shows how only the side facing X+ is red.
  • The triangular mesh on the right was scaled in blender before being
    imported so the normals are correct.
  • The mesh in the middle was scaled in Godot along the X axis and the normals are wrong, it should be the same red color as the other two meshes.
  • The mesh on the left is the same as the middle one but not scaled and instead rotated so it is at the same angle.

The more you stretch the middle mesh the redder it gets which is the opposite of what should happen.

enter image description here

Full shader code:

shader_type spatial;
render_mode ensure_correct_normals;

varying vec3 world_norm;
varying vec3 surfColor; 

void vertex() {
	world_norm = normalize((WORLD_MATRIX * vec4(NORMAL, 0.0)).xyz);
	surfColor = vec3(0,0,0);  //colorTint.rgb;
	surfColor.r = world_norm.x;// - 0.5;
	//surfColor.g = world_norm.y;

void fragment() {
	ALBEDO = surfColor;

Am I using ensure_correct_normals wrong? Am I not calculating the world_norm correctly? Is this a bug?

Thank you for any help you can give!

If you converted a PrismMesh to an ArrayMesh, note that PrismMesh normals were broken until 3.3.1: Fix normals of PrismMesh by CaptainProton42 · Pull Request #48775 · godotengine/godot · GitHub

Calinou | 2021-06-10 14:51

My meshes are imported from blender so I don’t think this is the problem but thanks! I tried upgrading to 3.3.2 anyway to see if something else would fix it but still no luck!

path9263 | 2021-06-16 21:05