adding surface extraction pass
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import FluidGridData;
|
||||
|
||||
struct Parameter
|
||||
{
|
||||
float iso;
|
||||
FluidGridData<float> density;
|
||||
RWStructuredBuffer<float3> vertices;
|
||||
RWStructuredBuffer<uint> indices;
|
||||
RWStructuredBuffer<uint> surfaceCount;
|
||||
RWStructuredBuffer<uint> vertexCount;
|
||||
};
|
||||
ParameterBlock<Parameter> params;
|
||||
|
||||
float getDensity(uint x, uint y, uint z)
|
||||
{
|
||||
return params.density[x + gridSize.x * y + gridSize.x * gridSize.y * z];
|
||||
}
|
||||
|
||||
[shader("compute")]
|
||||
[numthreads(32, 8, 1)]
|
||||
void main(uint3 dispatchThreadID : SV_DispatchThreadID)
|
||||
{
|
||||
uint x = dispatchThreadID.x+1;
|
||||
uint y = dispatchThreadID.y+1;
|
||||
uint z = dispatchThreadID.z+1;
|
||||
FluidGridData<float> density = params.density;
|
||||
if(x >= gridSize.x-3 || y >= gridSize.y-3 || z >= gridSize.z-3) return;
|
||||
|
||||
float phi[8] = {
|
||||
getDensity(x, y, z),
|
||||
getDensity(x + 1, y, z),
|
||||
getDensity(x, y + 1, z),
|
||||
getDensity(x + 1, y + 1, z),
|
||||
getDensity(x, y, z + 1),
|
||||
getDensity(x + 1, y, z + 1),
|
||||
getDensity(x, y + 1, z + 1),
|
||||
getDensity(x + 1, y + 1, z + 1)
|
||||
};
|
||||
|
||||
uint cubeIndex = 0;
|
||||
for (uint i = 0; i < 8; ++i) {
|
||||
if (phi[i] < params.iso) {
|
||||
cubeIndex |= (1 << i);
|
||||
}
|
||||
}
|
||||
if(cubeIndex == 0 || cubeIndex == 255) return;
|
||||
}
|
||||
@@ -27,6 +27,6 @@ float4 fragmentMain(VertexOut input) : SV_Target
|
||||
FluidGridData<float> density = params.density;
|
||||
int x = int(input.uv.x * (gridSize.x - 2) + 1);
|
||||
int y = int(input.uv.y * (gridSize.y - 2) + 1);
|
||||
float d = density[x, y, 0];
|
||||
float d = density[x, y, 1];
|
||||
return float4(d, d, d, 1);
|
||||
}
|
||||
Reference in New Issue
Block a user