Fix #107956: Simulation reset on fps change #108004

Merged
YimingWu merged 5 commits from ChengduLittleA/blender:fix-107956 into main 2023-05-31 10:06:05 +02:00
Member

Resets simulation cache when frame rate changes, so we don't get
inconsistent accumulations when frame rate is changed in the middle of
the simulation.

Resets simulation cache when frame rate changes, so we don't get inconsistent accumulations when frame rate is changed in the middle of the simulation.
YimingWu requested review from Jacques Lucke 2023-05-17 10:57:02 +02:00
YimingWu added the
Module
Nodes & Physics
Interest
Geometry Nodes
labels 2023-05-17 10:57:14 +02:00
YimingWu added this to the Nodes & Physics project 2023-05-17 10:57:24 +02:00
YimingWu changed title from Fix #107956: Simulation reset on fps change. to Fix #107956: Simulation reset on fps change 2023-05-17 10:59:07 +02:00

Does it make sense to make the cache update part of the scene frame rate update callback?

Does it make sense to make the cache update part of the scene frame rate update callback?
Author
Member

Humm... That case we need to iterate every single object's modifier to clear the cache. It makes sense but I kinda prefer an on-demand kind of approach so if you change the value back it doesn't affect anything else that's not being evaluated.

Humm... That case we need to iterate every single object's modifier to clear the cache. It makes sense but I kinda prefer an on-demand kind of approach so if you change the value back it doesn't affect anything else that's not being evaluated.
Jacques Lucke requested changes 2023-05-23 18:43:34 +02:00
@ -162,6 +162,8 @@ class ModifierSimulationCache {
CacheState cache_state_ = CacheState::Valid;
bool failed_finding_bake_ = false;
float delta_seconds_ = 0.0f;
Member

That does not seem quite right, not sure why delta_seconds_ should be stored. It kind of conflicts with the future possibility to have adaptive subframes. Would likely be better to just store the fps here. Even better might to somehow hook the reset up to rna_Scene_fps_update but that can also be done later.

That does not seem quite right, not sure why `delta_seconds_` should be stored. It kind of conflicts with the future possibility to have adaptive subframes. Would likely be better to just store the fps here. Even better might to somehow hook the reset up to `rna_Scene_fps_update` but that can also be done later.
ChengduLittleA marked this conversation as resolved
YimingWu force-pushed fix-107956 from 673a9f8a42 to a702b908ea 2023-05-24 05:00:38 +02:00 Compare
Jacques Lucke requested changes 2023-05-24 08:39:53 +02:00
@ -1187,16 +1201,12 @@ static void prepare_simulation_states_for_evaluation(const NodesModifierData &nm
}
}
else if (sim_states.prev != nullptr && sim_states.next == nullptr) {
const float max_delta_frames = 1.0f;
Member

Is there any reason to move all this code?
Just put the fps check into the /* Reset cached data if necessary. */ section above.

Is there any reason to move all this code? Just put the fps check into the `/* Reset cached data if necessary. */` section above.
ChengduLittleA marked this conversation as resolved
@ -1177,0 +1183,4 @@
const float delta_frames = std::min(max_delta_frames, scene_delta_frames);
const float delta_seconds = delta_frames / FPS;
const float old_fps = nmd_orig.simulation_cache->last_fps_;
if (old_fps && (!compare_ff(FPS, old_fps, 1e-8))) {
Member

using 1e-8 when comparing floats is probably not very useful, because that's lower than the precision. An exact check would probably work here, but can also just use 1e-6 instead.

using `1e-8` when comparing floats is probably not very useful, because that's lower than the precision. An exact check would probably work here, but can also just use `1e-6` instead.
ChengduLittleA marked this conversation as resolved
YimingWu force-pushed fix-107956 from 48be8f32a0 to 7c3e83461e 2023-05-25 04:00:48 +02:00 Compare
YimingWu force-pushed fix-107956 from 7c3e83461e to 0cb730039c 2023-05-25 04:02:28 +02:00 Compare
YimingWu force-pushed fix-107956 from 0cb730039c to 529a240038 2023-05-25 04:07:41 +02:00 Compare
Jacques Lucke requested changes 2023-05-25 10:57:13 +02:00
Jacques Lucke left a comment
Member

Sorry for the unnecessarily long back and forth. Just noticed that we should probably just invalidate the cache when the fps changes. The reset then happens automatically when going back to frame one.

Also, why are you always force-pushing to your branch? It would make checking your changes easier if you would just make normal commits. You don't have to rebase your branch all the time.

Sorry for the unnecessarily long back and forth. Just noticed that we should probably just invalidate the cache when the fps changes. The reset then happens automatically when going back to frame one. Also, why are you always force-pushing to your branch? It would make checking your changes easier if you would just make normal commits. You don't have to rebase your branch all the time.
Author
Member

Hi @JacquesLucke , I rebase the branch so I compile faster because when switching from and to main there will be fewer file changes.

I'll figure out a way to make it into frame rate callback. :D

Hi @JacquesLucke , I rebase the branch so I compile faster because when switching from and to main there will be fewer file changes. I'll figure out a way to make it into frame rate callback. :D
YimingWu force-pushed fix-107956 from 529a240038 to 0510ab8960 2023-05-30 15:18:26 +02:00 Compare
Jacques Lucke approved these changes 2023-05-31 09:55:01 +02:00
@ -184,0 +194,4 @@
continue;
}
NodesModifierData *nmd = (NodesModifierData *)md;
NodesModifierData *nmd_orig = reinterpret_cast<NodesModifierData *>(
Member

Please try it, but I'd assume that you can work on nmd directly instead of using nmd_orig.

Please try it, but I'd assume that you can work on `nmd` directly instead of using `nmd_orig`.
@ -922,6 +923,11 @@ static void rna_Scene_camera_update(Main *bmain, Scene *UNUSED(scene_unused), Po
DEG_relations_tag_update(bmain);
}
static void simulation_reset_cache(Scene *scene)
Member

No need for this extra indirection, just call BKE_simulation_reset_scene directly below.

No need for this extra indirection, just call `BKE_simulation_reset_scene` directly below.
ChengduLittleA marked this conversation as resolved
YimingWu added 1 commit 2023-05-31 10:04:44 +02:00
YimingWu merged commit 397663a7cb into main 2023-05-31 10:06:05 +02:00
YimingWu deleted branch fix-107956 2023-05-31 10:06:06 +02: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 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#108004
No description provided.