godot: Obscure warning "Attempting to use a shader that requires tangents with a mesh that doesn't contain tangents." is spammed.

Godot version

4.2beta6

System information

Windows 10

Issue description

In all my 4.2beta6 3D projects I get this warning spammed: servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp:3725 - Attempting to use a shader that requires tangents with a mesh that doesn't contain tangents. Ensure that meshes are imported with the 'ensure_tangents' option. If creating your own meshes, add an ARRAY_TANGENTarray (when using ArrayMesh) or callgenerate_tangents() (when using SurfaceTool). (User)

This is absolutely not helping me as I don’t know which mesh this is refering to. The only way that I can get rid of it right now is by basically “drilling down” into individual scenes where this error occures and then find the mesh that is refered by the warning.

This is not a process that is in any way straight forward in a larger project.

The error should have a reference to the mesh in any way (name of the mesh instance, name of the mesh file, name of the scene etc.)

Steps to reproduce

Can’t tell exactly.

Minimal reproduction project

About this issue

  • Original URL
  • State: closed
  • Created 8 months ago
  • Comments: 20 (8 by maintainers)

Most upvoted comments

@Mohamed-Kr the issue of the compatibility renderer always triggering the error is a separate bug that has already been fixed by https://github.com/godotengine/godot/pull/84752. The fix will be in RC1

@fracteed This warning doesn’t have to do with the new mesh format. So the upgrade tool won’t be enough to make the warning go away. We added the warning because using tangents in a shader with a mesh without tangents has become more dangerous than it was before, but it was still problematic before.

The workflow from Blender hasn’t changed. We generate tangents on import in more cases now than we used to, but generating tangents in your 3DCC is still much better to ensure your normal maps have a consistent look between Godot and your authoring tool.

This warning is getting spammed because you are using normal mapping with assets that don’t support tangents. In the case above, the warning came from line primitives that were erroneously exported with the mesh.

To back up a bit, the warning appears when you have: a) a shader that uses tangents (i.e. normal mapping, anisotropy, uses TANGENT, etc.) b) a mesh that doesn’t have a tangent array (pretty rare in 4.2, only happens in meshes that don’t have normals either)

If you are using normal mapping on a mesh without normals, it is most likely an oversight anyway. So, best case scenario you are wasting performance, worst case scenario, you are wasting performance and introducing performance overhead into your scene.

As for workflow, your workflow shouldn’t need to change. But the fact that you are getting this warning likely means that you have been accidentally applying normal mapping to surfaces that can’t really apply normal mapping, which again, means you are wasting performance and potentially introducing visual errors.

On the engine side, I think the warning is a bit too aggressive and is being perceived as a regression even though it is warning you about potential issues that already exist in your project. As described above. I would like to potentially limit the cases that show the warning and try to only show the warning when there is a high chance of visual error.

Okay, some further investigation. The surface triggering the error is using the lines primitive and doesn’t even have normals encoded. But it is sharing the the same normal mapped material as the other surfaces.

The loose edges setting must be responsible for exporting something as a set of lines (instead of triangles).

This is kind of a tricky edge case for us:

  1. We can’t generate tangents for a non-triangulated mesh, or for a mesh without normals.
  2. It likely doesn’t make sense to apply normal mapping to a line without normals or tangents.
  3. BUT there are likely tons of assets exported from Blender without thought that do exactly that.

I think we will just need to adjust the error condition to try to filter out these cases. For example, we could warn only when the primitive type is triangles.

What I am unsure of is whether the lines will look correct. I imagine if they are using a normal map with bogus tangents, the lines are not getting colored correctly. That being said, in your example asset, the lines aren’t even visible.

The offending surface is those purple lines inside the axe head image

Made a PR to assist with this. This particular error message is very tricky as it is deep within the rendering server. Plus meshes can come from many different sources.

What I did in the PR is add in the ability to specify the shader source (if using a custom Shader only) and a mesh source (if using an ArrayMesh only). This should cover most situations where this error occurs. Additionally, as of Beta 5, newly imported and created meshes should almost always have tangent arrays. So this message should become increasingly rare

I am also running into this issue, when trying to convert a 4.1 game over to 4.2. It is definitely a combination of meshes in the native .tres format paired with normal maps. Unfortunately, the upgrade tool doesn’t get rid of the error spam, even though all assets look fine.

I have done some tests and can re-export all of my offending meshes from Blender directly and reconvert to the new .tres mesh format.

@clayjohn my main question is what is the recommended workflow now with mesh tangents? By default glb export from blender has the option off and obj doesn’t even have the option. From some tests, it seems that 4.2 is fine with meshes that weren’t exported with tangents. I have always left the “ensure tangents” option on in godot itself, so had assumed godot could create these itself…maybe this is no longer the case?

It would be good to know what the recommended workflow is for 4.2 onward and if exporting with tangents from blender gives better quality normal mapping?

I took a look at the old file. It appears to be made of 4 surfaces and one of them is exported without tangents.

So I think we have 2 issues here:

  1. Blender isn’t exporting tangents even when the “tangents” checkbox is checked. This appears to be a common theme with Blender, there are many settings for objects that make them silently ignore tangents and export without them
  2. The surface without tangents isn’t getting tangents generated, even though “ensure tangents” is enabled.

If we can resolve 2. the error spam will go away, but your assets might look a bit messed up as they won’t necessarily have the same tangents that you have in Blender. But I guess that is the best we can do.

Hi,

I think I found the gltf export options which trigger the warnings for me.

Under Data -> Mesh there are the options Loose Edges and Loose Points.

When I enable these when exporting a file from Blender the warning gets triggered.

Enabling or disabling the export option Tangents does not trigger the warning.

I hope this additional information will help you fix the problem if there is one.

Tomorrow I can upload the glb file to share it with you.

I exported the 3D file to glb one time with tangens and once without. Both times I’ve got the warning.

Since this is my first time trying 3D with Godot I’m not able to tell if I did something wrong when exporting to glb.

If you could examine this and give me feedback this would be very nice.

@dataCobra Can you share the glb file here so we can take a look?

Also, I’m sure you have already checked, but can you confirm that the error isn’t accurate? I.e. that either your shader doesn’t require tangents, or that the mesh does contain tangents?

This is a new warning that was introduced to flag this problem for users. You can’t rely on tangents with a mesh that doesn’t have tangents. It will break your model in (sometimes) unexpected ways.

@dataCobra Did you run the mesh surface upgrade tool in Project > Tools > Upgrade Mesh Surfaces…?