2017-11-06 10:15:38 +01:00
|
|
|
(init
|
2017-11-05 23:26:36 +01:00
|
|
|
# Compute viewport size
|
|
|
|
(if (gt width height)
|
|
|
|
(
|
|
|
|
(set vp-height height)
|
|
|
|
(set vp-width (mul height (div 16 9)))
|
|
|
|
(set vp-x (div (sub width vp-width) 2))
|
|
|
|
(set vp-y 0)
|
|
|
|
)(
|
|
|
|
(set vp-width width)
|
|
|
|
(set vp-height (div width (div 16 9)))
|
|
|
|
(set vp-y (div (sub height vp-height) 2))
|
|
|
|
(set vp-x 0)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
(program prg-fullscreen "fullscreen.v.glsl")
|
|
|
|
(call dof-init)
|
|
|
|
)
|
|
|
|
|
2017-11-06 10:15:38 +01:00
|
|
|
(frame
|
2017-11-05 23:26:36 +01:00
|
|
|
(profiling "Frame render"
|
|
|
|
{ FIXME: other stages }
|
|
|
|
(call dof-main { FIXME: args here })
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# Depth of Field
|
|
|
|
|
|
|
|
(fn dof-init ()
|
|
|
|
# Sampler used for the inputs
|
|
|
|
(sampler dof-sampler
|
|
|
|
(mipmaps no)
|
2017-11-06 14:06:21 +01:00
|
|
|
(wrapping clamp-edge)
|
2017-11-05 23:26:36 +01:00
|
|
|
(sampling linear)
|
|
|
|
(lod 0 0)
|
|
|
|
)
|
|
|
|
|
|
|
|
# Texture & RT for pass 1
|
|
|
|
(texture tx-dof-pass1 rgb-f16 vp-width vp-height)
|
|
|
|
(framebuffer rt-dof-pass1 (colors tx-dof-pass1))
|
|
|
|
|
|
|
|
# Texture & RT for pass 2
|
|
|
|
(texture tx-dof-pass2 rgb-f16 vp-width vp-height)
|
|
|
|
(framebuffer rt-dof-pass2 (colors tx-dof-pass2))
|
|
|
|
(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")
|
|
|
|
(set-uniforms-integer prg-dof-pass1 0 1)
|
|
|
|
(set-uniforms-integer prg-dof-pass1 1 1)
|
|
|
|
(set-uniforms-integer prg-dof-pass2 0 1)
|
|
|
|
(set-uniforms-integer 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
|
|
|
|
(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)
|
|
|
|
(set-uniforms prog 2 (
|
|
|
|
(get-input dof-sharp-distance)
|
|
|
|
(get-input dof-sharp-range)
|
|
|
|
(get-input dof-falloff)
|
|
|
|
(get-input dof-max-blur)
|
|
|
|
))
|
2017-11-06 10:56:19 +01:00
|
|
|
(set-uniforms prog 3 ((get-input dof-samples)))
|
2017-11-05 23:26:36 +01:00
|
|
|
(set-uniforms prog 4 (vp-width vp-height time))
|
|
|
|
)
|
|
|
|
|
|
|
|
(fn dof-main (in-image in-depth)
|
|
|
|
(profiling "Depth of Field"
|
|
|
|
(use-texture 1 in-depth dof-sampler)
|
|
|
|
|
|
|
|
# First pass
|
|
|
|
(call dof-set-uniforms prg-dof-pass1)
|
|
|
|
(use-texture 0 in-image dof-sampler)
|
|
|
|
(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 dof-sampler)
|
|
|
|
(use-pipeline pl-dof-pass2)
|
|
|
|
(use-framebuffer rt-dof-pass2)
|
|
|
|
(fullscreen)
|
|
|
|
)
|
|
|
|
)
|