Skip to content

RotateOverTimeModifier - #552

Open
hukasu wants to merge 3 commits into
djeedai:mainfrom
hukasu:rotate-over-time
Open

RotateOverTimeModifier#552
hukasu wants to merge 3 commits into
djeedai:mainfrom
hukasu:rotate-over-time

Conversation

@hukasu

@hukasu hukasu commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Very naive implementation of RotateOverTimeModifier

@djeedai djeedai left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm skeptical about this change. See individual comments. As is I'm not convinced.

Comment thread src/modifier/rotate_over_time.rs Outdated
pub struct RotateOverTimeModifier {
/// Rotation that the particle will have in a second.
///
/// Expr type: Mat4

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want that Mat4 field, users are already struggling with vector operations and complaining there's too many missing helpers, so for matrices where we have almost nothing, basically nobody will use this modifier. Not your fault, but basically I don't want to try encouraging users to use Mat4 and drive them into a corner where there's no utilities to manipulate matrices; that will just lead to more opened issues and frustration.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced it for a Vec3 with euler angles, also have the advantage of being able to represent rotations of over 360 degrees

Comment thread src/modifier/rotate_over_time.rs Outdated
context.main_code += &format!(
r#" {{
let rotation = {rotation};
particle.{0} = normalize(mix(particle.{0}, (vec4(particle.{0}, 1) * rotation).xyz, {dt}));

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me RotateOverTimeModifier (and this is confirmed by its doc comment) means that the particle will continuously rotate. This is not the case; this modifier interpolates the rotation of the particle from its current rotation to a target one, then does nothing after that.

The other major issue is that calling mix(a, b, dt) only works nicely if dt < 1, otherwise the interpolation will overshoot. This is because we're mixing units; dt is in seconds here, whereas the mix(.., .., r) ratio is a unitless quantity in 0..=1. If you really intend to create an interpolator modifier, it should take a duration parameter that determines how long it should take to go from current to target rotation, and then calculate the unitless mix(.., .., r) ratio such that it takes that much time relative to dt.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The matrix indicates the rotation that the particle will do every 1 second, dt will always be way below 1 second unless there is immense lag going on, so the rotation will accumulate over the lifetime of the particle

Comment thread Cargo.toml
name = "lightning"

[[example]]
name = "rotate_over_time"

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general please avoid adding examples unless there's a non-obvious new feature or there's really no other example this could fit in. The reason is that the maintenance cost of examples is quite high; not only are examples used as behavior benchmark to validate behavior for all major changes (need to run them all one by one for visual check), they also require extra work in wasm (add new webpage, extra compile time, etc.). Ideally all of that should be automated or covered by unit/feature tests, but until then it's quite the burden. Thanks!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which example would it be ok to include this modifier then? if any?

@hukasu
hukasu marked this pull request as draft July 25, 2026 19:42
@hukasu
hukasu marked this pull request as ready for review July 25, 2026 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants