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

**URL:** https://discussions.unity.com/t/ive-created-an-open-source-gpu-accelerated-voxel-physics-solver/660960
**Category:** Physics
**Tags:** Physics
**Created:** [April 8, 2017, 6:24am UTC](https://discussions.unity.com/t/ive-created-an-open-source-gpu-accelerated-voxel-physics-solver/660960 "2017-04-08T06:24:27Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![00jknight](https://avatars.discourse-cdn.com/v4/letter/0/3d9bf3/32.png) [@00jknight](https://discussions.unity.com/u/00jknight)
#### Post date: [April 8, 2017, 6:24am UTC](https://discussions.unity.com/t/ive-created-an-open-source-gpu-accelerated-voxel-physics-solver/660960/1 "2017-04-08T06:24:27Z")

</div>

[![](https://europe1.discourse-cdn.com/unity/original/4X/9/f/9/9f9efb040dc53a8f201be7044710198eeb31226d.gif)](http://www.00jknight.com/blog/gpu-accelerated-voxel-physics-solver)  
_64,000 Rigid Body Simulations running on the GPU_

[View Post on My Blog](http://www.00jknight.com/blog/gpu-accelerated-voxel-physics-solver)  
[View Source on GitHub](https://github.com/jknightdoeswork/gpu-physics-unity)

Excerpt:

The collision calculations are being performed by a [Unity Compute Shader](https://github.com/jknightdoeswork/gpu-physics-unity/blob/master/Assets/Physics/GPUPhysicsComputeShader.compute). 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](http://http.developer.nvidia.com/GPUGems3/gpugems3_ch29.html).

After the physics step, rendering takes place without copying the position and rotation data onto the CPU by using Unity’s [CommandBuffer.DrawMeshInstancedIndirect](https://docs.unity3d.com/ScriptReference/Rendering.CommandBuffer.DrawMeshInstancedIndirect.html). 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](https://docs.unity3d.com/ScriptReference/Graphics.DrawMeshInstancedIndirect.html) instead. Despite these bugs, I am very thankful to Unity for providing these APIs and empowering my creative development.

---

<div class="post-metadata">

### Author: ![BrandyStarbrite](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/brandystarbrite/32/463783_2.png) [@BrandyStarbrite](https://discussions.unity.com/u/BrandyStarbrite)
#### Post date: [April 8, 2017, 6:23pm UTC](https://discussions.unity.com/t/ive-created-an-open-source-gpu-accelerated-voxel-physics-solver/660960/2 "2017-04-08T18:23:37Z")

</div>

Wooah! Cool work dude! 😯 🙂

---

<div class="post-metadata">

### Author: ![GabLeRoux](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/gableroux/32/90129_2.png) [@GabLeRoux](https://discussions.unity.com/u/GabLeRoux)
#### Post date: [April 9, 2017, 11:40pm UTC](https://discussions.unity.com/t/ive-created-an-open-source-gpu-accelerated-voxel-physics-solver/660960/3 "2017-04-09T23:40:14Z")

</div>

This is amazing 😄  
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!

---

<div class="post-metadata">

### Author: ![00jknight](https://avatars.discourse-cdn.com/v4/letter/0/3d9bf3/32.png) [@00jknight](https://discussions.unity.com/u/00jknight)
#### Post date: [April 11, 2017, 4:18am UTC](https://discussions.unity.com/t/ive-created-an-open-source-gpu-accelerated-voxel-physics-solver/660960/4 "2017-04-11T04:18:10Z")

</div>

> [@GabLeRoux](#):
>
> This is amazing 😄  
> 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.

---

<div class="post-metadata">

### Author: ![Edy](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/edy/32/613709_2.png) [@Edy](https://discussions.unity.com/u/Edy)
#### Post date: [April 19, 2017, 10:44am UTC](https://discussions.unity.com/t/ive-created-an-open-source-gpu-accelerated-voxel-physics-solver/660960/5 "2017-04-19T10:44:07Z")

</div>

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