I've created an Open Source GPU Accelerated Voxel Physics Solver


64,000 Rigid Body Simulations running on the GPU

View Post on My Blog
View Source on GitHub

Excerpt:

The collision calculations are being performed by a Unity Compute Shader. A Unity Command Buffer is used to dispatch the compute shader and the subsequent render commands. In my implementation, no per voxel data is transferred between the GPU and the CPU at runtime, and no C# code is executed at runtime. Voxel forces are modeled by 8 particles per cube - 1 per corner. Every frame, the Compute Shader computes and sums the particle forces to calculate every cubes’ position and velocity. Performance will likely be improved through research and optimization of the per particle Kernels within the Compute Shader. The compute shader’s implementation is based off of Takahiro Harada’s Chapter in GPU Gems 3: Real-Time Rigid Body Simulation on the GPU.

After the physics step, rendering takes place without copying the position and rotation data onto the CPU by using Unity’s CommandBuffer.DrawMeshInstancedIndirect. At the time of writing this API is brand new and seems to have some bugs. For example, I cannot seem to render anything using this method on a Mac. Nothing renders when the Camera’s clear mode is set to Solid Color (the image above is Skybox). Some of these bugs can be resolved by excluding rendering from the command buffer and rendering using Graphics.DrawMeshInstancedIndirect instead. Despite these bugs, I am very thankful to Unity for providing these APIs and empowering my creative development.

4 Likes

Wooah! Cool work dude! :hushed: :slight_smile:

This is amazing :smile:
I was looking for an example for the recent Unity 5.6 release with a Compute Shader for Metal on MacOS and iOS and it works! This is a really good project, thanks a lot for sharing this with the source code and the GIFs. Excellent work!

You’re welcome, Gabriel! Nice work yourself. Cheers from Saskatoon.

1 Like

Great work!! Thank you so much for sharing this!