2021-03-20 01:11:39 +01:00

39 lines
1.3 KiB
GLSL

#version 430
layout (binding = 0) uniform sampler3D densities;
uniform float step;
uniform float threshold;
uniform int size_x;
uniform int size_y;
uniform int size_z;
out vec3 varTexture;
out int varIndex;
void main(void) {
int id = gl_VertexID;
// Could be optimized by using bit-wise '>>' and '&', but this is more generic
int x = id % size_x;
int y = (id / size_x) % size_y;
int z = (id / size_x / size_y) % size_z;
vec3 xyz = vec3(x, y, z);
gl_Position = vec4(xyz, 1.0);
varTexture = xyz * step;
int b1 = int(texture(densities, varTexture).r < threshold);
int b2 = int(texture(densities, varTexture + vec3(step, 0.0, 0.0)).r < threshold);
int b3 = int(texture(densities, varTexture + vec3(step, 0.0, step)).r < threshold);
int b4 = int(texture(densities, varTexture + vec3(0.0, 0.0, step)).r < threshold);
int b5 = int(texture(densities, varTexture + vec3(0.0, step, 0.0)).r < threshold);
int b6 = int(texture(densities, varTexture + vec3(step, step, 0.0)).r < threshold);
int b7 = int(texture(densities, varTexture + vec3(step, step, step)).r < threshold);
int b8 = int(texture(densities, varTexture + vec3(0.0, step, step)).r < threshold);
varIndex = (b1 << 7) | (b2 << 6) | (b3 << 5) | (b4 << 4) |
(b5 << 3) | (b6 << 2) | (b7 << 1) | b8;
}