25 layout (local_size_x = 4, local_size_y = 4, local_size_z = 4) in;
41 float val[8] =
float[8](
42 imageLoad(inSurface, texel + ivec3(0, 0, 0))
.r,
43 imageLoad(inSurface, texel + ivec3(1, 0, 0))
.r,
44 imageLoad(inSurface, texel + ivec3(1, 0, 1))
.r,
45 imageLoad(inSurface, texel + ivec3(0, 0, 1))
.r,
46 imageLoad(inSurface, texel + ivec3(0, 1, 0))
.r,
47 imageLoad(inSurface, texel + ivec3(1, 1, 0))
.r,
48 imageLoad(inSurface, texel + ivec3(1, 1, 1))
.r,
49 imageLoad(inSurface, texel + ivec3(0, 1, 1))
.r
55 if (val[0] < 0.0) mask |= 1;
56 if (val[1] < 0.0) mask |= 2;
57 if (val[2] < 0.0) mask |= 4;
58 if (val[3] < 0.0) mask |= 8;
59 if (val[4] < 0.0) mask |= 16;
60 if (val[5] < 0.0) mask |= 32;
61 if (val[6] < 0.0) mask |= 64;
62 if (val[7] < 0.0) mask |= 128;
66 if (mask == 0 || mask == 0xff)
70 vec3(-1.0, -1.0, -1.0),
71 vec3(+1.0, -1.0, -1.0),
72 vec3(+1.0, -1.0, +1.0),
73 vec3(-1.0, -1.0, +1.0),
74 vec3(-1.0, +1.0, -1.0),
75 vec3(+1.0, +1.0, -1.0),
76 vec3(+1.0, +1.0, +1.0),
77 vec3(-1.0, +1.0, +1.0)
83 int cube_edges[24] =
int[24](
103 int edge_table[256] =
int[256](
104 0x0 , 0x109, 0x203, 0x30a, 0x406, 0x50f, 0x605, 0x70c,
105 0x80c, 0x905, 0xa0f, 0xb06, 0xc0a, 0xd03, 0xe09, 0xf00,
106 0x190, 0x99 , 0x393, 0x29a, 0x596, 0x49f, 0x795, 0x69c,
107 0x99c, 0x895, 0xb9f, 0xa96, 0xd9a, 0xc93, 0xf99, 0xe90,
108 0x230, 0x339, 0x33 , 0x13a, 0x636, 0x73f, 0x435, 0x53c,
109 0xa3c, 0xb35, 0x83f, 0x936, 0xe3a, 0xf33, 0xc39, 0xd30,
110 0x3a0, 0x2a9, 0x1a3, 0xaa , 0x7a6, 0x6af, 0x5a5, 0x4ac,
111 0xbac, 0xaa5, 0x9af, 0x8a6, 0xfaa, 0xea3, 0xda9, 0xca0,
112 0x460, 0x569, 0x663, 0x76a, 0x66 , 0x16f, 0x265, 0x36c,
113 0xc6c, 0xd65, 0xe6f, 0xf66, 0x86a, 0x963, 0xa69, 0xb60,
114 0x5f0, 0x4f9, 0x7f3, 0x6fa, 0x1f6, 0xff , 0x3f5, 0x2fc,
115 0xdfc, 0xcf5, 0xfff, 0xef6, 0x9fa, 0x8f3, 0xbf9, 0xaf0,
116 0x650, 0x759, 0x453, 0x55a, 0x256, 0x35f, 0x55 , 0x15c,
117 0xe5c, 0xf55, 0xc5f, 0xd56, 0xa5a, 0xb53, 0x859, 0x950,
118 0x7c0, 0x6c9, 0x5c3, 0x4ca, 0x3c6, 0x2cf, 0x1c5, 0xcc ,
119 0xfcc, 0xec5, 0xdcf, 0xcc6, 0xbca, 0xac3, 0x9c9, 0x8c0,
120 0x8c0, 0x9c9, 0xac3, 0xbca, 0xcc6, 0xdcf, 0xec5, 0xfcc,
121 0xcc , 0x1c5, 0x2cf, 0x3c6, 0x4ca, 0x5c3, 0x6c9, 0x7c0,
122 0x950, 0x859, 0xb53, 0xa5a, 0xd56, 0xc5f, 0xf55, 0xe5c,
123 0x15c, 0x55 , 0x35f, 0x256, 0x55a, 0x453, 0x759, 0x650,
124 0xaf0, 0xbf9, 0x8f3, 0x9fa, 0xef6, 0xfff, 0xcf5, 0xdfc,
125 0x2fc, 0x3f5, 0xff , 0x1f6, 0x6fa, 0x7f3, 0x4f9, 0x5f0,
126 0xb60, 0xa69, 0x963, 0x86a, 0xf66, 0xe6f, 0xd65, 0xc6c,
127 0x36c, 0x265, 0x16f, 0x66 , 0x76a, 0x663, 0x569, 0x460,
128 0xca0, 0xda9, 0xea3, 0xfaa, 0x8a6, 0x9af, 0xaa5, 0xbac,
129 0x4ac, 0x5a5, 0x6af, 0x7a6, 0xaa , 0x1a3, 0x2a9, 0x3a0,
130 0xd30, 0xc39, 0xf33, 0xe3a, 0x936, 0x83f, 0xb35, 0xa3c,
131 0x53c, 0x435, 0x73f, 0x636, 0x13a, 0x33 , 0x339, 0x230,
132 0xe90, 0xf99, 0xc93, 0xd9a, 0xa96, 0xb9f, 0x895, 0x99c,
133 0x69c, 0x795, 0x49f, 0x596, 0x29a, 0x393, 0x99 , 0x190,
134 0xf00, 0xe09, 0xd03, 0xc0a, 0xb06, 0xa0f, 0x905, 0x80c,
135 0x70c, 0x605, 0x50f, 0x406, 0x30a, 0x203, 0x109, 0x0 );
137 int edge_mask = edge_table[
mask];
140 int edge_crossings = 0;
142 for (
int i = 0; i < 12; i++)
145 if ((edge_mask & (1 << i)) == 0)
149 int ei0 = cube_edges[i * 2];
150 int ei1 = cube_edges[i * 2 + 1];
151 vec3 e0 = cube_vertices[ei0];
152 vec3 e1 = cube_vertices[ei1];
159 float t =
clamp((0.0 - v0) / (v1 - v0), 0.0, 1.0);
160 offset += e0 + t * (e1 - e0);
166 offset /=
float(edge_crossings);
174 uint unique = atomicCounterIncrement(outCount);
175 int index = texel.z * size.x * size.y + texel.y * size.x +
texel.x;
176 outIndices[unique] = uint(index);
178 return vec4(offset, 1.0);
183 ivec3 texel = ivec3(gl_GlobalInvocationID.xyz);
189 imageStore(outCentroid, texel,
vec4(offset, v.
w));
GLenum GLuint GLintptr offset
float clamp(float x, float min, float max)
vec4 ComputeCentroid(ivec3 texel)
layout(local_size_x=4, local_size_y=4, local_size_z=4) in
GLenum GLuint GLintptr GLsizeiptr size
void uniform(string name, const mat4 &v)
GLint GLint GLint GLint GLint x
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei imageSize
GLint GLint GLint GLint GLint GLint GLint GLbitfield mask