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
SurfaceTool generate_normals seems broken #88839
Comments
I don't have a solution, but I've investigated this a little bit. The mesh is kind of interesting, it contains 21002 indexed vertices, after deindexing and indexing again, it drops to 15882 which means the original mesh is either carrying a lot of unnecessary vertex data or Godot is losing vertex data when calling I'm wondering if your asset authoring tool is more clever than Godot when generating normals. Godot just averages the face normal of all faces that touch a given vertex |
@clayjohn exactly what I did, just calculate all vertex normals based on face normals and then average them, thing is, it does work just fine on Godot 3, but gives weird results on 4. |
Looking at the code I am having trouble figuring out what could be different. The code changes all seem pretty safe and simple. I'm wondering if something in the import process is changing the mesh in a way that impacts how normals are getting generated. I.e. maybe the issue isn't with edit: the biggest change is how smooth groups are treated. Before "smooth_group" was a true or false property that basically meant allow smoothing this vertex with other vertices. In Godot 4.0 smooth group is an id, and vertices only blend with other vertices in the same smooth group. So you can get a lot more detailed with how the smoothing works. |
Okay, checking in Godot 3.5.3, the mesh contains 15882 from the very beginning. So in Godot 4.2 it is indeed carrying too many indices Here is my test code (inserted into your MRP)
In 3.5.3 it prints:
In 4.2.1 it prints:
|
It seems that the difference in number of vertices comes from the LOD generation code. I'm not sure why the code would be adding vertices, but it seems that the difference in vertex count is not the root of this problem as it persists even after disabling LOD generation |
@clayjohn thing is, vertex count shouldn't be a problem if at the end of the day, the mesh is rendered using index-to-vertex logic, which means that as long as the first 15882 vertices and 86640 indices remain unchanged, adding extra vertices shouldn't give any wrong output right? Also I haven't spend a lot of time digging through the source to check what's going on, but I have a guess the problem lies on the arrays to I'll drop by with any concrete information once I get time to dive into the source. |
I spent quite a while on this to narrow down the problem but haven't got much about the issue whatsoever, BUT I did find that the vertex duplication comes from the GLTF itself apparently, since vertices needs to be doubled for correct UV/Vertex color maping. I still have no clue why regenerating normals break this hard |
Tested versions
4.2.1.stable.official
System information
Windows 10
Issue description
Having godot generate the normals from loaded meshes seems to produce terrible outputs.
In the example below I just loaded an
ArrayMesh
, tossed it toSurfaceTool
as surface arrays and called commit after generating normals, no changes were made.Left side the mesh loaded directly to a
MeshInstance3D
, on the right the one that went through theSurfaceTool
, the issue is quite noticeable on he arms[EDIT]
On further inspection, it doesn't seem to be something related to normals themselves, tested manually creating the normals and the result was the same, tested the exact same code that creates normals manually on Godot 3 and it seems to work just fine.
Steps to reproduce
Read above
Minimal reproduction project (MRP)
generate_noormals.zip
The text was updated successfully, but these errors were encountered: