demotool/demo.srd

555 lines
14 KiB
Text
Raw Normal View History

2017-11-06 10:15:38 +01:00
(init
# Compute viewport size
2017-11-15 23:09:52 +01:00
(locals aspect-ratio)
(set aspect-ratio (div 16 9))
(if (cmp-gt (div $width $aspect-ratio) $height)
(
(set vp-height $height)
2017-11-15 23:09:52 +01:00
(set vp-width (mul $height $aspect-ratio))
)(
(set vp-width $width)
2017-11-15 23:09:52 +01:00
(set vp-height (div $width $aspect-ratio))
)
)
2017-11-12 22:20:11 +01:00
# Viewport location
(set vp-x (div (sub $width $vp-width) 2))
(set vp-y (div (sub $height $vp-height) 2))
(program prg-fullscreen "fullscreen.v.glsl")
(call scene-init)
(call dof-init)
(call bloom-init)
2017-11-10 21:24:47 +01:00
(call combine-init)
(call fxaa-init)
)
2017-11-06 10:15:38 +01:00
(frame
(profiling "Frame render"
2017-11-10 21:24:47 +01:00
(call scene-render)
(call dof-render tx-scene-output tx-scene-depth)
(call bloom-render tx-scene-output)
(call combine-render tx-dof-pass2 tx-bloom1)
(call fxaa-render tx-combined)
)
)
################################################################################
# Scene
(fn scene-init ()
(texture tx-scene-output rgb-f16 $vp-width $vp-height)
(texture tx-scene-depth r-f16 $vp-width $vp-height)
(framebuffer rt-scene
(color tx-scene-output)
(color tx-scene-depth))
(program prg-scene-p1 "scene.f.glsl")
(pipeline pl-scene-p1 prg-fullscreen prg-scene-p1)
2017-11-10 12:48:57 +01:00
(odbg tx-scene-output hdr "Scene output")
(odbg tx-scene-depth depth "Scene depth")
(input camera-pos-x 0)
(input camera-pos-y 0)
(input camera-pos-z 30)
(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)
(ui-overrides
(section "Scenes"
(section "Raymarcher"
(int "Iterations" raymarcher-iterations
(min 1) (max 2048) (step .05))
(float "Step size" raymarcher-step
(min 0) (max 2) (slider))
(float "Epsilon" raymarcher-epsilon
(min 1e-10) (max 1) (power 1)
(decimals 12) (step 1e-8))
(float "Maximal distance" raymarcher-max-dist
(min 1e-2) (max 1000000) (decimals 0)
(step .05))
(int "Correction steps" raymarcher-correction
(min 0) (max 100) (slider))
)
(float "Fog" fog
(min 0) (max 1) (step .000005) (decimals 5))
)
)
)
2017-11-10 21:24:47 +01:00
(fn scene-render ()
(profiling "Scene render"
(uniforms prg-scene-p1 1 $vp-width $vp-height)
(uniforms prg-scene-p1 0 $time)
(uniforms prg-scene-p1 2
(get-input camera-pos-x)
(get-input camera-pos-y)
(get-input camera-pos-z)
)
(uniforms prg-scene-p1 3
(get-input camera-lookat-x)
(get-input camera-lookat-y)
(get-input camera-lookat-z)
)
(uniforms prg-scene-p1 4
(get-input camera-up-x)
(get-input camera-up-y)
(get-input camera-up-z)
)
(uniforms prg-scene-p1 5
(get-input camera-nearplane)
)
(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-i prg-scene-p1 8 (get-input raymarcher-correction))
(use-pipeline pl-scene-p1)
(use-framebuffer rt-scene)
(viewport 0 0 $vp-width $vp-height)
(fullscreen)
)
)
################################################################################
# Depth of Field
(fn dof-init ()
# Sampler used for the inputs
(sampler smp-dof
(mipmaps no)
(wrapping clamp-edge)
(sampling linear)
(lod 0 0)
)
# Texture & RT for pass 1
(texture tx-dof-pass1 rgb-f16 $vp-width $vp-height)
(framebuffer rt-dof-pass1 tx-dof-pass1)
# Texture & RT for pass 2
(texture tx-dof-pass2 rgb-f16 $vp-width $vp-height)
(framebuffer rt-dof-pass2 tx-dof-pass2)
# TODO MAYBE ? (alias tx-dof-output tx-dof-pass2)
# Output debugging
2017-11-10 12:48:57 +01:00
(odbg tx-dof-pass1 hdr "DoF - First pass")
(odbg tx-dof-pass2 hdr "DoF - Output")
# Programs
(program prg-dof-pass1 "dof-pass1.f.glsl")
(program prg-dof-pass2 "dof-pass2.f.glsl")
# Pipelines
(pipeline pl-dof-pass1 prg-fullscreen prg-dof-pass1)
(pipeline pl-dof-pass2 prg-fullscreen prg-dof-pass2)
# Inputs
(input dof-sharp-distance 0)
(input dof-sharp-range 50)
(input dof-falloff 50)
(input dof-max-blur 16)
(input dof-samples 16)
# Input overrides
(ui-overrides
(section "Post-processing"
(section "Depth of Field"
(float "Sharp distance" dof-sharp-distance
(min 0) (max 50000) (step .1))
(float "Sharp range" dof-sharp-range
(min 0) (max 50000) (step .1))
(float "Falloff" dof-falloff
(min 0) (max 50000) (step .1))
(float "Maximum blur" dof-max-blur
(min 1) (max 64) (slider))
2017-11-18 15:17:42 +01:00
(int "Samples" dof-samples
(min 1) (max 64) (slider))
)
)
)
)
(fn dof-set-uniforms (prog)
(uniforms prog 2
(get-input dof-sharp-distance)
(get-input dof-sharp-range)
(get-input dof-falloff)
(get-input dof-max-blur)
)
(uniforms prog 3 (get-input dof-samples))
(uniforms prog 4 $vp-width $vp-height $time)
)
2017-11-10 21:24:47 +01:00
(fn dof-render (in-image in-depth)
(profiling "Depth of Field"
(use-texture 1 in-depth smp-dof)
(uniforms-i prg-dof-pass1 0 0)
(uniforms-i prg-dof-pass1 1 1)
(uniforms-i prg-dof-pass2 0 0)
(uniforms-i prg-dof-pass2 1 1)
# First pass
(call dof-set-uniforms prg-dof-pass1)
(use-texture 0 in-image smp-dof)
(use-pipeline pl-dof-pass1)
(use-framebuffer rt-dof-pass1)
(fullscreen)
# Second pass
(call dof-set-uniforms prg-dof-pass2)
(use-texture 0 tx-dof-pass1 smp-dof)
(use-pipeline pl-dof-pass2)
(use-framebuffer rt-dof-pass2)
(viewport 0 0 $vp-width $vp-height)
(fullscreen)
)
)
2017-11-10 16:01:00 +01:00
################################################################################
# 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))
)
)
)
)
)
2017-11-10 21:24:47 +01:00
(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)
2017-11-10 21:01:35 +01:00
(locals m w h)
(set m (inv (pow 2 $level)))
(set w (mul $vp-width $m))
(set h (mul $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)
)
2017-11-10 21:24:47 +01:00
################################################################################
# Combine
(fn combine-init ()
# Assets
(sampler smp-combine-input (sampling nearest))
(sampler smp-combine-bloom
(sampling linear)
(mipmaps nearest)
(lod 0 100))
2017-11-10 21:24:47 +01:00
(texture tx-combined rgba-nu8 $vp-width $vp-height)
(odbg tx-combined ldr-alpha "Combined output")
(framebuffer rt-combined tx-combined)
(program prg-combine "combine.f.glsl")
(pipeline pl-combine prg-fullscreen prg-combine)
# Bloom parameters
(input bloom-strength .45)
(input bloom-attenuation .3)
# Vignette effect
(input vignette-shape-m 1)
(input vignette-shape-p 8)
(input vignette-shape-r 1)
(input vignette-aspect-ratio .5)
(input vignette-apply-base 0)
(input vignette-apply-max 1)
# Color grading
(input cg-lift-r 0)
(input cg-lift-g 0)
(input cg-lift-b 0)
(input cg-gain-r 1)
(input cg-gain-g 1)
(input cg-gain-b 1)
(input cg-gamma-r 0)
(input cg-gamma-g 0)
(input cg-gamma-b 0)
# Input overrides
(ui-overrides
(section "Post-processing"
(section "Bloom"
(section "Output"
(float "Strength" bloom-strength
(min 0) (max 1) (slider))
(float "Attenuation / level" bloom-attenuation
(min 0) (max 1) (slider))
)
)
(section "Color grading"
(color-grading "Lift"
cg-lift-r cg-lift-g cg-lift-b
(base -.1) (unit .1))
(color-grading "Gain"
cg-gain-r cg-gain-g cg-gain-b
(base 0) (unit 1))
(color-grading "Gamma"
cg-gamma-r cg-gamma-g cg-gamma-b
(base -.9) (unit .9))
)
)
# FIXME: overrides for vignette
)
2017-11-10 21:24:47 +01:00
)
(fn combine-render (in-main in-bloom)
(profiling "Combine"
(uniforms-i prg-combine 0 0)
(uniforms-i prg-combine 1 1)
(uniforms prg-combine 2 $vp-width $vp-height)
2017-11-10 21:24:47 +01:00
(use-pipeline pl-combine)
(use-framebuffer rt-combined)
(use-texture 0 in-main smp-combine-input)
(use-texture 1 in-bloom smp-combine-bloom)
2017-11-10 21:24:47 +01:00
(uniforms prg-combine 3
(get-input bloom-strength)
(get-input bloom-attenuation))
(uniforms prg-combine 4
(get-input vignette-shape-m)
(get-input vignette-shape-p)
(get-input vignette-aspect-ratio)
(get-input vignette-shape-r))
(uniforms prg-combine 5
(get-input vignette-apply-base)
(get-input vignette-apply-max))
(uniforms prg-combine 6
(get-input cg-lift-r)
(get-input cg-lift-g)
(get-input cg-lift-b))
(uniforms prg-combine 7
(get-input cg-gain-r)
(get-input cg-gain-g)
(get-input cg-gain-b))
(uniforms prg-combine 8
(get-input cg-gamma-r)
(get-input cg-gamma-g)
(get-input cg-gamma-b))
(viewport 0 0 $vp-width $vp-height)
2017-11-10 21:24:47 +01:00
(fullscreen)
)
)
################################################################################
# FXAA
(fn fxaa-init ()
(program prg-fxaa "fxaa.f.glsl")
(pipeline pl-fxaa prg-fullscreen prg-fxaa)
(sampler smp-fxaa
(sampling linear)
(wrapping clamp-border))
(input fxaa-subpixel .5)
(input fxaa-et .166)
(input fxaa-et-min .0833)
(ui-overrides
(section "Post-processing"
(section "FXAA"
(float "Sub-pixel quality" fxaa-subpixel
(min 0) (max 1) (slider))
(float "Edge threshold" fxaa-et
(min .063) (max .333) (slider))
(float "Edge threshold min." fxaa-et-min
(min .0312) (max .0833) (decimals 4)
(slider))
)
)
)
)
(fn fxaa-render (in-image)
(profiling "FXAA"
(uniforms-i prg-fxaa 0 0)
2017-11-15 23:09:52 +01:00
(uniforms prg-fxaa 1
$vp-x $vp-y $vp-width $vp-height)
(main-output)
(viewport 0 0 $width $height)
(clear 0 0 0 0)
(use-pipeline pl-fxaa)
(use-texture 0 in-image smp-fxaa)
(uniforms prg-fxaa 2
(get-input fxaa-subpixel)
(get-input fxaa-et)
(get-input fxaa-et-min))
(viewport $vp-x $vp-y $vp-width $vp-height)
(fullscreen)
)
)
2017-11-10 16:01:00 +01:00
# vim: syntax=demo-srd