Voxelize mesh algorithm in Unity. (includes GPU and CPU voxelizers.)
the Demo for GPU Particle with geometry shader. (only tested on windows10 (GTX 1060))
Inspired by Keijiro Takahashi works⚡️ StandardGeometryShader & KvantSpray
the Demo to update the resolution of voxels in realtime. (only tested on windows10 (GTX 1060))
Sample a mesh from SkinnedRenderer in every frame and voxelize it in realtime.
the human model and animation from asset store.
with GPU Voxelizer (recommended)
GPUVoxelData data = GPUVoxelizer.Voxelize(
voxelizer, // ComputeShader (Voxelizer.compute)
mesh, // a target mesh
64, // # of voxels for largest AABB bounds
true // flag to fill in volume or not; if set flag to false, sample a surface only
);
// build voxel cubes integrated mesh
GetComponent<MeshFilter>().sharedMesh = VoxelMesh.Build(data.GetData(), data.UnitLength, useUV);
// build 3D texture represent a volume by voxels.
RenderTexture volumeTexture = GPUVoxelizer.BuildTexture3D(
voxelizer,
data,
texture, // Texture2D to color voxels based on uv coordinates in voxels
RenderTextureFormat.ARGBFloat,
FilterMode.Bilinear
);
// need to release a voxel buffer
data.Dispose();
with CPU Voxelizer
// Voxelize target mesh with CPU Voxelizer
List<Voxel> voxels = CPUVoxelizer.Voxelize(
mesh, // a target mesh
20 // # of voxels for largest AABB bounds
);
Tested on Unity 2018.3.0f2, windows10 (GTX 1060), macOS (metal, not compatible with GPU Particle Demo).
-
Triangle mesh voxelization / Wolfire Games Blog - http://blog.wolfire.com/2009/11/Triangle-mesh-voxelization
-
Möller–Trumbore intersection algorithm - https://en.wikipedia.org/wiki/M%C3%B6ller%E2%80%93Trumbore_intersection_algorithm
-
keijiro/StandardGeometryShader - https://github.com/keijiro/StandardGeometryShader
-
keijiro/KvantSpray - https://github.com/keijiro/KvantSpray
-
Post Processing Stack - https://www.assetstore.unity3d.com/jp/#!/content/83912