Unity Marching Cubes Compute Lookup Tables

I have released (part) of the Transvoxel lookup tables for Unity compute shaders.

Hello!

Today I'm releasing a Unity compute shader include which has part of the Transvoxel lookup table implemented in hlsl. I built this while working on my Unity terrain generator's compute shader support (see image above). I am releasing this part of it simply because it was annoying to convert to hlsl, so I'm releasing it to save anyone else the bother. I will be adding the transition cell stuff once I implement them in my system.

I hope this saves you time when working on your next marching cubes project. Also, this probably will also work with other hlsl compute shaders, not just unity.

<script src="https://gist.github.com/Rover656/b9ee785a572367083b6aa2c7be5c0234.js"></script>

Usage example

Here's an example as to how you use this (hint: it's exactly the same as the original).

1// Generate case code
2int caseCode = 0;
3for (int i = 0; i < 8; i++)
4    if (densities[i] < isoLevel) caseCode |= 1 << i;
5
6// Get the cell class
7int cellClass = regularCellClass[caseCode];
8
9// Get cell data
10RegularCell cellData = regularCellData[cellClass];
11
12// Now you have access to the number of triangles, number of vertices, vertex data and the indices.
13int triangleCount = cellData.tCount;
14int vertexCount = cellData.vCount;
15int indices[] = cellData.indices;
16
17// Get the vertex data
18int vertexData[] = regularVertexData[caseCode];
HLSL

And here's an example on using the vertex data (note, this example does not show vertex reuse).

1// Vertex data usage example
2int edgeCode = vertexData[vertexIndex];
3int v0 = ((edgeCode & 0xFF) >> 0) & 0x0F;
4int v1 = ((edgeCode & 0xFF) >> 4) & 0x0F;
HLSL