This project focuses on efficiently generating a cubic voxel chunk mesh using GPU. The meshing and drawing operations achieve a high performance, running at approximately 650 FPS on an RTX 4090. The mesh generation itself is even faster, exceeding 1000 FPS when the camera is disabled.
On HDRP with RTX 2070 its around 300fps +- 20fps
On URP with RTX 2070 its around 600ps +- 100fps,
movie_015.mp4
fixedUVs.mp4
This example utilizes a 3D noise library to generate voxel data. Users can adjust parameters like frequency, amplitude, offset, and speed of the noise through the Unity inspector.
- Creating a mesh on the GPU
- Utilizing Shader Graph with a custom function to draw a mesh using Graphics.DrawProceduralIndirect or Graphics.RenderPrimitivesIndirect. This functionality became achievable with Unity's recent addition of the VertexId node to Shader Graph.
- Generate Voxels Compute: Generates voxel data (0/1) using 3D noise.
- Feedback Compute: Iterates all voxels to calculate the count of vertices and indices required for the mesh.
- Voxelizer Compute: Iterates all voxels to write vertex and index data into the buffers.
- Drawing the Mesh: Utilizes Graphics.DrawProceduralIndirect, Graphics.RenderPrimitivesIndirect or Graphics.RenderPrimitivesIndexedIndirect with data from index and vertex buffers.
The mesh is exclusively generated on the GPU and avoids CPU readback to create a Mesh object, which would be significantly slower (5 FPS).