Emmanuel BENOîT
3de255aad0
The program is loaded and its init part is run. Many bugs were fixed in the process, including various new bugs in the shaders manager.
440 lines
11 KiB
Text
440 lines
11 KiB
Text
(init
|
|
# Compute viewport size
|
|
(if (cmp-gt $width $height)
|
|
(
|
|
(set vp-height $height)
|
|
(set vp-width (mul $height (div 16 9)))
|
|
)(
|
|
(set vp-width $width)
|
|
(set vp-height (div $width (div 16 9)))
|
|
)
|
|
)
|
|
# 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)
|
|
(call combine-init)
|
|
(call fxaa-init)
|
|
)
|
|
|
|
(frame
|
|
(profiling "Frame render"
|
|
(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")
|
|
(uniforms prg-scene-p1 1 $vp-width $vp-height)
|
|
(pipeline pl-scene-p1 prg-fullscreen prg-scene-p1)
|
|
|
|
(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 -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-render ()
|
|
(profiling "Scene render"
|
|
(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 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
|
|
(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")
|
|
(uniforms-i prg-dof-pass1 0 1)
|
|
(uniforms-i prg-dof-pass1 1 1)
|
|
(uniforms-i prg-dof-pass2 0 1)
|
|
(uniforms-i prg-dof-pass2 1 1)
|
|
|
|
# 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
|
|
{ NOT IMPLEMENTED
|
|
(ui-overrides "Post-processing" "Depth of Field"
|
|
(float dof-sharp-distance (min 0) (max 1000) (step .1))
|
|
(float dof-sharp-range (min 0) (max 500) (step .1))
|
|
(float dof-falloff (min 0) (max 500) (step .1))
|
|
(float dof-max-blur (min 1) (max 64) (step .1))
|
|
(int dof-samples (min 1) (max 64) (step .1))
|
|
)
|
|
}
|
|
)
|
|
|
|
(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)
|
|
)
|
|
|
|
(fn dof-render (in-image in-depth)
|
|
(profiling "Depth of Field"
|
|
(use-texture 1 in-depth smp-dof)
|
|
|
|
# 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)
|
|
)
|
|
)
|
|
|
|
|
|
################################################################################
|
|
# 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-render (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 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 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)
|
|
)
|
|
|
|
|
|
################################################################################
|
|
# Combine
|
|
|
|
(fn combine-init ()
|
|
# Assets
|
|
(sampler smp-combine-input (sampling nearest))
|
|
(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")
|
|
(uniforms-i prg-combine 0 0)
|
|
(uniforms-i prg-combine 1 1)
|
|
(uniforms prg-combine 2 $vp-width $vp-height)
|
|
(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)
|
|
)
|
|
|
|
(fn combine-render (in-main in-bloom)
|
|
(profiling "Combine"
|
|
(use-pipeline pl-combine)
|
|
(use-framebuffer rt-combined)
|
|
(use-texture 0 in-main smp-combine-input)
|
|
(use-texture 1 in-bloom smp-combine-input)
|
|
(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)
|
|
(fullscreen)
|
|
)
|
|
)
|
|
|
|
|
|
################################################################################
|
|
# FXAA
|
|
|
|
(fn fxaa-init ()
|
|
(program prg-fxaa "fxaa.f.glsl")
|
|
(pipeline pl-fxaa prg-fullscreen prg-fxaa)
|
|
(uniforms-i prg-fxaa 0 0)
|
|
(uniforms prg-fxaa 1 $vp-width $vp-height)
|
|
|
|
(sampler smp-fxaa
|
|
(sampling linear)
|
|
(wrapping clamp-border))
|
|
|
|
(input fxaa-subpixel .5)
|
|
(input fxaa-et .166)
|
|
(input fxaa-et-min .0833)
|
|
)
|
|
|
|
(fn fxaa-render (in-image)
|
|
(profiling "FXAA"
|
|
(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)
|
|
)
|
|
)
|
|
|
|
|
|
# vim: syntax=demo-srd
|