Ported bloom to script

Breaks the parser because we don't support LODs for textures and
framebuffers. Also we need a command for local variables.
This commit is contained in:
Emmanuel BENOîT 2017-11-10 18:28:56 +01:00
parent 46972c7e60
commit 9e583c1374

163
demo.srd
View file

@ -18,12 +18,14 @@
(call scene-init) (call scene-init)
(call dof-init) (call dof-init)
(call bloom-init)
) )
(frame (frame
(profiling "Frame render" (profiling "Frame render"
(call scene-main) (call scene-main)
(call dof-main tx-scene-output tx-scene-depth) (call dof-main tx-scene-output tx-scene-depth)
(call bloom-main tx-scene-output)
) )
) )
@ -44,6 +46,25 @@
(odbg tx-scene-output hdr "Scene output") (odbg tx-scene-output hdr "Scene output")
(odbg tx-scene-depth depth "Scene depth") (odbg tx-scene-depth depth "Scene depth")
(input camera-pos-x 0)
(input camera-pos-y 0)
(input camera-pos-z -5)
(input camera-lookat-x 0)
(input camera-lookat-y 0)
(input camera-lookat-z 0)
(input camera-up-x 0)
(input camera-up-y 1)
(input camera-up-z 0)
(input camera-nearplane 2)
(input raymarcher-iterations 256)
(input raymarcher-step 1.2)
(input raymarcher-epsilon .00001)
(input raymarcher-max-dist 250)
(input raymarcher-correction 10)
(input fog .00015)
) )
(fn scene-main () (fn scene-main ()
@ -67,7 +88,14 @@
(uniforms prg-scene-p1 5 (uniforms prg-scene-p1 5
(get-input camera-nearplane) (get-input camera-nearplane)
) )
# FIXME MOAR UNIFORMS! (uniforms prg-scene-p1 6
(get-input raymarcher-iterations)
(get-input raymarcher-step)
(get-input raymarcher-epsilon)
(get-input raymarcher-max-dist)
)
(uniforms prg-scene-p1 7 (get-input fog))
(uniforms prg-scene-p1 8 (get-input raymarcher-correction))
(use-pipeline pl-scene-p1) (use-pipeline pl-scene-p1)
(use-framebuffer rt-scene) (use-framebuffer rt-scene)
(viewport 0 0 $vp-width $vp-height) (viewport 0 0 $vp-width $vp-height)
@ -163,4 +191,137 @@
) )
) )
################################################################################
# Bloom
(fn bloom-init ()
# Samplers
(sampler smp-bloom-blur
(sampling linear)
(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))
# High pass program
(program prg-bloom-highpass "bloom-highpass.f.glsl")
(pipeline pl-bloom-highpass prg-fullscreen prg-bloom-highpass)
(uniforms-i prg-bloom-highpass 0 0)
(uniforms-i prg-bloom-highpass 1 0)
(uniforms prg-bloom-highpass 2 $vp-width $vp-height)
# Downsampling program
(program prg-bloom-downsample "downsample.f.glsl")
(pipeline pl-bloom-downsample prg-fullscreen prg-bloom-downsample)
(uniforms-i prg-bloom-downsample 0 0)
# Blur pass
(program prg-bloom-blur "blur-pass.f.glsl")
(pipeline pl-bloom-blur prg-fullscreen prg-bloom-blur)
(uniforms-i prg-bloom-blur 0 0)
# Inputs that control the high pass filter
# FIXME I don't remember what they actually do, rename them later
(input bloom-filter0 1.6)
(input bloom-filter1 1.2)
(input bloom-filter2 .95)
# 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)
)
(fn bloom-main (in-scene)
(profiling "BLOOOOM!"
# High pass
(use-texture 0 in-scene smp-bloom-input)
(uniforms prg-bloom-highpass 3
(get-input bloom-filter0)
(get-input bloom-filter1)
(get-input bloom-filter2)
)
(use-framebuffer rt-bloom1-lod0)
(viewport 0 0 $vp-width $vp-height)
(fullscreen)
# Blur & downsample
(uniforms prg-bloom-downsample 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 w h)
(set w (div $vp-width (pow 2 $level)))
(set h (div $vp-height (pow 2 $level)))
(use-pipeline pl-bloom-downsample)
(use-framebuffer target)
(use-texture 0 tx-bloom1 smp-bloom-blur)
(uniforms prg-bloom-downsample 1 $w $h)
(uniforms 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 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 # vim: syntax=demo-srd