godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.12k stars 69 forks source link

Add a Cloth physics node #2513

Open NHodgesVFX opened 3 years ago

NHodgesVFX commented 3 years ago

Describe the project you are working on

3rd person platformer

Describe the problem or limitation you are having in your project

I want my characters cloth to move, this is possible with bone physics or softybodys currently. Bone based requires bones, can be quite unstable, and doesn't look as good as proper cloth. Softbodys are really hard to setup, and simulate based on the vertex count with no interpolation so performance isn't great.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Implement a proper cloth node that is easy to setup and has the options to interpolate vertex positions. This way you can have a character with a cape that has 5000 vertices but only need to simulate maybe 500-1000 points.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

Cloth algorithm could really be anything fast and stable, PBD would be good as its both but its also very extendable. Its also easy to parallelize and can run on the GPU.

Interpolation is a really nice feature because it allows simulating way less points than the mesh actually uses. It seems the main way to do this is to make the user provide a proxy mesh which is then simulated and the result transferred to the higher poly cloth. For ease of use its probably possible to autogenerate the proxy mesh. So that would give you 3 options simulate the full vertex count directly, simulate using a proxy mesh that the user imports, or simulate using a proxy mesh that is auto-generated.

The cloth node could be its own node like softbody. With soft body its really hard to pin vertices because the points overlap. I think implementing a painting system where you can paint the pins as well as the stiffness to them would be good not only for cloth but also for softbodys. For some references look at how ue4 handles painting cloth https://youtu.be/fIRIW00WgVI?t=145 or unity https://www.youtube.com/watch?v=Nc_ZMgEFj-A

Another nice feature could be self-collisions although its not mandatory and can be expensive but improves the simulation and look a lot.

With this a thing to keep in mind is that this can be used on something like a flag or on a characters clothing. this means the cloth simulation system needs to play well with skeletons and skinning. Basically pinned points still need to follow its respective bone.

Why not just improve softbodys. I'm not sure what algorithm is used for softbodys but my guess is its not tailored to simulating cloth. So the results would look worse and it might be more computationally expensive. Cloth would also be able to run on the GPU, I'm not sure if this is practical with the existing softbodys

Softbodys should still be improved though if this proposal gets added it should be possible to use the painting or better selection system in softbodys as well.

If this enhancement will not be used often, can it be worked around with a few lines of script?

No

Is there a reason why this should be core and not an add-on in the asset library?

Godot includes softbody in core and a proper cloth node would be utilized in many games as well.

mrjustaguy commented 3 years ago

Something like this would be great for cloth simulations (and some other applications): https://mmacklin.com/sdfcontact.pdf https://www.youtube.com/watch?v=ooZ9rUYOFI4 (YT video is a quick overview of the paper in action)

pouleyKetchoupp commented 3 years ago

All these ideas are interesting, although I feel like it's a lot to discuss in one thread. It would be great to have separate proposals for weight painting, interpolation, PBD, GPU simulation, self-collision and skinning for pinned vertices with possibly more details and example use cases for some of them.

Edit: About adding a Cloth Physics node: Most of these could be improvements on the SoftBody node (possibly as options) so a specific cloth node doesn't seem really needed. I can see how PBD or GPU simulation could potentially have their own node though, if they need to be setup in a different way.

NHodgesVFX commented 3 years ago

I can add more proposals with more details. I think it makes sense to combine some of them for example pbd and gpu would go well together. As that would allow a high number of particles to be simulated and could be a separate node. Skinning, interpolation and self collision could probaly be its own as well. Then lastly the weight paint editor. I guess over the next couple hours or days I'll create some more proposals.

pouleyKetchoupp commented 3 years ago

Yeah, that makes sense. Self collision could be separated, as it's kind of a different part of the system and more can be discussed about soft body collision options, but no big deal if you prefer to put it together with skinning and interpolation.

NHodgesVFX commented 3 years ago

I was thinking I would just write another proposal about improvements to the softbody node. With the exception of the weight paint editor thingy because although it would be used for soft body. it could be used for other stuff too, so it should probaly be its own thing.

Then of course one for gpu pbd

pouleyKetchoupp commented 3 years ago

Alright, that's fine to me.

ca3games commented 3 years ago

I think a better idea would be to support some simulation made on a 3D software, like blender, where the cloth simulation is baked into a series of shapekeys deformation, that way you can basically have a cloth simulation inside an animation, without performance hits.

I find the idea still too performance consuming for having hundreds of npcs walking with cloth simulations, but I see the value on maybe a baked solution for things like flags or some semi baked solution.

I believe a cloth soft body would still be acceptable for things like character capes or strands of hair.

NHodgesVFX commented 3 years ago

I think a better idea would be to support some simulation made on a 3D software, like blender, where the cloth simulation is baked into a series of shapekeys deformation, that way you can basically have a cloth simulation inside an animation, without performance hits.

I find the idea still too performance consuming for having hundreds of npcs walking with cloth simulations, but I see the value on maybe a baked solution for things like flags or some semi baked solution.

I believe a cloth soft body would still be acceptable for things like character capes or strands of hair.

You can do hundreds of npcs with cloth no problem. you just simulate the ones that are close to you and that you can see. Baking physics isn't great because you lose the interactivity. Also for hundreds of npcs you will have an issue with bandwidth and file size.

Plus computers get way more powerful each year unless your targeting low end mobile realtime cloth is completely fine for performance

jeffrey-cochran commented 3 years ago

Something like this would be great for cloth simulations (and some other applications): https://mmacklin.com/sdfcontact.pdf https://www.youtube.com/watch?v=ooZ9rUYOFI4 (YT video is a quick overview of the paper in action)

Yeah Macklin and Müller have done a bunch of awesome work

DiegoSynth commented 9 months ago

This would be really very useful, avoiding the pain of pre-baking cloth animations which adds days to the pipeline every time a change is made to the model. Unfortunately the Softbody node just doesn't work for this if you add collision. Thanks!

davidrochin commented 3 weeks ago

It would be amazing to see this in Godot. At least for my project, baking physics on bone animation would be an insane amount of work. I would need hundreds of extra bones on my uber-rig (that I'm reusing with dozens of characters), and skinning would become extremely hard.

Being able to set a Proxy mesh for the cloth simulation would be really useful, since it would allow us to add physics to a mesh that is visually complex, without actually having a complex simulation.

DiegoSynth commented 3 weeks ago

I have seen that Godot Jolt has added a SoftBody that in theory would do this. I'm not sure how big is the impact of switching from the inbuilt physics system to Jolt though. Do we need to use different Nodes if we switch? (for example something else instead of RigidBody3D?) Or is it transparent and all the methods and nodes remain the same?

If anyone knows, please share!