WIP: Geometry Nodes: Easing Node #109405
No reviewers
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
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
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
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
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
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
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
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
4 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#109405
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "CharlieJolly/blender:gn-easing-node"
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?
Reopened to keep local branch in sync.
Please note that this patch has previously been closed and rejected.
#109405 (comment)
Geometry Nodes: Add Easing Function Node
This node provides GN users with a high level node incorporating classic easing functions from Penner and new easing functions from Godot and CSS sources. The node is expected to be used for motion graphics and animation but is also useful to control interpolation by plugging into a Factor socket. Each function is designed to operate on an input in the [0,1] range. The output is not clamped.
Mentioned by Cartesian Caramel as an ease of use feature.
https://www.youtube.com/watch?v=UzocW9RtOOQ&t=855s
Penner: Back, Bounce, Circ, Cubic, Elastic, Expo, Quad, Quart, Quint, Sine
CSS: Steps, Cubic Bezier, Linear
Godot: Spring
Other: Periodic functions inc Sawtooth, Square and Sine, Bias/Gain curve, Variable (power curve with exponent mapped to [0-1] range), Snake (same as Bounce but with flipped neg/pos bounces)
These easing functions are customisable with additional controls where applicable:
Inflection - rather than Ease In, Ease Out options, the Inflection point determines where the In-Out/Out-In transition occurs. At 0.5, this provides a classic EaseInOut or EaseOutIn effect.
Invert - switches easing direction from In-Out to Out-In.
Mirror - mirrors the input, to create reverses, spikes and pulses.
Count - controls the amount of Bounces or Flips for Bounce and Snake functions.
Frequency - controls frequency for Elastic, Steps and Periodic functions.
Jump Start/End - controls if the step function should include or exclude the first and end steps.
Based on my original patch D13884.
https://archive.blender.org/developer/D13884
Cubic Bezier demo
https://cubic-bezier.com/#.17,.67,.83,.67
Classic Penner easings plus more.
https://twitter.com/TimKrief/status/1672163107383197696?s=20
CSS Easing Functions
https://developer.mozilla.org/en-US/docs/Web/CSS/easing-function
Credits:
Bounce/Snake with configurable bounces adapted from Animation Nodes. Copyright 2017 Jacques Lucke.
Robert Penner functions, BSD-3-Clause Copyright 2001 Robert Penner. All rights reserved.
Cubic Bezier uses UnitBezier class, ported from webkit. Copyright 2008 Apple Inc. All rights reserved.
I think you should add Geometry Nodes module developers as reviewers for them to see. I'm rooting for this node
@ -1,7 +1,6 @@
# SPDX-FileCopyrightText: 2022-2023 Blender Foundation
#
# SPDX-License-Identifier: GPL-2.0-or-later
unrelated changes
Thanks for the cleanup comments.
@ -1733,0 +1734,4 @@
/* NodeEasingOperation. */
uint8_t operation;
/* NodeEasingDirection. */
uint8_t direction;
@ -0,0 +23,4 @@
.subtype(PROP_FACTOR)
.make_available([](bNode &node) { node_storage(node).operation = NODE_EASING_SLOPE; });
b.add_input<decl::Float>(N_("Scale"))
.default_value(0.0f)
Default value is zero even without explicit declaration
@ -0,0 +125,4 @@
sock++;
bNodeSocket *sockSlope = (bNodeSocket *)BLI_findlink(&node->inputs, sock++);
bNodeSocket *sockScale = (bNodeSocket *)BLI_findlink(&node->inputs, sock++);
bNodeSocket *sockOffset = (bNodeSocket *)BLI_findlink(&node->inputs, sock++);
While patch is WIP it's easier to keep the existing style here as sockets are not finalised.
@ -0,0 +140,4 @@
bNodeSocket *sockEaseOut = (bNodeSocket *)BLI_findlink(&node->inputs, sock++);
bNodeSocket *sockEaseInAndOut = (bNodeSocket *)BLI_findlink(&node->inputs, sock++);
bool use_slope = ELEM(operation, NODE_EASING_SLOPE, NODE_EASING_BIAS, NODE_EASING_GAIN);
All temporal variables can be const.
@ -0,0 +193,4 @@
static int set_direction(const bool out, const bool inout)
{
if (inout) {
return (out) ? NODE_EASING_DIRECTION_OUT_IN : NODE_EASING_DIRECTION_IN_OUT;
(out)
->out
?@ -0,0 +218,4 @@
return 1.0f - p;
}
m = 1.0f - m;
Might be better to create new temporal const value and make all function arguments const.
@ -0,0 +228,4 @@
return min2 + (value - min1) * (max2 - min2) / (max1 - min1);
}
static float pre_map_input(const int direction, float x)
Same as above.
@ -0,0 +433,4 @@
static float easing_sine_out(float x)
{
return sinf(x * (float)M_PI_2);
Shouldn't C-style cast be used. Function style cast for numeric types (https://wiki.blender.org/wiki/Style_Guide/C_Cpp).
@ -0,0 +570,4 @@
return x;
}
if (x < 0.5)
return easing_bias(x * 2.0f, t) / 2.0f;
Don't omit creating scope for if statements (https://wiki.blender.org/wiki/Style_Guide/C_Cpp).
@ -0,0 +585,4 @@
float xt = x / t;
return (x * t / x) * (1 - (sqrt(1 - xt * xt)));
}
float xm = 1 - x;
Try to make all numeric temporal variables and function arguments constants. It's very easy when you don't need to follow the state of the variable throughout the body of the code.
@ -0,0 +713,4 @@
const VArray<float> &mirror = params.readonly_single_input<float>(param++, "Mirror");
MutableSpan<float> results = params.uninitialized_single_output<float>(param++, "Result");
mask.foreach_index([&](const int64_t i) {
If loop body is just math,
foreach_index_optimized<int>
might better.foreach_index_optimized
- ,The docs say, Only use this when very little processing is done for each index.Not clear how much code is too much.
This generate a loop body for different segments types. Usually, all segments is a span of indices in random memory. But potentially, all indices can be a unique sequence of range without hole (size == last - first). In this case, we can avoid lookup of all indices in a span, by iterating over index range (
i++
instead ofind[i++]
).Unless you're doing a bunch of nested loops, recursions, or 10+ samples of random indexes on other arrays randomly dumped into memory, then your CPU cache can be very well optimized. Because you don't need to sample the mask either.
In this case, everything you do is just math. There are one or two reding, but this should not be critical.
@ -0,0 +751,4 @@
const VArray<float> &mirror = params.readonly_single_input<float>(param++, "Mirror");
MutableSpan<float> results = params.uninitialized_single_output<float>(param++, "Result");
mask.foreach_index([&](const int64_t i) {
Try to use
int
instead ofint64_t
in geometry nodes code if this possible.@mod_moder it's quite an old patch so it does need a good clean-up. Btw, I'm getting an email for each comment. When Hans commented on the interpolation patch they all came through on a single email. Are there different ways to review code? I'm only just getting used to the new system.
@ -0,0 +1446,4 @@
const bNode &node = builder.node();
NodeEasing *data = (NodeEasing *)node.storage;
switch (data->operation) {
switch (NodeEasingOperation(data->operation)) {
Make this for all switch statements.
@ -0,0 +1444,4 @@
static void node_easing_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder)
{
const bNode &node = builder.node();
NodeEasing *data = (NodeEasing *)node.storage;
NodeEasing *data = node_storage(params.node());
See:
NODE_STORAGE_FUNCS
.@CharlieJolly I'm also not entirely sure about this, but it seems that if I'm not reviewing, I can't do it all at once... Yeah, thinking about it now, I'm very good at spamming.. sorry.
As a result, scrolling through the code, I see:
This seems like a lot of code bloat with logic that can be added as assets.
We can partially reduce the bloat by adding groups of multifunctions (to create clamp nodes instead added this to any math multi functions...) (Besides, it's just a concept, far from reality), but as something that will also potentially have to get into shaders in the future, it looks scary.
I think it's really worth trying to increase the use of functions from
BLI_math_....hh
.And also, I see sooo many magic numbers.
Also, is double precision really necessary?
These aren't new functions. This was originally using the Penner based
BLI_easing.h
lib in Blender but that is pretty archaic and is a source of many of the issues you pointed out. I simplified the functions and made them work on a [0-1] domain, removing the time, change and duration options. Removing multiple versions of the same function for ease in, ease out etc. The magic numbers are pretty well established for the Penner functions. I didn't have the intention of porting this to Shader nodes as the focus here is providing a high level node for motion graphics, my argument here is that assets don't provide the interactivity that comes from being able to easily switch options and experiment. I didn't see this node fitting Shader nodes.I'll go through your comments and update the patch, thanks.
8ee5b69bd2
toa5a5e18951
WIP: D13884 Easing Nodeto WIP: Geometry Nodes: Easing NodeNote: @mod_moder made some code review comments. These seem to have been lost as I squashed the changes and uploaded as a single commit. I made most of the changes that were suggested.
34d59092a4
toaf6f950297
WIP: Geometry Nodes: Easing Nodeto Geometry Nodes: Easing NodeMerge main and fix up build issues.
Based on the discussion in https://devtalk.blender.org/t/2023-08-01-nodes-physics-module-meeting/30528, I will close this PR. The menu switch would allow implementing this as a node group asset. Though possibly the different modes should just be different nodes as well.
Reopen so I can keep my local branch in sync. Changed title to WIP.
Geometry Nodes: Easing Nodeto WIP: Geometry Nodes: Easing NodeCheckout
From your project repository, check out a new branch and test the changes.