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

Fix collided 3D GPU particles sometimes jittering #92474

Merged

Conversation

Rudolph-B
Copy link
Contributor

Fixes an issue found by @RPicster in #87320.

What would happen is a particle will collide with a collider, the collision system would detect it and attempt to move the particle out of the collider. Sometime this would result in a particle that still touches the collider and other times not (When it touched was cause by a floating point precision error). If the particle did not touch the collider it would start moving again even though visually it is touching the collider. This causes "collided" particles to jitter. It is much more visible at lower Particle "Fixed FPS"

The solution I found was to introduce an EPSILON term in collision calculations. This ensures that collided particle will always "touch" the collider after the particle has been moved. This solution was applied to the Forward+ renderer as well as the OpenGL renderer.

An MRP showcasing the issue and solution for multiple collider types

@Rudolph-B Rudolph-B requested a review from a team as a code owner May 28, 2024 12:47
@akien-mga akien-mga requested a review from a team May 28, 2024 12:58
@akien-mga akien-mga added this to the 4.3 milestone May 28, 2024
Copy link
Member

@clayjohn clayjohn 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 on the RD and GLES3 backends and can confirm that this PR fixes the jittering.

With the jittering fixed, it's more obviously when the particle penetrates and then de-penetrates a surface (in the next frame) unofortunately, but that is something we can fix later. This PR is already a huge improvement.

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.

However, this PR completely changes the appearance of the trails particles in https://github.com/godotengine/godot-demo-projects/tree/master/3d/particles due to the collision behavior being modified in "fringe" cases:

Before

particle_trail_collision_before.mp4

After (this PR)

particle_trail_collision_after.mp4

I assume this is because this PR changes how particles collide when they spawn within a collision box (even if only slightly). Reducing the particle's collision base size from 0.1 to 0.01 fixes the issue in the particles demo, but I thought I'd highlight it.

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.

Despite my above comment, I still think this is good to merge. Code looks good to me.

I would highlight this change in the next blog post still, just in case.

@akien-mga akien-mga merged commit 8b044da into godotengine:master May 31, 2024
16 checks passed
@akien-mga
Copy link
Member

Thanks!

@Rudolph-B
Copy link
Contributor Author

@Calinou What version/commit did you use for the before?

@Calinou
Copy link
Member

Calinou commented Jun 1, 2024

@Calinou What version/commit did you use for the before?

It's master branch from a week ago or so (it's my system-wide godot binary which I regularly rebuild). The particles have looked like this since the initial addition of the particles demo around 4.1.

@Rudolph-B Rudolph-B deleted the fix-collided-particles-jittering branch June 1, 2024 15:37
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.

None yet

4 participants