facett-core 0.1.10

facett — visual kernel: render a node/edge Scene into egui (wgpu fast path to come)
Documentation
// **Reusable separable Gaussian blur** (feature `wgpu`) — the GPU substrate for the
// frosted-glass backdrop blur (`SurfaceSpec::Frosted`, T2.3) and any post effect
// that wants a cheap, large-radius blur of an offscreen texture.
//
// Separable: a 2D Gaussian factors into a horizontal then a vertical 1D pass, so the
// full kernel costs O(2·taps) instead of O(taps²). One pipeline drives both passes;
// the per-pass uniform picks the axis (`texel.zw`) and carries the CPU-computed
// 9-tap weights (offsets 0..4, mirrored) so the caller controls the radius via σ.

struct BlurUniforms {
    // texel.xy = 1/src_w, 1/src_h ; texel.zw = blur axis in texels (H=(1,0), V=(0,1))
    texel: vec4<f32>,
    // Gaussian weights for offsets 0,1,2,3 (centre + first three rings).
    w0123: vec4<f32>,
    // Weight for offset 4 (x); yzw unused/pad.
    w4: vec4<f32>,
};

@group(0) @binding(0) var<uniform> U: BlurUniforms;
@group(0) @binding(1) var src_tex: texture_2d<f32>;
@group(0) @binding(2) var src_smp: sampler;

struct VsOut {
    @builtin(position) clip: vec4<f32>,
    @location(0) uv: vec2<f32>,
};

@vertex
fn blur_vs(@builtin(vertex_index) vi: u32) -> VsOut {
    var p = array<vec2<f32>, 3>(
        vec2<f32>(-1.0, -1.0),
        vec2<f32>( 3.0, -1.0),
        vec2<f32>(-1.0,  3.0),
    );
    var out: VsOut;
    let xy = p[vi];
    out.clip = vec4<f32>(xy, 0.0, 1.0);
    out.uv = vec2<f32>(xy.x * 0.5 + 0.5, 1.0 - (xy.y * 0.5 + 0.5));
    return out;
}

@fragment
fn blur_fs(in: VsOut) -> @location(0) vec4<f32> {
    let step = U.texel.xy * U.texel.zw;
    var c = textureSample(src_tex, src_smp, in.uv) * U.w0123.x;
    c = c + textureSample(src_tex, src_smp, in.uv + step * 1.0) * U.w0123.y;
    c = c + textureSample(src_tex, src_smp, in.uv - step * 1.0) * U.w0123.y;
    c = c + textureSample(src_tex, src_smp, in.uv + step * 2.0) * U.w0123.z;
    c = c + textureSample(src_tex, src_smp, in.uv - step * 2.0) * U.w0123.z;
    c = c + textureSample(src_tex, src_smp, in.uv + step * 3.0) * U.w0123.w;
    c = c + textureSample(src_tex, src_smp, in.uv - step * 3.0) * U.w0123.w;
    c = c + textureSample(src_tex, src_smp, in.uv + step * 4.0) * U.w4.x;
    c = c + textureSample(src_tex, src_smp, in.uv - step * 4.0) * U.w4.x;
    return c;
}