blob: 6c8d311d3e30ab07e3fe408b83f3ba9dabb69bf3 (
plain) (
blame)
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
29
30
31
32
33
34
|
struct VertexOutput {
@builtin(position) position: vec4f,
@location(0) tex_coord: vec2f,
}
struct EffectUniforms {
resolution: vec2f,
direction: vec2f,
scalars: vec4f,
}
@group(0) @binding(0) var input_texture: texture_2d<f32>;
@group(0) @binding(1) var input_sampler: sampler;
@group(1) @binding(0) var<uniform> uniforms: EffectUniforms;
@fragment
fn fragment_main(input: VertexOutput) -> @location(0) vec4f {
let texel_size = vec2f(1.0, 1.0) / uniforms.resolution;
let sigma = uniforms.scalars.x;
let step_size = uniforms.scalars.y;
var color = vec4f(0.0, 0.0, 0.0, 0.0);
var total_weight = 0.0;
for (var index = -30; index <= 30; index = index + 1) {
let position = f32(index) * step_size;
let weight = exp(-(position * position) / (2.0 * sigma * sigma));
let sample_uv = input.tex_coord + (texel_size * uniforms.direction * position);
color = color + textureSample(input_texture, input_sampler, sample_uv) * weight;
total_weight = total_weight + weight;
}
return color / total_weight;
}
|