Skip to main content

VERTEX_GEN_COMPUTE

Constant VERTEX_GEN_COMPUTE 

Source
pub const VERTEX_GEN_COMPUTE: &str = r#"
#version 430 core
layout(local_size_x = 64) in;

struct MCVertex {
    vec4 position;
    vec4 normal;
    vec4 color;
    vec4 emission;  // emission in x, unused yzw
};

layout(std430, binding = 0) readonly buffer FieldValues { float field_values[]; };
layout(std430, binding = 1) readonly buffer FieldColors { vec4 field_colors[]; };
layout(std430, binding = 2) readonly buffer PrefixSums { uint prefix_sums[]; };
layout(std430, binding = 3) writeonly buffer Vertices { MCVertex vertices[]; };
layout(std430, binding = 4) readonly buffer TriTable { int tri_table[4096]; }; // 256 * 16
layout(std430, binding = 5) readonly buffer EdgeTable { uint edge_table[256]; };

uniform uint u_resolution;
uniform float u_threshold;
uniform vec3 u_bounds_min;
uniform vec3 u_bounds_max;

// ... (vertex generation kernel omitted for brevity — mirrors CPU marching cubes logic)
void main() {
    // Each work item processes one cell, looks up its prefix sum offset,
    // and writes vertices to that offset in the SSBO.
    // Full implementation mirrors the CPU ExtractedMesh generation.
}
"#;
Expand description

Pass 3: Generate vertices.