demotool/test/fx-bloom.srd

168 lines
4.5 KiB
Text
Raw Normal View History

################################################################################
# Bloom
(fn bloom-init ()
# Samplers
(sampler smp-bloom-blur
(sampling linear)
(mipmaps linear)
(lod 0 100)
(wrapping clamp-edge)
)
(sampler smp-bloom-input
(sampling nearest)
)
# First ping/pong texture & targets
(texture tx-bloom1 rgb-f16 $vp-width $vp-height 6)
(framebuffer rt-bloom1-lod0 (color tx-bloom1 0))
(framebuffer rt-bloom1-lod1 (color tx-bloom1 1))
(framebuffer rt-bloom1-lod2 (color tx-bloom1 2))
(framebuffer rt-bloom1-lod3 (color tx-bloom1 3))
(framebuffer rt-bloom1-lod4 (color tx-bloom1 4))
(framebuffer rt-bloom1-lod5 (color tx-bloom1 5))
(odbg tx-bloom1 hdr "Bloom")
# Second ping/pong texture & targets
(texture tx-bloom2 rgb-f16 $vp-width $vp-height 6)
(framebuffer rt-bloom2-lod0 (color tx-bloom2 0))
(framebuffer rt-bloom2-lod1 (color tx-bloom2 1))
(framebuffer rt-bloom2-lod2 (color tx-bloom2 2))
(framebuffer rt-bloom2-lod3 (color tx-bloom2 3))
(framebuffer rt-bloom2-lod4 (color tx-bloom2 4))
(framebuffer rt-bloom2-lod5 (color tx-bloom2 5))
(odbg tx-bloom2 hdr "Bloom (partial)")
# High pass program
(program prg-bloom-highpass "bloom-highpass.f.glsl")
(pipeline pl-bloom-highpass prg-fullscreen prg-bloom-highpass)
# Downsampling program
(program prg-bloom-downsample "downsample.f.glsl")
(pipeline pl-bloom-downsample prg-fullscreen prg-bloom-downsample)
# Blur pass
(program prg-bloom-blur "blur-pass.f.glsl")
(pipeline pl-bloom-blur prg-fullscreen prg-bloom-blur)
# Inputs that control the high pass filter
(input bloom-power 1.6)
(input bloom-factor 1.2)
(input bloom-output-factor 1.05)
# Inputs that control the blur weights
(input bloom-bw0 .324)
(input bloom-bw1 .232)
(input bloom-bw2 .0855)
(input bloom-bw3 .0205)
# Blur size
(input bloom-blur-size 1.3)
# Input overrides
(ui-overrides
(section "Post-processing"
(section "Bloom"
(section "Input filter"
(float "Input power" bloom-power
(min .5) (max 4) (slider))
(float "Input factor" bloom-factor
(min .5) (max 4) (slider))
(float "Output factor" bloom-output-factor
(min .5) (max 4) (slider))
)
(section "Blur"
(float "Size" bloom-blur-size
(min .5) (max 4) (slider))
(float4 "Weights"
bloom-bw0 bloom-bw1 bloom-bw2 bloom-bw3
(min 0) (max 1) (step .00005))
)
)
)
)
)
(fn bloom-render (in-scene)
(profiling "BLOOOOM!"
(uniforms-i prg-bloom-highpass 0 0)
(uniforms-i prg-bloom-highpass 1 0)
(uniforms prg-bloom-highpass 2 $vp-width $vp-height)
(uniforms-i prg-bloom-downsample 0 0)
(uniforms-i prg-bloom-blur 0 0)
# High pass
(use-texture 0 in-scene smp-bloom-input)
(uniforms prg-bloom-highpass 3
(get-input bloom-power)
(get-input bloom-factor)
(get-input bloom-output-factor)
)
(use-framebuffer rt-bloom1-lod0)
(use-pipeline pl-bloom-highpass)
(viewport 0 0 $vp-width $vp-height)
(fullscreen)
# Set up blur weights
(uniforms prg-bloom-blur 4
(get-input bloom-bw0)
(get-input bloom-bw1)
(get-input bloom-bw2)
(get-input bloom-bw3))
# Blur & downsample
(uniforms prg-bloom-blur 1 $vp-width $vp-height)
(call bloom-blur-pass 0 rt-bloom1-lod0 rt-bloom2-lod0)
(call bloom-downsample rt-bloom1-lod1 1)
(call bloom-blur-pass 1 rt-bloom1-lod1 rt-bloom2-lod1)
(call bloom-downsample rt-bloom1-lod2 2)
(call bloom-blur-pass 2 rt-bloom1-lod2 rt-bloom2-lod2)
(call bloom-downsample rt-bloom1-lod3 3)
(call bloom-blur-pass 3 rt-bloom1-lod3 rt-bloom2-lod3)
(call bloom-downsample rt-bloom1-lod4 4)
(call bloom-blur-pass 4 rt-bloom1-lod4 rt-bloom2-lod4)
(call bloom-downsample rt-bloom1-lod5 5)
(call bloom-blur-pass 5 rt-bloom1-lod5 rt-bloom2-lod5)
)
)
(fn bloom-downsample (target level)
(locals m w h)
(set m (pow 2 $level))
(set w (div $vp-width $m))
(set h (div $vp-height $m))
(use-pipeline pl-bloom-downsample)
(use-framebuffer target)
(use-texture 0 tx-bloom1 smp-bloom-blur)
(uniforms prg-bloom-downsample 1 $w $h)
(uniforms-i prg-bloom-downsample 2 (sub $level 1))
(viewport 0 0 $w $h)
(fullscreen)
(uniforms prg-bloom-blur 1 $w $h)
)
(fn bloom-blur-pass (lod fb1 fb2)
# Common stuff for both passes
(use-pipeline pl-bloom-blur)
(uniforms-i prg-bloom-blur 2 $lod)
# Pass 1
(use-framebuffer fb2)
(use-texture 0 tx-bloom1 smp-bloom-blur)
(uniforms prg-bloom-blur 3
(get-input bloom-blur-size) 0)
(fullscreen)
# Pass 2
(use-framebuffer fb1)
(use-texture 0 tx-bloom2 smp-bloom-blur)
(uniforms prg-bloom-blur 3
0 (get-input bloom-blur-size))
(fullscreen)
)
# vim: syntax=demo-srd