Mesh: Share normals caches by splitting vertex and face calculation #110479
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#110479
Loading…
Reference in New Issue
No description provided.
Delete Branch "HooglyBoogly/blender:mesh-vert-face-normals-split"
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?
Since vertex and face normals can be calculated separately, it simplifies
things to further separate the two caches. This makes it easier to use
SharedCache
to avoid recalculating normals when copying meshes.Sharing vertex normal caches with meshes with the same positions and
topology allows completely skipping recomputation as meshes are
copied. The effects are similar to
e8f4010611
, but normals are muchmore expensive, so the benefit is larger.
In a simple test changing a large grid's generic attribute with geometry
nodes, I observed a performance improvement from 12 to 17 FPS.
Most real world situations will have smaller changes though.
Completely splitting face and vertex calculation is slightly slower
when face normals aren't already calculated, so I kept the option
to recalculate them together as well.
This simplifies investigating the changes in #105920 which resolve
non-determinism in the vertex normal calculation. If we can make the
topology map creation fast enough, that might allow simplifying this
code more in the future.
5820eb501c
to1b5f7de7c2
Mesh: Split vertex and face normal calculationto Mesh: Share normals caches by splitting vertex and face calculationGenerally seems fine, but would of course be fine if we could avoid the slowdown if possible. Right now, it's not clear to me if it's at all possible to have no slowdown while still making normal calculation deterministic like you did in #105920. It would be good if you could describe a bit better why there is non-determinism in the first place and how it impacts other parts of Blender.
Ignoring the non-determinism issue, it seems like it might be possible to keep the same performance while still having two separate shared caches, at the cost of a bit more complexity. This could be achieved by calling
face_normals_cache.ensure
directly fromMesh::vert_normals()
. Then one could have a specialized implementation that computes the vertex and face normals at the same time if the face normals are not available yet.The changes seem fine but it would be good if the slowdown could be avoided for the common code path for animation playback.
Could there be a function that calculates vertex & face normals at once which is called from
BKE_mesh_ensure_normals_for_display
for e.g.From my own tests this can slow down animation playback ~6%, tested with a single modifier an 2.5million quads.
While not a large amount, it's noticeable and would be good to avoid if possible.
Thanks for the comments! I added back the code calculating both vertex and face normals together, in addition to the option of separating them. I think this is now ready, though I'll run some more performance tests on my desktop when I'm back home, just to get some "X times faster" numbers.
Re-tested, if anything this is a little faster now (~1-3%).
Some notes inline but nothing blocking.
@ -83,3 +81,1 @@
Span<int> corner_verts,
MutableSpan<float3> face_normals,
MutableSpan<float3> vert_normals);
void normals_calc_verts(Span<float3> vert_positions,
Worth adding a note about
normals_calc_faces_verts
in the doc-string as it may be preferred.@ -289,3 +275,1 @@
}
});
}
static void normals_calc_faces_verts(const Span<float3> positions,
suggestion, but this reads a bit like face-verts which is sometimes used for faces-of-verts: I find this makes it clearer that the function is calculating both the values at once:
normals_calc_faces_and_verts
.(this knit-pick applies to the old function too).
@blender-bot build
@blender-bot build