diff options
Diffstat (limited to 'shaders/bloom.kage')
-rw-r--r-- | shaders/bloom.kage | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/shaders/bloom.kage b/shaders/bloom.kage new file mode 100644 index 0000000..fc987b1 --- /dev/null +++ b/shaders/bloom.kage @@ -0,0 +1,43 @@ +//go:build ignore +//kage:unit pixels + +package main + +const THRESHOLD = .9 +const DIRECTIONS = 30.0 // BLUR DIRECTIONS (Default 16.0 - More is better but slower) +const QUALITY = 12.0 // BLUR QUALITY (Default 4.0 - More is better but slower) +const SIZE = 5.0 // BLUR SIZE (Radius) +const PI = 6.28318530718 // Pi*2 +const OPACITY = 0.21 + + +var Time float +var NoiseOffset float + +func Fragment(dstPos vec4, srcPos vec2, color vec4) vec4 { + uv := srcPos + + average := vec3(0.0) + radius := SIZE / 2 + + amount := 0.0 + for d:=0.0; d<PI; d+=PI/DIRECTIONS{ + for i:=1.0/QUALITY; i<=1.0; i+=1.0/QUALITY{ + t := imageSrc0UnsafeAt(uv + vec2(cos(d),sin(d))*radius*log(i)).rgb + + brightness := dot(t.rgb, vec3(0.2126, 0.7152, 0.0722)) + if brightness > THRESHOLD { + average += t + amount += 1.0 + } + } + } + + col := imageSrc0UnsafeAt(uv).rgb + if amount > 0 { + col += (average / amount) * OPACITY + } + + return vec4(col,1.0) +} + |