Animation: Common curve drawing for FCurves #110764

Merged
Christoph Lendenfeld merged 7 commits from ChrisLend/blender:graph_common_curve_drawing into main 2023-08-10 15:33:30 +02:00

Before this patch, the drawing code iterated the FCurve to see if there are any
curve interpolation types that can't easily be drawn. (Sinusoidal, Bounce, etc)
If it found one, it would fall back to evaluating the FCurve.

That meant in the worst case scenario it would iterate the whole FCurve
before even starting to draw.

This PR unifies the drawing logic for FCurves no matter their interpolation type.
If it encounters a key type that it can't draw, it falls back to samples, but only
for the current key.

To clarify that it renames draw_fcurve_curve_bezts to draw_fcurve_curve_keys

Curves with modifiers are still drawn with samples.

Performance

Test setup: 6000f of dense data on 62 bones. Only measuring the average draw time per curve. All measurements were done at the same zoom level.

- before after
only beziers 28μs 13μs
only elastic 90μs 60μs
mix (~1/2 of the view with elastic) 110μs 24μs

The performance boost with "only elastic" can be explained by the fact that per key I can skip 1 call to evaluate_fcurve. That is because I always start at an existing keyframe so I can use its position.

Before this patch, the drawing code iterated the FCurve to see if there are any curve interpolation types that can't easily be drawn. (Sinusoidal, Bounce, etc) If it found one, it would fall back to evaluating the FCurve. That meant in the worst case scenario it would iterate the whole FCurve before even starting to draw. This PR unifies the drawing logic for FCurves no matter their interpolation type. If it encounters a key type that it can't draw, it falls back to samples, but only for the current key. To clarify that it renames `draw_fcurve_curve_bezts` to `draw_fcurve_curve_keys` Curves with modifiers are still drawn with samples. ## Performance Test setup: 6000f of dense data on 62 bones. Only measuring the average draw time **per curve**. All measurements were done at the same zoom level. | - | before | after | | - | - | - | | only beziers | 28μs | 13μs | | only elastic | 90μs | 60μs | | mix (~1/2 of the view with elastic) | 110μs | 24μs | The performance boost with "only elastic" can be explained by the fact that per key I can skip 1 call to `evaluate_fcurve`. That is because I always start at an existing keyframe so I can use its position.
Christoph Lendenfeld added the
Module
Animation & Rigging
label 2023-08-03 16:32:56 +02:00
Christoph Lendenfeld added 2 commits 2023-08-03 16:33:07 +02:00
Christoph Lendenfeld added this to the Animation & Rigging project 2023-08-04 11:39:22 +02:00
Christoph Lendenfeld requested review from Nathan Vegdahl 2023-08-04 11:42:04 +02:00
Nathan Vegdahl requested changes 2023-08-04 17:29:41 +02:00
Nathan Vegdahl left a comment
Member

Love this change. Way clearer and simpler this way.

Just one issue with computing the step size of the fcurve evaluation. (Very much the kind of mistake I would make, too!)

Love this change. Way clearer and simpler this way. Just one issue with computing the step size of the fcurve evaluation. (Very much the kind of mistake I would make, too!)
@ -1095,0 +1089,4 @@
const float samples_per_pixel = 0.75f;
const float samples_per_frame = (window_width * samples_per_pixel) / v2d_frame_range;
const float evaluation_step = (bezt->vec[1][0] - prevbezt->vec[1][0]) / samples_per_frame;
Member

I played around with a build, and this computation of the evaluation_step doesn't seem to be right (it gives very inconsistent drawing resolutions, sometimes extremely low, sometimes very high).

I think the issue is that you're effectively double-accounting for the mapping from screen space to fcurve space by using both v2d_frame_range and (bezt->vec[1][0] - prevbezt->vec[1][0]) in the computation. I believe you only need one of them.

If I replace the const float samples_per_frame and const float evaluation_step lines with the following:

const float pixel_width = v2d_frame_range / window_width;
const float evaluation_step = pixel_width / samples_per_pixel;

Then it seems to behave as expected. For example, setting samples_per_pixel to 0.1 then results in a key every ~10 pixels, regardless of zoom.

I played around with a build, and this computation of the `evaluation_step` doesn't seem to be right (it gives very inconsistent drawing resolutions, sometimes extremely low, sometimes very high). I think the issue is that you're effectively double-accounting for the mapping from screen space to fcurve space by using both `v2d_frame_range` and `(bezt->vec[1][0] - prevbezt->vec[1][0])` in the computation. I believe you only need one of them. If I replace the `const float samples_per_frame` and `const float evaluation_step` lines with the following: ```c const float pixel_width = v2d_frame_range / window_width; const float evaluation_step = pixel_width / samples_per_pixel; ``` Then it seems to behave as expected. For example, setting `samples_per_pixel` to `0.1` then results in a key every ~10 pixels, regardless of zoom.
Author
Member

I tested it and your code gives me the exact same evaluation_step
I still changed the code to your suggestion because I think it reads a bit better

I tested it and your code gives me the exact same `evaluation_step` I still changed the code to your suggestion because I think it reads a bit better
Member

Huh, that's odd. Wonder why it behaved differently on my system. Oh well. :-)

Huh, that's odd. Wonder why it behaved differently on my system. Oh well. :-)
nathanvegdahl marked this conversation as resolved
Christoph Lendenfeld added 2 commits 2023-08-10 11:30:47 +02:00
Christoph Lendenfeld requested review from Nathan Vegdahl 2023-08-10 11:30:48 +02:00
Nathan Vegdahl approved these changes 2023-08-10 11:37:22 +02:00
Nathan Vegdahl left a comment
Member

Looks good to me!

Looks good to me!
Christoph Lendenfeld added 1 commit 2023-08-10 12:23:23 +02:00
Christoph Lendenfeld added 1 commit 2023-08-10 12:51:52 +02:00
Christoph Lendenfeld requested review from Nathan Vegdahl 2023-08-10 15:17:01 +02:00
Christoph Lendenfeld added 1 commit 2023-08-10 15:19:32 +02:00
Nathan Vegdahl approved these changes 2023-08-10 15:30:37 +02:00
Nathan Vegdahl left a comment
Member

Looks good to me!

Looks good to me!
Christoph Lendenfeld merged commit 255818a569 into main 2023-08-10 15:33:30 +02:00
Christoph Lendenfeld deleted branch graph_common_curve_drawing 2023-08-10 15:33:31 +02:00
Christoph Lendenfeld removed this from the Animation & Rigging project 2023-11-23 10:55:48 +01:00
Sign in to join this conversation.
No reviewers
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
2 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#110764
No description provided.