+1 vote

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!

Godot version 3.3
in Engine by (251 points)
edited by

If you converted a PrismMesh to an ArrayMesh, note that PrismMesh normals were broken until 3.3.1: https://github.com/godotengine/godot/pull/48775

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!

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.