I built a VR chainsaw in Unity.
Here's a breakdown thread of how I did it

[1/13]
Here's a breakdown thread of how I did it


[1/13]
The log is rendered using GPU based marching cubes. I based it off of this project: https://github.com/Scrawk/Marching-Cubes-On-The-GPU
It's a technique used by sculpting apps like Oculus Medium, and it allows partial and concave cuts. Perfect for carving! [2/13]
It's a technique used by sculpting apps like Oculus Medium, and it allows partial and concave cuts. Perfect for carving! [2/13]
The grid of voxels uses a signed distance field to define the shapes in it. I use a cylinder function for the log ( https://iquilezles.org/www/articles/distfunctions/distfunctions.htm).
The saw blade is a box with a cylinder at the end of it.
I use SDF subtraction to carve out the blade shape from the cylinder. [3/13]
The saw blade is a box with a cylinder at the end of it.
I use SDF subtraction to carve out the blade shape from the cylinder. [3/13]
To find out if a cut piece of wood is detached from the rest of the log, I use the GPU based connected component labelling technique from this paper:
https://arxiv.org/abs/1712.09789 .
Here's a codepen of the algorithm: https://codepen.io/pushmatrix/pen/eYzbZbd
[4/13]
https://arxiv.org/abs/1712.09789 .
Here's a codepen of the algorithm: https://codepen.io/pushmatrix/pen/eYzbZbd
[4/13]
I make the wood pieces fly off using a vertex shader. If a vertex is no longer attached to the log, I move it parallel to the blade.
Adding collision detection to these cut pieces would be pretty expensive. Having them fly off quickly seemed like a fine solution.
[5/13]
Adding collision detection to these cut pieces would be pretty expensive. Having them fly off quickly seemed like a fine solution.
[5/13]
Some people commented that the size of the cuts are larger than the size of the blade. Unfortunately detecting detached pieces is really computationally intense.
I am limited to a 64x64x64 voxel grid size for performance reasons.
[6/13]
I am limited to a 64x64x64 voxel grid size for performance reasons.

[6/13]
The wood shader was my favourite part.
To get the log ring effect, I use a texture with horizontal grain lines. I project it top down on the log using circular mapping. This warps the texture into a circle. I do the same with the normal map.
[7/13]
To get the log ring effect, I use a texture with horizontal grain lines. I project it top down on the log using circular mapping. This warps the texture into a circle. I do the same with the normal map.
[7/13]
A slight amount of noise is applied to the texture to make the rings irregular and more organic. This noise changes as you go down the log so that each cross section looks a little bit different. [8/13]
You can see from a side cross section the impact the noise has on creating a convincing natural wood effect. [9/13]
The bark is a texture that I use cylindrical mapping to wrap it along the log. I blend between the wood ring shader and the bark so that the bark only appears on the outside.
[10/13]
[10/13]
A defining feature of chainsaw art is seeing the marks left by the saw.
For every cut voxel, I store the orientation the blade was in.
I can use this in combination with the voxel's normal to project a texture onto the wood that is rotated the same as the blade. [11/13]
For every cut voxel, I store the orientation the blade was in.
I can use this in combination with the voxel's normal to project a texture onto the wood that is rotated the same as the blade. [11/13]
To add depth to the cuts, I calculate ambient occlusion using this technique outlined by @AlanZucconi: https://www.alanzucconi.com/2016/07/01/ambient-occlusion [12/13]
Then add some particles, some sweet work gloves and a little environment and you got yourself a fun little tool! Now to get it working on Quest 
Hope you enjoyed, and post any questions you have below
https://twitter.com/pushmatrix/status/1326169348961079299?s=20

Hope you enjoyed, and post any questions you have below
