let bloomDir = vec2(0.0, 1.0); var offsets : array = array(0.0, 1.384615421, 3.230769157); var weights : array = array(0.227027029, 0.31621623, 0.07027027); struct BloomUniforms { radius : f32; dim : f32; } @group(0) @binding(0) var bloom : BloomUniforms; @group(0) @binding(1) var bloomTexture : texture_2d; @group(0) @binding(2) var bloomSampler : sampler; struct FragmentInput { @location(0) texCoord : vec2; } fn getGaussianBlur(texCoord : vec2) -> vec4 { let texelRadius = (vec2(bloom.radius) / vec2(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; @stage(fragment) fn fragmentMain(input : FragmentInput) -> @location(0) vec4 { let blurColor = getGaussianBlur(input.texCoord); let dimColor = (textureSample(prevTexture, bloomSampler, input.texCoord) * bloom.dim); return (blurColor + dimColor); }