WIP: Testing realtime clock branch in combination with simulation nodes #106309

Lukas Tönne wants to merge 195 commits from LukasTonne/blender:geometry-nodes-simulation-realtime-clock into main

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

No response

_No response_
Lukas Tönne added 152 commits 2023-03-30 14:48:28 +02:00
4726803e85 Fixed typo in Simulation Input node
"Delta Time" was set instead of "Elapsed Time" output.
97df619be7 Move "Run" input to simulation output node
It's the output node that decides whether to requiest the values
from the nodes inside the simulation, so it makes more sense
for it to be there. This is part of a general effort to have less
redundancy in the options.
18b2ec1963 Rename "Use Cache" to "Persistent Cache"
This is a temporary option anyway, the caches will be controlled in a
more unified place at the object or scene level. But for now the name
can be a bit better anyway.
7469e19446 Add basic UI support for multiple simulations in a group
Just allows multiple simulation "frames"/regions/contexts to be drawn
in the editor, doesn't include any changes to caching yet.
92a1234830 Add hint to add simulation output node first
Until we can add both nodes at the same time, or we find
an improve simulation to link the two nodes
850aa3d26a Allow multiple caches in the same node group
The caches now hash the identifier of the output node as well.
bb732c240d Half finished refactoring to simulation cache
- Cache is accessed with a string identifier, allowing multiple sockets in the future
- Cache is meant to be stored in a simple array, not sparsely like before
- Persistent cache and temporary "last run" cache are separated more clearly
- Use a "Time Point" class instead of integers, to maybe clarify adding subframe support in the future
- Use a different "sim" namespace (not sure if that will last)
- The value from the last frame is moved, to avoid a copy when no persistent cache is used

I don't think this works now, at least I haven't tested it.
c9958c8e9f Basics of temporary and persistent cache working again
Edge cases not really tested still though
3dcb437d5c Remove elapsed time sockets
Since this is theoretically redundant with simulating a float
with the delta time value, we decided to remove it for now to
make the whole interface simpler.
94e6f87ebc Remove "Persistent Cache" option from the UI
I will keep it internally, but for the simulation MVP we want to focus
on the most basic "last frame's cache" features at first.
49e8218edf Remove Started and Ended booleans
These aren't theoretically necessary, since you can just created them
as regular outputs. Maybe we will eventually add them back for
convenience, but that's not clear.
3fcf50d37a Make the simulation always run, remove run socket
Note: Still unstable. Simulation resets when playback stops bug.

Since the "Run" behavior can basically be implemented with the switch
node already, it's just adding unnecessary complexity to the interface
now, when it's use case isn't clear. We decided to remove it for now,
and only consider it later as a possible convenience feature, rather
than an essential part of the design.

Also, the simulation nodes are now considered "side effect nodes"
for the evaluator, meaning they are *always* evaluated, even if they
aren't needed because of switch nodes, etc. This was the best way
we thought of to make simulations run consistently even through
situations like that.
620b190e52 Fix delta time output
Output time in seconds rather than frame units
1965e31d17 Fix T101130: Scaling of NLA Strip Via S Hotkey Not Working
After switching over to using start_frame / end_frame, scaling an NLA strip didn't scale the strip, it just repeated the action.

Now withing the NLA transform code, we look for TFM_TIME_EXTEND / TFM_TIME_SCALE transform mode, and handle the update to strip scale accordingly
c30718ded9 cmake/win: Allow running blender_test from the VS debugger
This was missing some paths setup in the environment, ctest
normally sets this up before running the tests from the CLI
but that does not help the IDE all that much.
496e344015 Cleanup: Move mesh modifier apply function to editors module
The function was highly related to the apply modifier operator,
and only used once. This was too specific to be in the blenkernel,
especially in a mesh conversion file.
e50d567c97 Cleanup: Various improvements to modifier apply operator
Use C++ casts, decrease variable scope, use references, use const.
6b26b0db21 Fix build issue with NanoVDB and HIP on Linux
This patch was already accepted upstream, so this is temporary until we update
to a new OpenVDB release that includes it.
f9b621a9d9 Nodes: Allow skipping node attachment after dragging
This patch allows skipping the automatic insertion of nodes on top of
links when the transform operator ends. When putting nodes into small
spaces this often gets in the way and wastes time. Now, when holding
`alt`, this is turned off.

The header text is also improved to add this shortcut and to remove
the Dx and Dy values and improve the formatting a bit.

Making this functionality optional might allow us to use it in more
places in the future, like for the nodes added by link-drag-search.

Differential Revision: https://developer.blender.org/D16230
20cab8f8f2 Geometry Nodes: Add error message when applying modifier with no mesh
If the resulting geometry from applying a geometry nodes modifier
contains no mesh, give an error message. This gives people something to
search and makes the behavior more purposeful.

Also remove the `modifyMesh` implementation from the geometry nodes
modifier, since it isn't necessary anymore. And remove the existing
"Modifier returned error, skipping apply" message which was cryptic
and redundant if applying returns an actual error message.

Resolves T103229

Differential Revision: https://developer.blender.org/D16782
24523726d7 Mesh: Store active & default color attributes with strings
Attributes are unifying around a name-based API, and we would like to
be able to move away from CustomData in the future. This patch moves
the identification of active and fallback (render) color attributes
to strings on the mesh from flags on CustomDataLayer. This also
removes some ugliness used to retrieve these attributes and maintain
the active status.

The design is described more here: T98366

The patch keeps forward compatibility working until 4.0 with
the same method as the mesh struct of array refactors (T95965).

The strings are allowed to not correspond to an attribute, to allow
setting the active/default attribute independently of actually filling
its data. When applying a modifier, if the strings don't match an
attribute, they will be removed.

The realize instances / join node and join operator take the names from
the first / active input mesh. While other heuristics may be helpful
(and could be a future improvement), just using the first is simple
and predictable.

Differential Revision: https://developer.blender.org/D15169
ac59dfeffd Fix T103049: Cycles specular light leak regression
The logic here is not ideal but was unintentionally changed in refactoring
for path guiding, now restore it back to 3.3 behavior again.
a3a132ea74 Build: upgrade pre-built libraries for Linux
Replace ../lib/linux_centos7_x86_64 with ../lib/linux_x86_64_glibc_228,
built with Rocky8 Linux, compatible with the VFX platform CY2023,
see: T99618.

- Update build-bot configuration.
- Remove unnecessary check for Blosc, this is part of OpenVDB lib now.
- Remove WITH_CXX11_ABI, always use new C++11 ABI now
- Replace centos7 by glibc_228 everywhere

Note that existing builds with cached paths pointing to
"../lib/linux_centos7_x86_64" will need to be updated.

Includes contributions by Brecht.
34f307547b Fix T103183: UV map name of mesh converted from curve is untranslated
Upon conversion, the newly-created UV map with default name "UVMap"
should be translated.

Reviewed By: mont29

Maniphest Tasks: T103183

Differential Revision: https://developer.blender.org/D16775
af7c34716b Fix active/default color names not being editable
Revert [0] and enable the editable flag as the intent for [1] was that
these values would be editable.

[0]: e58f5422c3
[1]: 6514bb05ea
0403d77a0f Fix T103237: Prevent UV Unwrap from packing hidden UV islands
When migrating to the new packing API, pin_unselected was not
implemented correctly.

Regression from rB143e74c0b8eb, rBe3075f3cf7ce, rB0ce18561bc82.

Differential Revision: https://developer.blender.org/D16788

Reviewed By: Campbell Barton

Duplicated in blender-v3.4-release as rB3dcd9992676a
a12614d166 Fix T102923: replace zero check with epsilons with uv constrain to bounds
Small roundoff errors during UV editing can sometimes occur, most likely
due to so-called "catastrophic cancellation".

Here we set a tolerance around zero when using Constrain-To-Bounds and UV Scaling.

The tolerance is set at one quarter of a texel, on a 65536 x 65536 texture.

TODO: If this fix holds, we should formalize the tolerance into the UV editing
subsystem, perhaps as a helper function, and investigate where else it needs
to be applied.

Differential Revision: https://developer.blender.org/D16702
c9bd78890a Build: remove opus workaround for sndfile
For some reason SNDFILE now builds without this workaround,
which broke building FFMPEG.
bb8cbf0c10 UI: don't change mouse cursor while it's grabbed
The paint cursor was continuously set which meant hiding the cursor
while interacting with buttons would immediately show it again.

This exposed cursor warping.
5d1ed47d6c Fix T103253: Infinite drag of number buttons is broken on WIN32
Recent reverting of changes to cursor grabbing intended to match
Blender 3.3 release. This is the case for 3.4x branch, however there is
an additional change to grabbing on WIN32 by Germano [0] which is a
significant improvement on old grabbing logic for Windows.
So instead of matching 3.3x behavior, restore logic that keeps
the cursor centered while grabbing & hidden.

This re-introduces T102792 issue displaying the paint-brush while
dragging buttons, this will have to be solved separately.

Re-apply [1] & [2], revert [3] & [4].

[4]: a3a9459050
[0]: 9fd6dae793
[1]: 4cac8025f0
[2]: 230744d6fd
[3]: 0240b89599
54942e5ea6 Fix T102792: Sculpt cursor jumps to random place
Restrict the condition under which paint cursors read use the cursor
location from the the operating-system.

This caused a glitch when dragging UI elements in painting context
popup. Since the paint cursor would display using mouse motion
which was clamped to the window center - an internal detail of hidden
cursor grabbing.

Now only read the cursor coordinates when clamped to a region which
is used for the transform cursor to stay visible even when the cursor
wraps around.
32a7384c0b Geometry Nodes: improve dot graph export of lazy function graph
* Dim default input values.
* Print default input values instead of type name.
* Add node/socket names to group input/output nodes.
74171ff3b0 CMake: warn Linux references old linux_centos7_x86_64 paths
When the centos7 library dir is found, warn when the values of cached
variables reference it, listing the variables and their values.
06525747c0 Build: resolve failure to copy indirect dependencies for USD on Linux
Even when building without OpenImageIO and OpenVDB, USD depends on these

Ensure these libraries are copied when building with USD.
cfb77c54b0 Fix T103257: Enabling or disabling viewport denoising while using OptiX OSL results in an error
Switching viewport denoising causes kernels to be reloaded with a new
feature mask, which would destroy the existing OptiX pipelines. But OSL
kernels were not reloaded as well, leaving the shading pipeline
uninitialized and therefore causing an error when it is later attempted to
execute it. This fixes that by ensuring OSL kernels are always reloaded
when the normal kernels are too.
6bd6d7aec7 Fix T103258: Deleting a shader with OptiX OSL results in an illegal address error
Materials without connections to the output node would crash with OSL
in OptiX, since the Cycles `OSLCompiler` generates an empty shader
group reference for them, which resulted in the OptiX device
implementation setting an empty SBT entry for the corresponding direct
callables, which then crashed when calling those direct callables was
attempted in `osl_eval_nodes`. This fixes that by setting the SBT entries
for empty shader groups to a dummy direct callable that does nothing.
f92a85d7d2 Nodes: Add Exclusion color mix mode
Expands Color Mix nodes with new Exclusion mode.

Similar to Difference but produces less contrast.

Requested by Pierre Schiller @3D_director and
@OmarSquircleArt on twitter.

Differential Revision: https://developer.blender.org/D16543
807be888a5 Fix: Crash after mesh color attribute name commit
6514bb05ea missed a null check when accessing the active
and default color attribute names, since the CustomData API does not
do that check itself.
8226abc111 Cleanup: Remove duplicate UV islands header
This code was duplicated from `pbvh_uv_islands.hh`,
which was the version that was actually used.
a0ed3601c9 Fix T103187: Opening node search menu is slow because of assets.
Avoid utility function call that would query the file system, this was a
bottleneck. The path joining was also problematic. See patch for more

Differential Revision: https://developer.blender.org/D16768

Reviewed by: Jacques Lucke
988241e23e Geometry Nodes: simplify handling of invalid group interface sockets
Previously, the code tried to keep node groups working even if some of
their input/output sockets had undefined type. This caused some
complexity with no benefit because not all places outside of this file
would handle the case correctly. Now node groups with undefined
interface sockets are disabled and have to be fixed manually before
they work again.

Undefined interface sockets are mostly caused by invalid Python
API usage and incomplete forward compatibility (e.g. when newer
versions introduce new socket types that the older version does
not know).
aeea690e00 Cleanup: Remove unnecessary node link flag
Links that are currently being dragged are now stored outside
of the node tree, so we don't need a flag to distinguish them
from "proper" links.
38567bc023 Cleanup: Slightly refactor cancelling link drag operator
Clarify that the dragged links aren't stored in the tree, use a
separate function for cancelling vs. applying the links to the tree.
508fd044b4 Revert "Fix simulation"
This reverts commit 468f43c7a6.

Revert "Add initial dynamic declarations"

This reverts commit 50a2c77c4e.

Revert "Add initial simulation state items array to output node"

This reverts commit 3f1027567d.
buildbot/vexp-code-experimental-coordinator Build done. Details
Fixes after merge
buildbot/vexp-code-patch-coordinator Build done. Details
Merge branch 'main' into geometry-nodes-simulation
buildbot/vexp-code-patch-coordinator Build done. Details
Merge branch 'main' into geometry-nodes-simulation
f36dd06609 Add initial infrastructure for multiple simulation state items
- Use dynamic declarations to build simulation node sockets
- Fixes in some node code for futher use of dynamic declarations
- Copying, freeing, reading, and writing of simulation state array
- Add simulation state items with link drag operator

The new sockets won't do anything yet, only geometry sockets are
supported, and there is no way to remove sockets yet.
3bad7a51cb Implement simulation nodes as lazy functions directly
Support for multiple sockets will be slightly more complete now too,
but that part hasn't been tested.
b77436b534 Added realtime clock struct in the animtimer customdata.
Multiple clocks can run at the same time, using the same animtimer.
The `active_clock` flags show which clocks are running. If any clock
is running (`active_clock != 0`) the `animtimer` must also exist.
8ca3840b4f Replaced checks for `animtimer` that are used to check if anim playback is running.
Since the timer is now shared, the existence of the pointer alone is not enough
to determine if animation playback is running. The screen flag (or better:
the ED_screen_animation_is_playing function) should be used for such checks.
53582157f4 Store both animation and realtime clock data in the animtimer customdata.
Running clocks are identified by the `active_clock` flags now,
the `animtimer` pointer is not sufficient any longer to determine if
animation playback is running.
2c4e71f4ef Use the same operator for both clocks.
If separate operators are used they will have to return pass-through and,
more importantly, we won't be easily able to ensure a single depsgraph
74b50cf429 Fix memory leak: operators were running as modal when they shouldn't.
The bool return value of the ED_ functions got converted to 1, which
is the operator return value for modal operators.
070ac1898a Added a `BKE_scene_graph_update_for_timestep` function to handle different clocks.
The original `BKE_scene_graph_update_for_newframe` function sets the scene frame
and only tags the scene time source. The new function supports all clock types
while still ensuring only one actual depsgraph evaluation.

It would be nicer if this could be split such that the update passes are more
agnostic towards the specific clock types. The current update pass loop is
quite complicated and handles a lot of corner cases.
b14668ae03 Simulation Nodes: refactor automatic caching
The most important part of this change is that the simulation
state at a specific point in time is more self contained now.
This way, only the modifier has to deal with finding the old/new
simulation states and not every simulation individually.

Furthermore, this also includes some simple cache invalidation
when the user changes something that might affect the result.
4f46024e0b Added a persisten clock value to Scene DNA.
This is necessary to have a reliable persistent frame value from which
simulations can compute a "delta time". The `realtime_clock.frame` value
in `Scene` is currently never reset, this should be supported eventually.
06227194bb Store the depsgraph update frame and ctime in time source nodes.
Multiple clocks exist now to give a "current time" value for computing
time steps and for checking if a simulation needs to be reset.
9cda17ef65 Fix for uninitialized memory use when the cache is cleared.
The `prev_simulation_state` is looked up before and needs to stay valid.
To make this work the cache now is pruned up to the last state, rather
than cleared entirely. It will contain at most 2 states at any time.
e80440a95b Fix broken realtime clock while animation is running.
The `active_clock` flags need to be checked using bitwise operators,
not a switch statement, since both clocks can be running at the same time.
5a179ae1bc Operator for resetting the realtime clock to zero.
The value 0.0 counts a special "start frame" which causes the
simulation cache to be invalidated.
19027eb676 Added own notifier for the realtime clock to ensure depsgraph time is correct.
The depsgraph time source node for the realtime clock needs to be updated to
the current clock time before evaluation. This currently happens after operators
through the `ND_FRAME` notifier for the scene frame. The realtime clock needs its
own notfier so that operators can ensure the clock value is correct.

Without this update the simulation nodes see an old clock value and don't find a
"previous state" until the simulation is past that frame again. It will never
insert a new frame until that point and delta time will remain 0.0.
d95a33d6ac More reliable cache invalidation on reset.
This is not a great solution yet, it relies on an explicit depsgraph update
to ensure that the modifier eval sees a frame 0.0 value.
db7597f00a Better solution to invalidating all caches.
Instead of relying on the depsgraph update and a "frame == 0" test,
the operator now explicitly invalidates all caches. This requires
looping over the scene, but as a one-off user operation that is

This reverts commit d95a33d6ac.
buildbot/vexp-code-patch-coordinator Build done. Details
Disable cache invalidation on manual modifier changes.
This may be ok for scene playback, but it means the simulation is reset
entirely whenever any dependency is changed, for example moving an object
whose transform is used with an Object Info node.

@blender-bot build

@blender-bot build
Lukas Tönne added this to the Nodes & Physics project 2023-04-20 10:53:33 +02:00
Lukas Tönne force-pushed geometry-nodes-simulation-realtime-clock from ca669472f1 to 8cb5c172a3 2023-04-25 12:03:41 +02:00 Compare
This pull request has changes conflicting with the target branch.
  • release/datafiles/userdef/userdef_default_theme.c
  • scripts/startup/bl_operators/geometry_nodes.py
  • scripts/startup/bl_operators/node.py
  • scripts/startup/bl_ui/node_add_menu.py
  • scripts/startup/bl_ui/space_node.py
  • scripts/startup/bl_ui/space_view3d.py
  • source/blender/blenkernel/BKE_modifier.h
  • source/blender/blenkernel/BKE_node_runtime.hh
  • source/blender/blenkernel/BKE_node_tree_zones.hh
  • source/blender/blenkernel/CMakeLists.txt
Sign in to join this conversation.
No reviewers
No Label
Animation & Rigging
Asset Browser
Asset Browser Project Overview
Automated Testing
Blender Asset Bundle
Dependency Graph
Development Management
EEVEE & Viewport
Geometry Nodes
Grease Pencil
ID Management
Images & Movies
Import Export
Line Art
Motion Tracking
Nodes & Physics
Pipeline, Assets & IO
Platforms, Builds & Tests
Python API
Render & Cycles
Render Pipeline
Sculpt, Paint & Texture
Text Editor
User Interface
UV Editing
VFX & Video
Video Sequencer
Virtual Reality
Interest: Wayland
Blender 2.8 Project
Milestone 1: Basic, Local Asset Browser
OpenGL Error
Good First Issue
Animation & Rigging
Development Management
EEVEE & Viewport
Grease Pencil
Nodes & Physics
Pipeline, Assets & IO
Platforms, Builds & Tests
Python API
Render & Cycles
Sculpt, Paint & Texture
User Interface
VFX & Video
Unbreak Now!
Needs Info from Developers
Needs Information from User
Needs Triage
Known Issue
To Do
No Milestone
No Assignees
1 Participants
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.


No dependencies set.

Reference: blender/blender#106309
There is no content yet.