godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.78k stars 21.13k forks source link

`GPUParticlesCollisionSDF3D` does not seem to have any visible effect on particles #93573

Open derkork opened 4 months ago

derkork commented 4 months ago

Tested versions

v4.2.2.stable.mono.official [15073afe3]

System information

Godot v4.2.2.stable.mono - Windows 10.0.22631 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 4080 (NVIDIA; 32.0.15.5599) - AMD Ryzen 9 7950X3D 16-Core Processor (32 Threads)

Issue description

I have two identical particle systems. Both are set up to have collision mode rigid. Both particle systems are above a cube with which they are supposed to collide. The left particle system interacts with a GPUParticlesCollisionBox3D which shows some tunneling issues as identified in https://github.com/godotengine/godot/issues/93570. The right particle system is supposed to interact with a GPUParticlesCollisionSDF3D. This is set up to calculate an SDF for a box with the same extents as the GPUParticlesCollisionBox3D on the left side. However, no matter which resolution is baked, the particles just go right through the GPUParticlesCollisionBox3D. This problem persists even if I double the thickness of the geometry. Also the AABB is set up correctly so it's not an instance of https://github.com/godotengine/godot/issues/93567 :

https://github.com/godotengine/godot/assets/327257/ce0be673-e66b-41e5-8e55-73129812e8ad

Steps to reproduce

In the attached reproducer project, open particle_collisions_test3.tscn to inspect and play around with the setup.

Minimal reproduction project (MRP)

reproducer3.zip

smix8 commented 4 months ago

I think this is just a problem with the editor scene not reloading everything when the baked data resource changes because when you save the scene and open it again it works.

derkork commented 4 months ago

https://github.com/godotengine/godot/assets/327257/659da6e6-f949-4c85-984d-9cda2a513211

That doesn't seem to be the case here. Even restarting the editor doesn't fix it for me.

Calinou commented 4 months ago

The issue is that your SDF extents are exactly flush with the mesh geometry. The SDF baker is unable to bake the collider data correctly in this situation. To avoid this, extend the SDF's height so that there's at least one cell of free space between the end of the geometry and the SDF's boundaries. In the MRP, you can try increasing the height from 1.0 to 1.5, bake again then reload the scene.

In general, when you define extents for something to bake, it's a good idea to add a small margin around your geometry. This also applies to VoxelGI, ReflectionProbe and so on.

That said, even with this change, many particles are still falling through the box in both 4.2.2.stable and 4.3.beta2. It doesn't happen as often if you set Fixed FPS to 0 on the particles (so that particles simulate more often and have less risk of tunneling), but it still happens occasionally. Particles won't fall through the box anymore, but you'll see some of them hanging at the bottom of the box if you fly through the box in the editor. I don't know if this can be fixed though given the nature of SDF collision.

https://github.com/godotengine/godot/assets/180032/f9a6e8b7-95b6-48ff-bb0d-57c13a074fdf

derkork commented 4 months ago

Increasing the size indeed helps a bit though I'd say that most of the particles just fall straight through.

https://github.com/godotengine/godot/assets/327257/1ba6d829-b0fa-4499-98d6-ca02af3915ab

I played around with the FPS and saw no real improvement with 0, but saw drastic improvements when cranking the FPS up to rather ridiculous levels:

https://github.com/godotengine/godot/assets/327257/d2e09b60-4f6c-4be5-8aea-26a914173a43

not sure if this is a workable solution though unless you have a rather capable machine.

derkork commented 4 months ago

I was wondering if there maybe is some minimum size that a thing must have so the SDF works reasonably well without having to crank up the FPS so much. I set this up according to the documentation and was expecting to see results like in this progress blog post. So were the FPS really cranked up for this video or why did it work there for the test Suzanne but not for my simple cube? E.g. what could be a checklist the developer can look at when using these GPUParticlesCollisionSDF3D in their project?

derkork commented 2 months ago

I found that changing the base size can help a bit. At the default all the particles fall through the tree. If I increase it, some particles actually collide.

https://github.com/user-attachments/assets/62262682-ca43-4678-84b3-9a49268b6db8

Another thing that helps is increasing the thickness from the default of 1m to 2m though still some particles fall through and i'm not sure why 1m isn't enough.