Fix #110169: nearly flat normalized fcurves jump around in editor #110796

Merged
Nathan Vegdahl merged 3 commits from nathanvegdahl/blender:fix_110169_broken_fcurve_normalization into main 2023-08-07 10:53:10 +02:00
Member

The root cause was a classic fixed-size epsilon issue. The code that
checked if an fcurve was effectively flat, and thus shouldn't be
normalized, used a fixed-size epsilon that was reasonable for values
close-ish to zero, but didn't work well for values >= 1.0.

This patch addresses the issue by introducing a robust ulps-based
comparison, to ensure that a minimum number of representable floats
exist between the min/max values of the curve. This approach scales
appropriately up and down to both huge and tiny values.

The root cause was a classic fixed-size epsilon issue. The code that checked if an fcurve was effectively flat, and thus shouldn't be normalized, used a fixed-size epsilon that was reasonable for values close-ish to zero, but didn't work well for values >= 1.0. This patch addresses the issue by introducing a robust ulps-based comparison, to ensure that a minimum number of representable floats exist between the min/max values of the curve. This approach scales appropriately up and down to both huge and tiny values.
Nathan Vegdahl added 1 commit 2023-08-04 15:59:42 +02:00
d7f5974ad6 Fix #110169: nearly flat normalized fcurves jump around in editor
The root cause was a classic fixed-size epsilon issue.  The code that
checked if an fcurve was effectively flat, and thus shouldn't be
normalized, used a fixed-size epsilon that was reasonable for values
close-ish to zero, but didn't work well for values >= 1.0.

This patch addresses the issue by introducing a robust ulps-based
comparison, to ensure that a minimum number of representable floats
exist between the min/max values of the curve.  This approach scales
appropriately up and down to both huge and tiny values.
Nathan Vegdahl requested review from Christoph Lendenfeld 2023-08-04 16:01:34 +02:00
Nathan Vegdahl requested review from Brecht Van Lommel 2023-08-04 16:01:48 +02:00
Author
Member

I wrote a new ulps-based function ulp_diff_ff() to implement this fix. I think this new function will generally be useful in resolving certain kinds of floating point issues in the future as well. The advantage of it over the existing compare_ff_relative() is that the latter also includes a standard epsilon-based comparison, and if the epsilon is zero the ulps-based comparison doesn't work correctly between floats of different sign. So this new function allows robust pure ulps-based thresholds to be used.

However, I can sometimes be a little overzealous about floating point issues. So maybe this is overkill. I'm also not totally sure if I've even put the function in the best place (e.g. maybe one of the new C++ files would be a better place for new functions?).

I wrote a new ulps-based function `ulp_diff_ff()` to implement this fix. I think this new function will generally be useful in resolving certain kinds of floating point issues in the future as well. The advantage of it over the existing `compare_ff_relative()` is that the latter also includes a standard epsilon-based comparison, and if the epsilon is zero the ulps-based comparison doesn't work correctly between floats of different sign. So this new function allows robust pure ulps-based thresholds to be used. However, I can sometimes be a little overzealous about floating point issues. So maybe this is overkill. I'm also not totally sure if I've even put the function in the best place (e.g. maybe one of the new C++ files would be a better place for new functions?).
Nathan Vegdahl added the
Module
Animation & Rigging
label 2023-08-04 16:13:04 +02:00
Nathan Vegdahl added this to the Animation & Rigging project 2023-08-04 16:13:11 +02:00

Can we use ulp_diff_ff in the implementation of compare_ff_relative, since it seems like it would correct some issues there?

I think there's usually a good reason to do both absolute and relative comparisons like compare_ff_relative. Relative differences don't work well near zero, there can be bigger errors when the value comes from a computation that involved bigger values.

Can we use `ulp_diff_ff` in the implementation of `compare_ff_relative`, since it seems like it would correct some issues there? I think there's usually a good reason to do both absolute and relative comparisons like `compare_ff_relative`. Relative differences don't work well near zero, there can be bigger errors when the value comes from a computation that involved bigger values.

ulp_diff_ff(min_coord, max_coord) > 64 this means there are 64 floating point steps between min and max?
I think we can bump that even further since the drawing is still a bit weird at that value
The difference between the values here is 0.00001
image

`ulp_diff_ff(min_coord, max_coord) > 64` this means there are 64 floating point steps between min and max? I think we can bump that even further since the drawing is still a bit weird at that value The difference between the values here is 0.00001 ![image](/attachments/279b6efb-a6d8-4d2b-ab28-3f511c5f41f4)
Author
Member

Can we use ulp_diff_ff in the implementation of compare_ff_relative, since it seems like it would correct some issues there?

Will do.

I think there's usually a good reason to do both absolute and relative comparisons like compare_ff_relative. Relative differences don't work well near zero, there can be bigger errors when the value comes from a computation that involved bigger values.

Agreed. compare_ff_relative definitely has its place as well. But in some cases (such as this fix, I think) a pure ulp-based approach is more appropriate. It's good to have both available.

> Can we use `ulp_diff_ff` in the implementation of `compare_ff_relative`, since it seems like it would correct some issues there? Will do. > I think there's usually a good reason to do both absolute and relative comparisons like `compare_ff_relative`. Relative differences don't work well near zero, there can be bigger errors when the value comes from a computation that involved bigger values. Agreed. `compare_ff_relative` definitely has its place as well. But in some cases (such as this fix, I think) a pure ulp-based approach is more appropriate. It's good to have both available.
Author
Member

I think we can bump that even further since the drawing is still a bit weird at that value

Good call. I was trying to be conservative, but I think you're right that I was being over-conservative in this case.

> I think we can bump that even further since the drawing is still a bit weird at that value Good call. I was trying to be conservative, but I think you're right that I was being over-conservative in this case.
Nathan Vegdahl added 1 commit 2023-08-04 18:19:44 +02:00
e5d2c923d1 Fix: compare_ff_relative() could be wrong with floats of different signs
Specifically, when relying on the ulps code path.  This commit changes
it to use the more robust ulp_diff_ff() for its ulps code path.
Nathan Vegdahl added 1 commit 2023-08-04 18:35:32 +02:00
Brecht Van Lommel approved these changes 2023-08-04 20:26:26 +02:00

@blender-bot build

@blender-bot build
Nathan Vegdahl merged commit d4d0daa934 into main 2023-08-07 10:53:10 +02:00
Nathan Vegdahl deleted branch fix_110169_broken_fcurve_normalization 2023-08-07 10:53:11 +02:00
Sign in to join this conversation.
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 Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#110796
No description provided.