2022-01-21 22:38:16 +00:00
|
|
|
let bloomDir = vec2(0.0, 1.0);
|
|
|
|
|
|
|
|
var<private> offsets : array<f32, 3> = array<f32, 3>(0.0, 1.384615421, 3.230769157);
|
|
|
|
|
|
|
|
var<private> weights : array<f32, 3> = array<f32, 3>(0.227027029, 0.31621623, 0.07027027);
|
|
|
|
|
|
|
|
struct BloomUniforms {
|
2022-03-28 14:31:22 +00:00
|
|
|
radius : f32,
|
|
|
|
dim : f32,
|
2022-01-21 22:38:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@group(0) @binding(0) var<uniform> bloom : BloomUniforms;
|
|
|
|
|
|
|
|
@group(0) @binding(1) var bloomTexture : texture_2d<f32>;
|
|
|
|
|
|
|
|
@group(0) @binding(2) var bloomSampler : sampler;
|
|
|
|
|
|
|
|
struct FragmentInput {
|
|
|
|
@location(0)
|
2022-03-28 14:31:22 +00:00
|
|
|
texCoord : vec2<f32>,
|
2022-01-21 22:38:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn getGaussianBlur(texCoord : vec2<f32>) -> vec4<f32> {
|
|
|
|
let texelRadius = (vec2(bloom.radius) / vec2<f32>(textureDimensions(bloomTexture)));
|
|
|
|
let step = (bloomDir * texelRadius);
|
|
|
|
var sum = vec4(0.0);
|
|
|
|
sum = (sum + (textureSample(bloomTexture, bloomSampler, texCoord) * weights[0]));
|
|
|
|
sum = (sum + (textureSample(bloomTexture, bloomSampler, (texCoord + (step * 1.0))) * weights[1]));
|
|
|
|
sum = (sum + (textureSample(bloomTexture, bloomSampler, (texCoord - (step * 1.0))) * weights[1]));
|
|
|
|
sum = (sum + (textureSample(bloomTexture, bloomSampler, (texCoord + (step * 2.0))) * weights[2]));
|
|
|
|
sum = (sum + (textureSample(bloomTexture, bloomSampler, (texCoord - (step * 2.0))) * weights[2]));
|
|
|
|
return vec4(sum.rgb, 1.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
@group(0) @binding(3) var prevTexture : texture_2d<f32>;
|
|
|
|
|
2022-06-07 13:55:34 +00:00
|
|
|
@fragment
|
2022-01-21 22:38:16 +00:00
|
|
|
fn fragmentMain(input : FragmentInput) -> @location(0) vec4<f32> {
|
|
|
|
let blurColor = getGaussianBlur(input.texCoord);
|
|
|
|
let dimColor = (textureSample(prevTexture, bloomSampler, input.texCoord) * bloom.dim);
|
|
|
|
return (blurColor + dimColor);
|
|
|
|
}
|