This repository has been archived on 2026-05-22. You can view files and clone it, but cannot push or open issues or pull requests.
Files
Tetrahedrons/Platformer/shaders/intersect.comp

122 lines
2.7 KiB
Plaintext

#version 430
layout(std430, binding=0) buffer TetraVerts
{
vec4 tetraVerts[];
};
layout(std430, binding=1) buffer TetraInds
{
uint tetraInds[];
};
layout(std430, binding=2) buffer PolyVerts
{
vec4 polyVerts[];
};
layout(std430, binding=3) buffer PolyEdges
{
uint polyEdges[];
};
layout(std430, binding=4) buffer PolyFaces
{
uint polyFaces[];
};
layout(std430, binding=5) buffer TetraEdges
{
uint tetrEdges[];
};
layout(std430, binding=6) buffer TetraFaces
{
uint tetrFaces[];
};
uniform PlaneMats
{
mat4 tform;
};
layout(local_size_x = 128, local_size_y = 1, local_size_z = 1) in;
void main () {
int ti0 = int(gl_GlobalInvocationID.x * 4);
int pv0 = int(gl_GlobalInvocationID.x * 4);
int pe0 = int(gl_GlobalInvocationID.x * 8);
int pf0 = int(gl_GlobalInvocationID.x * 6);
int te0 = int(gl_GlobalInvocationID.x * 12);
int tf0 = int(gl_GlobalInvocationID.x * 12);
int pvi = 0;
int pei = 0;
int pfi = 0;
int tei = 0;
int tfi = 0;
for (int i = 0; i < 4; i++)
for (int j = i + 1; j < 4; j++)
{
vec4 a = tetraVerts[tetraInds[ti0 + i]];
vec4 a_ = tform * a;
vec4 b = tetraVerts[tetraInds[ti0 + j]];
vec4 b_ = tform * b;
if (a_.x * b_.x < 0)
{
vec4 p = (b-a) / (a_.x - b_.x) * b_.x + b;
polyVerts[pv0 + pvi++] = p;
}
}
polyEdges[pe0 + pei++] = pv0 + 0;
polyEdges[pe0 + pei++] = pv0 + 1;
polyEdges[pe0 + pei++] = pv0 + 1;
if (pvi == 4)
{
polyEdges[pe0 + pei++] = pv0 + 3;
polyEdges[pe0 + pei++] = pv0 + 3;
}
polyEdges[pe0 + pei++] = pv0 + 2;
polyEdges[pe0 + pei++] = pv0 + 2;
polyEdges[pe0 + pei++] = pv0 + 0;
polyFaces[pf0 + pfi++] = pv0 + 0;
polyFaces[pf0 + pfi++] = pv0 + 1;
polyFaces[pf0 + pfi++] = pv0 + 2;
if (pvi == 4)
{
polyFaces[pf0 + pfi++] = pv0 + 1;
polyFaces[pf0 + pfi++] = pv0 + 2;
polyFaces[pf0 + pfi++] = pv0 + 3;
}
for (int i = 0; i < 4; i++)
for (int j = i + 1; j < 4; j++)
for (int k = j + 1; k < 4; k++)
{
tetrFaces[tf0 + tfi++] = tetraInds[ti0 + i];
tetrFaces[tf0 + tfi++] = tetraInds[ti0 + j];
tetrFaces[tf0 + tfi++] = tetraInds[ti0 + k];
}
for (int i = 0; i < 4; i++)
for (int j = i + 1; j < 4; j++)
{
tetrEdges[tf0 + tei++] = tetraInds[ti0 + i];
tetrEdges[tf0 + tei++] = tetraInds[ti0 + j];
}
while (pvi < 4) polyVerts[pv0 + pvi++] = vec4(0);
while (pei < 8) polyEdges[pe0 + pei++] = 0;
while (pfi < 6) polyFaces[pf0 + pfi++] = 0;
while (tei < 8) polyEdges[te0 + tei++] = 0;
while (tfi < 6) polyFaces[tf0 + tfi++] = 0;
}