mesh: use faster acos() variant in normals calculation #114501
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#114501
Loading…
Reference in New Issue
No description provided.
Delete Branch "aras_p/blender:acos_approx"
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?
acos()
usage in all places related to normal calculations shows up in the profiler. Given that "angle between faces" is only additional heuristic weight in there (the effect of it at all is very subtle), approximate but faster version of acos() might be just fine. Especially since some other parts of Blender (e.g. mikktspace) use approximate acos in a conceptually the same part.This PR:
saacos()
,saasin()
,sasqrt()
since they were 100% identical tosaacosf()
,saasinf()
,sasqrtf()
since 2012.saacosf_approx()
andsaasinf_approx()
toBLI_math_base.h
. Implementation the same as already exists in Cycles; max error 0.00258 degrees.saacosf_approx()
instead ofsaacosf()
.Computing normals on a Stanford Lucy (14m verts) mesh:
All places that are about "normal calculation" were changed, including e.g. Corrective Smooth modifier. Applying that one to the same 14m vertices mesh, Mac M1 Max: 9.96s -> 9.76s
A few points from discussion so far, mostly as discussed in chat:
BLI_math_base.hh
instead of modifying the C API heresaacos
vssaacosf
in a separate PR@blender-bot build
Looks fine to me assuming tests pass.
A further cleanup would be to rename
sa
->safe_
and move them intoBLI_math_base_safe.h
, for consistency.math_geom.c
is still C tho :( Or should I move that to C++ before this, separately?accumulate_vertex_normals_tri_v3
,accumulate_vertex_normals_v3
, andaccumulate_vertex_normals_poly_v3
aren't used in any code that matters right now (only the second in metaball tessellation). So I'd just ignore that file for now.Why not update them anyway? If that code ever gets used or copied, we likely won't remember to apply this optimization.
If there are no objections to moving math_geom.c to .cc then I can try doing just that. Does that need a PR/review, or "just do it"?
Usually a PR is helpful to make sure if compiles on all platforms. But it doesn't need review I don't think.
@blender-bot build
@brecht so the tests do not pass, in exactly one place, which is Suzanne vertex normals. There's several vertices that result in a tiny bit normal difference (like 7th decimal after the dot). And in the OBJ exporter tests that emits only 4 normal digits, several vertices get that tiny difference. And in the
modifiers
test where Suzanne mesh gets a Displace modifier, some resulting vertices are different in position by up to 0.00002. Visually it looks the same and inspecting vertex normals in geometry nodes spreadsheet shows no difference (since it rounds before that).I can update expectations of both tests, but the question is: is this tiny change in vertex normals acceptable or not?
Yes, it's fine. You can just update the tests.
WIP: mesh: use faster acos() variant in normals calculationto mesh: use faster acos() variant in normals calculation