Skip to main content

BLOOM_TEX

Constant BLOOM_TEX 

Source
pub const BLOOM_TEX: &str = r#"
@group(0) @binding(3) var bloom_tex: texture_2d<f32>;

fn bloom_dim() -> vec2<u32> {
    return min(textureDimensions(bloom_tex), post.extent.zw);
}

fn load_bloom(p: vec2<i32>) -> vec4<f32> {
    let dim = vec2<i32>(bloom_dim());
    if (dim.x <= 0 || dim.y <= 0) { return vec4<f32>(0.0); }
    let c = clamp(p, vec2<i32>(0), dim - vec2<i32>(1));
    return textureLoad(bloom_tex, c, 0);
}

fn sample_bloom(x: f32, y: f32) -> vec4<f32> {
    let dim = vec2<f32>(bloom_dim());
    if (dim.x < 1.0 || dim.y < 1.0) { return vec4<f32>(0.0); }
    let xc = clamp(x, 0.0, dim.x - 1.0);
    let yc = clamp(y, 0.0, dim.y - 1.0);
    let x0 = i32(floor(xc));
    let y0 = i32(floor(yc));
    let tx = xc - floor(xc);
    let ty = yc - floor(yc);
    let a = load_bloom(vec2<i32>(x0, y0));
    let b = load_bloom(vec2<i32>(x0 + 1, y0));
    let c = load_bloom(vec2<i32>(x0, y0 + 1));
    let d = load_bloom(vec2<i32>(x0 + 1, y0 + 1));
    return mix(mix(a, b, tx), mix(c, d, tx), ty);
}
"#;