Godot: SurfaceTool normals can't be smooth when UVs are added

Created on 13 Aug 2016  ·  3Comments  ·  Source: godotengine/godot

Tested on Godot 2.1 beta and 2.1 stable, Windows 10 64 bits

When generating a surface with SurfaceTool and the add_smooth_group(true) method, it's impossible to get smooth normals if UVs are added to vertices.
I found that it specifically happens when UVs are not increasing from one vertice to another. So if every quad of a surface has UVs going from 0 to 1, the quad will be rendered with hard face normals.
Because of this I am forced to generate normals myself.

Not sure if it's a bug because I believe it was implemented so it does that. But as I said, it's possible to have smooth normals even in that case, so this can be enhanced.

Repro:
SurfaceToolSmoothShading.zip
Launch the main scene, see the generated surface on the left with UVs has hard faces, the one on the right doesn't and has smooth faces, while both have a smooth group.

bug confirmed core

Most helpful comment

It still happens:
SurfaceToolSmoothShading.zip

I believe it happens because SurfaceTool assumes smoothing can only happen if vertices are shared, and to be shared vertices must have equal attributes. While it's true this case makes them have different UVs, smoothing should still be possible with two vertices with different UV, but giving two normals having the same value.

All 3 comments

HI @Zylann I was googling in search of the correct way to smooth a code generated mesh and I stumbled upon this.
I am using godot 3.0.4 and, using add_smooth_group as you are I am getting it correctly rendered, with UV.
[edit] I have to correct myself, the issue is still there, but I have to specify, as Zylann did in the code, that it works only if UV are spread over the mesh, but not when repeated for every quad:

# If UVs are spread, normals are smooth.
  var t00 = Vector2(p00.x, p00.z) / Vector2(sx,sy)
  var t10 = Vector2(p10.x, p10.z) / Vector2(sx,sy)
  var t11 = Vector2(p11.x, p11.z) / Vector2(sx,sy)
 var t01 = Vector2(p01.x, p01.z) / Vector2(sx,sy)

@Zylann Can you (or anyone else) still reproduce this bug in Godot 3.2.1 or 3.2.2beta4?

It still happens:
SurfaceToolSmoothShading.zip

I believe it happens because SurfaceTool assumes smoothing can only happen if vertices are shared, and to be shared vertices must have equal attributes. While it's true this case makes them have different UVs, smoothing should still be possible with two vertices with different UV, but giving two normals having the same value.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nunodonato picture nunodonato  ·  3Comments

RebelliousX picture RebelliousX  ·  3Comments

timoschwarzer picture timoschwarzer  ·  3Comments

gonzo191 picture gonzo191  ·  3Comments

testman42 picture testman42  ·  3Comments