Geometry Nodes: Easing Node #109405

Closed
Charlie Jolly wants to merge 7 commits from CharlieJolly/blender:gn-easing-node into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
Member

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.

**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. ![](https://projects.blender.org/attachments/02b300dc-66f8-42d7-b1e1-ebe8eae72d1c) 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.
Iliya Katushenock added this to the Nodes & Physics project 2023-06-27 14:13:18 +02:00
Charlie Jolly added the
Interest
Geometry Nodes
label 2023-06-27 14:40:46 +02:00
Contributor

I think you should add Geometry Nodes module developers as reviewers for them to see. I'm rooting for this node

I think you should add Geometry Nodes module developers as reviewers for them to see. I'm rooting for this node
Charlie Jolly requested review from Hans Goudey 2023-06-29 00:55:40 +02:00
Iliya Katushenock reviewed 2023-06-29 01:11:28 +02:00
@ -1,7 +1,6 @@
# SPDX-FileCopyrightText: 2022-2023 Blender Foundation
#
# SPDX-License-Identifier: GPL-2.0-or-later

unrelated changes

unrelated changes
Author
Member

unrelated changes

Thanks for the cleanup comments.

> unrelated changes Thanks for the cleanup comments.
CharlieJolly marked this conversation as resolved
Iliya Katushenock reviewed 2023-06-29 01:12:07 +02:00
@ -1733,0 +1734,4 @@
/* NodeEasingOperation. */
uint8_t operation;
/* NodeEasingDirection. */
uint8_t direction;
  /* NodeEasingOperation. */
  int8_t operation;
  /* NodeEasingDirection. */
  int8_t direction;
```Cpp /* NodeEasingOperation. */ int8_t operation; /* NodeEasingDirection. */ int8_t direction; ```
CharlieJolly marked this conversation as resolved
Iliya Katushenock reviewed 2023-06-29 01:15:46 +02:00
@ -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

Default value is zero even without explicit declaration
CharlieJolly marked this conversation as resolved
Iliya Katushenock reviewed 2023-06-29 01:19:09 +02:00
@ -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++);
  bNodeSocket *sockSlope = static_cast<bNodeSocket *>(node->inputs.first);
  bNodeSocket *sockScale = sockSlope->next;
  bNodeSocket *sockOffset = sockScale->next;
...
```Cpp bNodeSocket *sockSlope = static_cast<bNodeSocket *>(node->inputs.first); bNodeSocket *sockScale = sockSlope->next; bNodeSocket *sockOffset = sockScale->next; ... ```
Author
Member

While patch is WIP it's easier to keep the existing style here as sockets are not finalised.

While patch is WIP it's easier to keep the existing style here as sockets are not finalised.
mod_moder marked this conversation as resolved
Iliya Katushenock reviewed 2023-06-29 01:19:43 +02:00
@ -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.

All temporal variables can be const.
CharlieJolly marked this conversation as resolved
Iliya Katushenock reviewed 2023-06-29 01:21:03 +02:00
@ -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?

`(out)` -> `out`?
CharlieJolly marked this conversation as resolved
Iliya Katushenock reviewed 2023-06-29 01:23:59 +02:00
@ -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.

Might be better to create new temporal const value and make all function arguments const.
CharlieJolly marked this conversation as resolved
Iliya Katushenock reviewed 2023-06-29 01:26:36 +02:00
@ -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.

Same as above.
CharlieJolly marked this conversation as resolved
Iliya Katushenock reviewed 2023-06-29 01:31:08 +02:00
@ -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).

Shouldn't C-style cast be used. Function style cast for numeric types (https://wiki.blender.org/wiki/Style_Guide/C_Cpp).
CharlieJolly marked this conversation as resolved
Iliya Katushenock reviewed 2023-06-29 01:33:48 +02:00
Iliya Katushenock reviewed 2023-06-29 01:34:14 +02:00
@ -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).

Don't omit creating scope for if statements (https://wiki.blender.org/wiki/Style_Guide/C_Cpp).
CharlieJolly marked this conversation as resolved
Iliya Katushenock reviewed 2023-06-29 01:35:37 +02:00
@ -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.

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.
CharlieJolly marked this conversation as resolved
Iliya Katushenock reviewed 2023-06-29 01:37:07 +02:00
@ -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.

If loop body is just math, `foreach_index_optimized<int>` might better.
Author
Member

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.

`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 of ind[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.

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 of `ind[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.
CharlieJolly marked this conversation as resolved
Iliya Katushenock reviewed 2023-06-29 01:37:48 +02:00
@ -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 of int64_t in geometry nodes code if this possible.

Try to use `int` instead of `int64_t` in geometry nodes code if this possible.
CharlieJolly marked this conversation as resolved
Author
Member

@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.

@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.
Iliya Katushenock reviewed 2023-06-29 01:39:50 +02:00
@ -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.

`switch (NodeEasingOperation(data->operation)) {` Make this for all switch statements.
CharlieJolly marked this conversation as resolved
Iliya Katushenock reviewed 2023-06-29 01:40:32 +02:00
@ -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.

`NodeEasing *data = node_storage(params.node());` See: `NODE_STORAGE_FUNCS`.
CharlieJolly marked this conversation as resolved

@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?

@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?
Author
Member

@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.

> @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.
Charlie Jolly force-pushed gn-easing-node from 8ee5b69bd2 to a5a5e18951 2023-07-17 17:43:12 +02:00 Compare
Charlie Jolly changed title from WIP: D13884 Easing Node to WIP: Geometry Nodes: Easing Node 2023-07-17 18:55:46 +02:00
Author
Member

Note: @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.

Note: @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.
Charlie Jolly force-pushed gn-easing-node from 34d59092a4 to af6f950297 2023-10-02 21:39:18 +02:00 Compare
Charlie Jolly changed title from WIP: Geometry Nodes: Easing Node to Geometry Nodes: Easing Node 2023-10-02 21:39:46 +02:00
Author
Member

image

Merge main and fix up build issues.

![image](/attachments/00ed90f5-b38a-44af-8fe6-821e946a6fe3) Merge main and fix up build issues.
204 KiB
Charlie Jolly added 1 commit 2023-10-02 21:43:16 +02:00
Charlie Jolly added 1 commit 2023-10-03 01:02:41 +02:00
Member

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.

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.
Hans Goudey closed this pull request 2023-10-31 11:04:29 +01:00

Pull request closed

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
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
4 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#109405
No description provided.