Deform MeshCollider with Compute Shader

If you want to do something like this:

 

In C# : You need a for loop which
-> iterates a few ten-thousands vertices, and then
-> for each vertex, you need to calculate the distance between each bead…

All these instructions are run 1 by 1 on CPU. You can imagine the time needed for this.

——–

But with compute shader, those several ten-thousands iterations can be done “at the same time” in GPU (it depends how you setup the data). And the result data will be transferred back to CPU, and directly apply to Mesh.vertices array.

And this is what you can see in this video, the fps stays above 70.

Update: This can be done much faster using AsyncGPUReadback. Visit here for example: https://github.com/cinight/MinimalCompute

One thought on “Deform MeshCollider with Compute Shader

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s