Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
RPicster opened this issue Nov 14, 2023 · 29 comments · Fixed by #84894

Comments

@RPicster
Copy link
Contributor

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

@akien-mga
Copy link
Member

akien-mga commented Nov 14, 2023

Referencing the mesh is difficult, as this happens in the rendering server. The way servers are designed is that they receive data and commands and act on them - they don't know where the data comes from and can't find back what scene-level node or resource triggered this. It's done this way for performance reasons, a two-way communication path between scene and servers would kill performance.

But to be clear I fully agree that getting those warnings without any traceability if less than helpful.

There might be ways to get some more info though, I'm not familiar with the details. CC @clayjohn

It would not be a solution for end users, but from advanced users you could compile Godot with debug symbols, and then put a breakpoint where this warning is emitted, to get a stacktrace and see where the call orginated in scene space.

@clayjohn
Copy link
Member

clayjohn commented Nov 14, 2023

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

@YuriSizov YuriSizov modified the milestones: 4.2, 4.3 Nov 14, 2023
@Mohamed-Kr
Copy link

This happens to me each time a gizmo (that serves as 3D transform handle in the editor, not sure about how they are called) appearance is updated, for example when they get displayed, hidden or hovered.

Godot v4.2.beta6 - Windows 10.0.22621 - GLES3 (Compatibility) - Intel(R) Iris(R) Plus Graphics (Intel Corporation; 27.20.100.9621) - Intel(R) Core(TM) i7-1065G7 CPU @ 1.30GHz (8 Threads)

@Mohamed-Kr
Copy link

And it is specific to the compatibility renderer.

@clayjohn
Copy link
Member

@Mohamed-Kr the issue of the compatibility renderer always triggering the error is a separate bug that has already been fixed by #84752. The fix will be in RC1

@dataCobra
Copy link

dataCobra commented Nov 27, 2023

Hey I'm on RC2 and still get this error.

Linux 64bit Godot 4.2 RC2

@akien-mga
Copy link
Member

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

@dataCobra
Copy link

dataCobra commented Nov 27, 2023

Hey @akien-mga,

no I did not.

I've created a completely new project and imported the glb file.

This does not happen on version 4.1.3.

Update: I tried using the tool without success. Problem is still there.

@clayjohn
Copy link
Member

@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
Copy link

dataCobra commented Nov 27, 2023

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
Copy link

Hey, here is the link to my nextcloud with a zip which contains two glb files.

https://cloud.netcobra.de/s/fMxbgwHHMMFTtQQ

One with the export tangents option enabled and the other has it disabled.

Please let me know when you downloaded the files so I can disable the link.

@dataCobra
Copy link

Okay I don't know what has changed but the new exports I put into the zip file are not triggering the warning. 🙄

Here is the link to the old file which did trigger the warning message.

https://cloud.netcobra.de/s/o2FJ6dCg8TAsdgC

Please let me know when you downloaded the files so I can disable the link.

@dataCobra
Copy link

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.

@clayjohn
Copy link
Member

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.

@clayjohn
Copy link
Member

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

@dataCobra
Copy link

Thank you for the time to explain the topic in this detail. 👍

So it seems to be a user made issue. More specific an issue in the way I exported the file.

I don't even know exactly why I enables both loose options in the first place. 🤷‍♂️

@fracteed
Copy link

fracteed commented Dec 3, 2023

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?

@clayjohn
Copy link
Member

clayjohn commented Dec 3, 2023

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

@fracteed
Copy link

fracteed commented Dec 4, 2023

@clayjohn thanks for the detailed reply! I probably ran into a corner case situation as I am using a large number of .tres meshes that were converted in the early 4.0 days and worked fine up until now. They would have been originally exported as objs from blender (which has no option for tangents), so the tangents would have been created by godot presumably upon import.

Anyway, I now know to export glb from blender with the tangent option on. Not sure why that is off by default, maybe to cut down on file size? Most of my normal mapping is using triplanar rather than uv''s so there is probably no difference visually, but it sounds like good future proofing to export with tangents. I don't tend to use obj much any more anyway.

Even though this wasn't directly related to the new mesh format, hopefully the mesh format has been locked down for the foreseeable future :)

@vila4480
Copy link

vila4480 commented Dec 10, 2023

Hope this helps in any way: of all the imported assets in my game, only a custom Terrain3D was causing this issue. I tried recreating the Terrain3D node in v4.2.1 RC1 but I get the same warnings.
Stopped getting the warnings when I removed the Terrain3D node. I can still use its MeshInstance3D with the same shape, but I'm not sure how to fix it for the Terrain3D itself (my concern being the performance of a large terrain and the ability to adjust it in-editor).

EDIT: Sorry, apparently it is directly related to the Terrain3D plugin. The devs have issued a nightly build to cover this issue, here's a quote from their releases page: "For Godot 4.2, use the nightly build ... from 4d844c4 which fixes some error spam."
I updated the plugin and I no longer get that warning spam.

@Zylann
Copy link
Contributor

Zylann commented May 31, 2024

My terrain plugin uses a chunk mesh with minimal vertex data which is displaced in shader and re-used for every chunk. That means normals, binormals and tangents can't possibly come from the mesh, they are generated in the shader. The mesh therefore only contains vertices, no normals, no tangents, nothing else. It is also not using any form of compression, because it is made from code.
Someone tried to assign tangents in the vertex shader to test something, but then this warning started spamming.
What should be done in that case? Is it impossible to use TANGENT and should a custom varying be used? Won't that potentially cause issues when Godot's internal shader code assumes TANGENT should have the right values or has/hasn't been assigned?

@clayjohn
Copy link
Member

I guess our only option is to add the ability to disable the warning.

@Zylann
Copy link
Contributor

Zylann commented May 31, 2024

How would it be specified though? If this is a project setting, that would also silence relevant warnings, not just the irrelevant ones, because it's global. This is also not good for plugins because it would require user action. I suppose a shader hint could be better, but I dont know if it's possible. Another thing could be to figure out if the shader reads TANGENT rather than referencing it at all, because in the present case the shader only writes, not read.

@viktor-ferenczi
Copy link
Contributor

viktor-ferenczi commented Aug 16, 2024

If you are using normal mapping on a mesh without normals, it is most likely an oversight anyway.

Is there a way to silence this warning?

I'm getting this warning on Godot 4.3 (final, release) with my voxel shader which is setting NORMAL, TANGENT and BINORMAL, but uses a very basic cube mesh to render the voxels into which has none of those. So apparently there is a use case when this is not an oversight.

Related ticket of my voxel plugin

Please reopen this ticket and either disable this warning by default or provide a way to disable it.

Thanks!

@viktor-ferenczi
Copy link
Contributor

I guess our only option is to add the ability to disable the warning.

We need a way to disable any warning in a project, because issues like this can happen in many different subsystems.

@clayjohn
Copy link
Member

I guess our only option is to add the ability to disable the warning.

We need a way to disable any warning in a project, because issues like this can happen in many different subsystems.

Please open a new bug report as you are asking for something different from the OP

@Calinou
Copy link
Member

Calinou commented Aug 16, 2024

We need a way to disable any warning in a project, because issues like this can happen in many different subsystems.

This already exists as Engine.print_error_enabled = false, which disables all error/warning prints until you use Engine.print_error_enabled = true. Please read its documentation before using it though 🙂

@vila4480
Copy link

We need a way to disable any warning in a project, because issues like this can happen in many different subsystems.

This already exists as Engine.print_error_enabled = false, which disables all error/warning prints until you use Engine.print_error_enabled = true. Please read its documentation before using it though 🙂

That suggestion disables all errors and warnings which is not the intended purpose of his request though.
A bit disappointed that this issue is taking so long to fix.
I have hundreds of assets in my game and I get an error like this for each one.

@viktor-ferenczi
Copy link
Contributor

Added a Godot proposal to introduce configurable log filters/limits:
godotengine/godot-proposals#10471

Please continue the discussion there. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.