summaryrefslogtreecommitdiff
path: root/src/effects/gaussian_blur.wgsl
blob: de0f2cfb5930f8b5c9ad32e9853dbd4f97f21af6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// 5x5 gaussian blur

@group(0) @binding(0) var smplr: sampler;
@group(0) @binding(1) var txt: texture_2d<f32>;

#include "common_uniforms"
#include "render/fullscreen_vs"

// effect_params.p: x=strength, y=strength_audio, z=stretch
struct WgslEffectParams { p: vec4f, c: vec4f }

@group(0) @binding(2) var<uniform> uniforms: CommonUniforms;
@group(0) @binding(3) var<uniform> effect_params: WgslEffectParams;

@fragment fn fs_main(@builtin(position) p: vec4f) -> @location(0) vec4f {
    let pulse = 1.0 + uniforms.audio_intensity * effect_params.p.y;
    let size = effect_params.p.x * pulse;
    let dir = vec2f(1., effect_params.p.z) * size / uniforms.resolution.x;

    let uv = p.xy / uniforms.resolution;
    var res = vec4f(0.0);
    for (var x: f32 = -2.0; x <= 2.0; x += 1.0) {
        for (var y: f32 = -2.0; y <= 2.0; y += 1.0) {
            res += textureSample(txt, smplr, uv + vec2f(x, y) * dir);
        }
    }
    return res * (1. / 25.0);
}