mirror of
https://github.com/celisej567/metaballs.git
synced 2026-09-15 20:12:36 +03:00
65 lines
2.2 KiB
Plaintext
65 lines
2.2 KiB
Plaintext
#pragma kernel Calculate
|
|
|
|
struct Values {
|
|
float edge0Val, edge1Val, edge2Val, edge3Val, edge4Val, edge5Val, edge6Val, edge7Val;
|
|
};
|
|
|
|
struct Positions {
|
|
float3 edge0Pos, edge1Pos, edge2Pos, edge3Pos, edge4Pos, edge5Pos, edge6Pos, edge7Pos;
|
|
};
|
|
|
|
struct Ball {
|
|
float radiusSq;
|
|
float3 position;
|
|
};
|
|
|
|
StructuredBuffer<Positions> positions;
|
|
StructuredBuffer<Ball> metaballs;
|
|
RWStructuredBuffer<Values> outputBuffer;
|
|
|
|
int width;
|
|
int height;
|
|
|
|
int numMetaballs;
|
|
|
|
[numthreads(8,8,8)]
|
|
void Calculate(uint3 id : SV_DispatchThreadID)
|
|
{
|
|
int pos = id.x + width * (id.y + height * id.z);
|
|
|
|
outputBuffer[pos].edge0Val = 0;
|
|
outputBuffer[pos].edge1Val = 0;
|
|
outputBuffer[pos].edge2Val = 0;
|
|
outputBuffer[pos].edge3Val = 0;
|
|
outputBuffer[pos].edge4Val = 0;
|
|
outputBuffer[pos].edge5Val = 0;
|
|
outputBuffer[pos].edge6Val = 0;
|
|
outputBuffer[pos].edge7Val = 0;
|
|
|
|
for (int i = 0; i < numMetaballs; i++) {
|
|
float3 dist = positions[pos].edge0Pos - metaballs[i].position;
|
|
outputBuffer[pos].edge0Val += metaballs[i].radiusSq / (dist.x * dist.x + dist.y * dist.y + dist.z * dist.z);
|
|
|
|
dist = positions[pos].edge1Pos - metaballs[i].position;
|
|
outputBuffer[pos].edge1Val += metaballs[i].radiusSq / (dist.x * dist.x + dist.y * dist.y + dist.z * dist.z);
|
|
|
|
dist = positions[pos].edge2Pos - metaballs[i].position;
|
|
outputBuffer[pos].edge2Val += metaballs[i].radiusSq / (dist.x * dist.x + dist.y * dist.y + dist.z * dist.z);
|
|
|
|
dist = positions[pos].edge3Pos - metaballs[i].position;
|
|
outputBuffer[pos].edge3Val += metaballs[i].radiusSq / (dist.x * dist.x + dist.y * dist.y + dist.z * dist.z);
|
|
|
|
dist = positions[pos].edge4Pos - metaballs[i].position;
|
|
outputBuffer[pos].edge4Val += metaballs[i].radiusSq / (dist.x * dist.x + dist.y * dist.y + dist.z * dist.z);
|
|
|
|
dist = positions[pos].edge5Pos - metaballs[i].position;
|
|
outputBuffer[pos].edge5Val += metaballs[i].radiusSq / (dist.x * dist.x + dist.y * dist.y + dist.z * dist.z);
|
|
|
|
dist = positions[pos].edge6Pos - metaballs[i].position;
|
|
outputBuffer[pos].edge6Val += metaballs[i].radiusSq / (dist.x * dist.x + dist.y * dist.y + dist.z * dist.z);
|
|
|
|
dist = positions[pos].edge7Pos - metaballs[i].position;
|
|
outputBuffer[pos].edge7Val += metaballs[i].radiusSq / (dist.x * dist.x + dist.y * dist.y + dist.z * dist.z);
|
|
}
|
|
}
|