Mesh: Make vertex normal calculation deterministic #111718

Merged
Hans Goudey merged 9 commits from HooglyBoogly/blender:mesh-normals-deterministic into main 2023-11-10 15:19:13 +01:00

9 Commits

Author SHA1 Message Date
Hans Goudey b9a40350b9 Merge branch 'main' into mesh-normals-deterministic
buildbot/vexp-code-patch-coordinator Build done. Details
2023-11-10 14:42:43 +01:00
Hans Goudey e5b9049dba Fix error
buildbot/vexp-code-patch-coordinator Build done. Details
2023-11-09 10:25:28 +01:00
Hans Goudey bea3ee1f2d Merge branch 'main' into mesh-normals-deterministic 2023-11-09 10:15:39 +01:00
Hans Goudey 87e77133ee Merge branch 'main' into mesh-normals-deterministic 2023-11-09 09:06:00 +01:00
Hans Goudey f6f708a759 Remove "fast" option 2023-09-11 12:22:54 -04:00
Hans Goudey 96e54617a4 Merge branch 'main' into mesh-normals-deterministic 2023-09-11 12:12:59 -04:00
Hans Goudey 5f796cf33c Merge branch 'main' into mesh-normals-deterministic
buildbot/vexp-code-patch-coordinator Build done. Details
2023-09-08 10:23:19 -04:00
Hans Goudey a5ccfad3d8 Cleanup 2023-08-30 22:23:20 -04:00
Hans Goudey 05fedab237 Mesh: Refactor vertex normals for determinism
Currently, atomic additions in vertex normal calculation introduce
non-determinism that can influence the result of other operations,
sometimes causing non-reproduceable renders (in cases like #100250).
This is because the order used during threading when accumulating face
normals changes.

This commit fixes that non-determinism, using a vertex to face topology
map to calculate vertex normals normals without atomics. When the map is
already available, this can be faster too.

Internally, a new "fast" code path is available too. This avoids
weighting face normals by the corresponding corner angle when averaging
them to create face normals. This significantly reduces the necessary
computation and memory bandwidth for vertex normal calculation.

The "fast" option is included in this PR as a way to potentially reduce
the peformance impact of requiring the topology map.

TODO:
- [ ] Run performance tests in differenct smooth shading use cases
  - [ ] Large mesh build from scratch every frame
  - [ ] Armature deformation of large mesh without subdivision
- [ ] Test "fast" option and expose toggle in UI if it's worth it

In the longer term future, this method of vertex normal calculation
means it will be easier to do partial recalculations when only part
of a mesh changes. That might be essential for cases like transforming
small selections in a non-BMesh edit mode.
2023-08-30 18:54:43 -04:00