• Stars
    star
    291
  • Rank 142,563 (Top 3 %)
  • Language
    C#
  • License
    MIT License
  • Created over 7 years ago
  • Updated about 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A implementation of the marching cubes algorithm on the GPU in Unity.

Marching-Cubes-On-The-GPU

This project generates voxels and the mesh all on the GPU using a compute shader version of the marching cubes algorithm. The voxels are generated using a version of the improved Perlin noise done previously but running in a compute shader.

For practically reasons it maybe best to do this sort of thing using multi-threading on the CPU but I though it would still be useful to have a version running on the GPU. I have also included some code in the script to read back the generated mesh from the GPU and convert it into a normal mesh. I dont recommend doing this every frame but its there if you need it.

The scene generates 3D noise as the voxel values and then uses the marching cubes algorithm to convert the voxels to a mesh. As the mesh is generated using a compute shader the vertices are written to a compute buffer. Unity's draw procedural method is then used to render the buffer.

Using a buffer does present some issues. The buffer has to be a fixed size but the number of vertices generated is unknown until the algorithm is ran. To get around this I created a buffer that could hold the maximum number of vertices that the marching cubes can generate which is 5 triangles per voxel. When the algorithm runs only the generated vertices will be written to the buffer leaving all other vertices in the buffer as being zero filled. This means that when rendered a vertex shader is run for each vertex but as the triangle's have no area there is no fragment generated. This is a bit inefficient but I have compared the method with a buffer converted to a normal Unity mesh and there does not seem to be any difference in rendering performance. Maybe in a more complex scene it could become a issue. To get around this and only have the generated vertices in the buffer maybe some sort of set up with a append buffer or counter buffer (to generate indices for the vertices) would be better.

I have also added a stage to generate the smoothed normals by using the derivatives of the voxel values and interpolating them based on the vertices position. There is also a second scene that generates a new mesh every frame using 4D Perlin noise to make a animated voxel mesh.

Marching Cubes GPU

More Repositories

1

Ceto

Ceto: Ocean system for Unity
C#
1,015
star
2

PBD-Fluid-in-Unity

A PBD fluid in unity running on the GPU
C#
724
star
3

Marching-Cubes

Marching cubes in Unity
C#
462
star
4

Terrain-Topology-Algorithms

Terrain topology algorithms in Unity
C#
430
star
5

Hull-Delaunay-Voronoi

Hull, Delaunay and Voronoi algorithms in Unity
C#
411
star
6

Brunetons-Improved-Atmospheric-Scattering

A Unity port of Brunetons improved atmospheric scattering
HLSL
354
star
7

Position-Based-Dynamics

Position based dynamics in Unity
C#
299
star
8

GPU-GEMS-3D-Fluid-Simulation

3D fluid simulation on the in Unity
C#
278
star
9

Phillips-Ocean

A ocean using Phillips spectrum in Unity
C#
272
star
10

GPU-GEMS-2D-Fluid-Simulation

2D fluid simulation in Unity
C#
247
star
11

Mesh-Voxelization

Mesh voxelization in Unity
C#
231
star
12

CGALDotNet

C# wrapper for CGAL
C#
198
star
13

Interactive-Erosion

Interactive erosion in Unity
C#
170
star
14

2D-Deformable-body-in-Unity

A 2D Deformable body simulation in Unity using FEM
C#
142
star
15

Procedural-Noise

Simple examples of noise algorithms in Unity
C#
136
star
16

Brunetons-Ocean

Brunetons ocean in Unity
C#
127
star
17

Tiled-Directional-Flow

A shader to control the direction water flows based on a flow map in Unity.
ShaderLab
118
star
18

Proland-To-Unity

A port of Proland to Unity
C#
112
star
19

GPU-GEMS-Atmospheric-Scatter

Atmoshperic scatter in Unity
GLSL
73
star
20

AperiodicTexturing

A periodical texturing in Unity
C#
66
star
21

CGALDotNetUnity

CGALDotNet examples in Unity
C#
60
star
22

Brunetons-Atmospheric-Scatter

Brunetons procomputed atmospheric scatting in Unity
C#
55
star
23

GPU-Voronoi-Noise

GPU Voronoi noise in Unity
HLSL
48
star
24

CyclonePhysicsEngine

C# port of the Cylcone physics engine
C#
47
star
25

Wireframe-Shader

A wireframe material in Unity using the geometry shader.
ShaderLab
47
star
26

Simple-Procedural-Terrain

A simple example of how to create a Unity terrain from code using procedural noise.
C#
45
star
27

GPU-GEMS-NBody-Simulation

A NBody simulation in Unity
C#
43
star
28

GPU-GEMS-Improved-Perlin-Noise

Perlin noise on the GPU in Unity
GLSL
42
star
29

CGALDotNetGeometry

Geometry objects under MIT licence for CGALDotNet project
C#
28
star
30

ImageProcessing

A collection of code for processing images
C#
22
star
31

XAtlasDotNet

A c# wrapper around xatlas used to unwrap mesh uv’s.
C++
14
star
32

Common

Common code library
C#
9
star
33

OpenCLDotNet

A C# wrapper around OpenCL
C#
2
star