Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CPUParticles2D - Add ability to follow physics interpolated target #101911

Merged
merged 1 commit into from
Jan 24, 2025

Conversation

rburing
Copy link
Member

@rburing rburing commented Jan 22, 2025

Allows a non-interpolated particle system to closely follow an interpolated target without tracking ahead of the target, by performing fixed timestep interpolation on the particle system global transform, and using this for emission.

Ports relevant parts from 3e19cf8 and 723632a and a117a33 by @lawnjelly

Test project from #92006 (comment): particles_2d_example.zip (CPU particles are red).

@lawnjelly Is removing the old NOTIFICATION_TRANSFORM_CHANGED really correct?

@lawnjelly
Copy link
Member

lawnjelly commented Jan 22, 2025

@lawnjelly Is removing the old NOTIFICATION_TRANSFORM_CHANGED really correct?

From memory, it could well be, as the particle transforms should now be in true global space and therefore have to be recalculated each frame anyway from the global_transform.

The old particles were in some hacked global space by applying the inverse of the node transform both client and GPU side, for no sensible reason (as far as I can see, it was probably to avoid doing the changes to properly support global space, which we have since done). That hacked global space made interpolation nigh on impossible, hence the reason for introducing true global space capability for canvas items.

This may be depending on the changes to support set_canvas_item_use_identity_transform().

@lawnjelly
Copy link
Member

Seems to work great, I tested:

  • physics interpolation on, global mode
  • physics interpolation on, local mode
  • physics interpolation off, global mode
  • physics interpolation off, local mode

I've also tested children of the CPUParticles and their transform appears to be correct too.

It is a while since I wrote this though (year and a bit) so it's not super fresh in mind, so the more testing it can get (particularly in real projects, which I don't have for 4.x) the better. Probably a good idea to try in all the relevant 2D demo projects.

// This is used to avoid passing the camera transform down the rendering
// function calls, as it won't be used in 99% of cases, because the camera
// transform is normally concatenated with the item global transform.
_current_camera_transform = p_transform;
Copy link
Member

Choose a reason for hiding this comment

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

Note: This is assuming single threaded pattern for doing the 2D render, that there's no multithreaded rendering and contention for this variable going on. It's safe in 3.x, and I assume in 4.x, but worth mentioning.

(If it was, it would be solvable with something uglier).

Copy link
Member

@lawnjelly lawnjelly left a comment

Choose a reason for hiding this comment

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

Looks fine as far as I can see but could do with a secondary review if any of 4.x team is up to check it.

@AThousandShips AThousandShips added this to the 4.4 milestone Jan 22, 2025
Copy link
Member

@Calinou Calinou left a comment

Choose a reason for hiding this comment

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

Tested locally, it works as expected. Code looks good to me.

I've tested the MRP from OP as well as the 2D particles demo with particles converted to CPUParticles2D.

With 10 physics ticks per second and interpolation enabled, this is how it looks with GPUParticles2D (which this PR doesn't fix):

gpu_particles_2d_interpolation.mp4

And with CPUParticles2D:

cpu_particles_2d_interpolation.mp4

scene/2d/cpu_particles_2d.cpp Outdated Show resolved Hide resolved
Allows a non-interpolated particle system to closely follow an interpolated target without tracking ahead of the target, by performing fixed timestep interpolation on the particle system global transform, and using this for emission.

Co-authored-by: lawnjelly <lawnjelly@gmail.com>
@rburing rburing force-pushed the fti_2d_particles_on_target branch from 5fd108d to 56fc0fd Compare January 24, 2025 13:13
@Repiteo Repiteo merged commit a736394 into godotengine:master Jan 24, 2025
19 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Jan 24, 2025

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants