Mesh: Make vertex normal calculation deterministic #111718
No reviewers
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#111718
Loading…
Reference in New Issue
No description provided.
Delete Branch "HooglyBoogly/blender:mesh-normals-deterministic"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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
and #101726). 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 without atomics. When the map is already
available, this can be faster too.
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.
As an experiment I tried a "fast" code path that avoids weighting face
normals by the corresponding corner angle when averaging them to
create vertex normals. This significantly reduces the necessary
computation and memory bandwidth for vertex normal calculation.
The results are shown below too, but it's not part of this PR.
I measured the FPS with two smooth shaded 16 million face grids:
Though many other things besides normals are being tested here,
it's clear that the performance difference isn't that large either way,
though there is an observable regression with meshes created from
scratch, and there is a noticeable improvement when the topology
stays the same and is persistent.
Mesh: Refactor vertex normals for determinismto Mesh: Make vertex normal calculation deterministicTo reviewers, I'm very curious about your opinions here! It is it worth a slight performance regression for non-persistent mesh topology to have deterministic normals? Or should we focus more on the deformation use case where this is actually an improvement? Is it worth keeping the old atomic code around if we go with this? Is "requiring" the memory for the vertex to face topology map okay? How can we factor in code simplicity and consistency between CPU and GPU implementations or other longer term benefits? This PR is helpful to those long term goals IMO.
Also, I'd like to keep in mind that we shouldn't need to calculate vertex normals at all when the mesh is shaded flat. I'll be able to address that after #108014 lands.
There is other issue I reported #110430 and i found that is caused by the normal calculation, this changes add some new issues to text objects solidify modifier
411cd827b736
#112065 optimizes the topology map creation a bit more. I hope that can help lessen the performance regression in the "Created from scratch every frame" case.
I'll probably remove the "fast" option from this commit and consider that separately, but I'll wait for some response in this PR first, just so people can see it.
@blender-bot build
The performance seems acceptable if it's slower in some cases and faster in others. The memory usage seems like the main downside to me.
I wanted to try integer quantization as described in #101726, but also don't have a lot of time for this now. So maybe this solution is ok.
Right. This method does require the topology map for cases where it probably wouldn't be required otherwise. However, the topology map is already used for other things (everywhere
vert_to_corner_map
is used currently) and I hope to use it more in the future for things like attribute interpolation. So I'd consider the cost amortized over more features. And overall it's less than the memory required for a UV map, for example.Sounds interesting! Though one thing I like about this solution is that it makes the normal calculation simpler, with no need for atomics or temporary arrays of intermediate values. It also works equally for any mesh topology. Obviously can't rule out integer quantization without trying it though! That could still be investigated as a second option in the future.
Mesh: Make vertex normal calculation deterministicto WIP: Mesh: Make vertex normal calculation deterministicIt's unfortunate about the memory usage, but I don't think that should hold this up.
WIP: Mesh: Make vertex normal calculation deterministicto Mesh: Make vertex normal calculation deterministic@blender-bot build
@blender-bot build