2017-11-06 10:15:38 +01:00
|
|
|
(init
|
2017-11-05 23:26:36 +01:00
|
|
|
# Compute viewport size
|
2017-11-09 18:24:39 +01:00
|
|
|
(if (cmp-gt width height)
|
2017-11-05 23:26:36 +01:00
|
|
|
(
|
2017-11-09 18:24:39 +01:00
|
|
|
(set vp-height $height)
|
|
|
|
(set vp-width (mul $height (div 16 9)))
|
|
|
|
(set vp-x (div (sub $width $vp-width) 2))
|
2017-11-05 23:26:36 +01:00
|
|
|
(set vp-y 0)
|
|
|
|
)(
|
2017-11-09 18:24:39 +01:00
|
|
|
(set vp-width $width)
|
|
|
|
(set vp-height (div $width (div 16 9)))
|
|
|
|
(set vp-y (div (sub $height $vp-height) 2))
|
2017-11-05 23:26:36 +01:00
|
|
|
(set vp-x 0)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
(program prg-fullscreen "fullscreen.v.glsl")
|
2017-11-09 18:24:39 +01:00
|
|
|
|
|
|
|
(call scene-init)
|
2017-11-05 23:26:36 +01:00
|
|
|
(call dof-init)
|
|
|
|
)
|
|
|
|
|
2017-11-06 10:15:38 +01:00
|
|
|
(frame
|
2017-11-05 23:26:36 +01:00
|
|
|
(profiling "Frame render"
|
2017-11-09 18:24:39 +01:00
|
|
|
(call scene-main)
|
|
|
|
(call dof-main tx-scene-output tx-scene-depth)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# Scene
|
|
|
|
|
|
|
|
(fn scene-init ()
|
|
|
|
(texture tx-scene-output rgb-f16 vp-width vp-height)
|
|
|
|
(texture tx-scene-depth r-f16 vp-width vp-height)
|
2017-11-10 10:15:56 +01:00
|
|
|
(framebuffer rt-scene
|
|
|
|
(color tx-scene-output)
|
|
|
|
(color tx-scene-depth))
|
2017-11-09 18:24:39 +01:00
|
|
|
|
|
|
|
(program prg-scene-p1 "scene.f.glsl")
|
2017-11-09 23:20:48 +01:00
|
|
|
(uniforms prg-scene-p1 1 $vp-width $vp-height)
|
2017-11-09 18:24:39 +01:00
|
|
|
(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")
|
2017-11-09 18:24:39 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
(fn scene-main ()
|
|
|
|
(profiling "Scene render"
|
2017-11-09 23:20:48 +01:00
|
|
|
(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)
|
|
|
|
)
|
|
|
|
# FIXME MOAR UNIFORMS!
|
|
|
|
(use-pipeline pl-scene-p1)
|
|
|
|
(use-framebuffer rt-scene)
|
2017-11-09 18:24:39 +01:00
|
|
|
(viewport 0 0 $vp-width $vp-height)
|
|
|
|
(fullscreen)
|
2017-11-05 23:26:36 +01:00
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# Depth of Field
|
|
|
|
|
|
|
|
(fn dof-init ()
|
|
|
|
# Sampler used for the inputs
|
2017-11-09 18:24:39 +01:00
|
|
|
{ NOT IMPLEMENTED
|
|
|
|
(sampler dof-sampler
|
|
|
|
(mipmaps no)
|
|
|
|
(wrapping clamp-edge)
|
|
|
|
(sampling linear)
|
|
|
|
(lod 0 0)
|
|
|
|
)
|
|
|
|
}
|
2017-11-05 23:26:36 +01:00
|
|
|
|
|
|
|
# Texture & RT for pass 1
|
|
|
|
(texture tx-dof-pass1 rgb-f16 vp-width vp-height)
|
2017-11-10 10:15:56 +01:00
|
|
|
(framebuffer rt-dof-pass1 tx-dof-pass1)
|
2017-11-05 23:26:36 +01:00
|
|
|
|
|
|
|
# Texture & RT for pass 2
|
|
|
|
(texture tx-dof-pass2 rgb-f16 vp-width vp-height)
|
2017-11-10 10:15:56 +01:00
|
|
|
(framebuffer rt-dof-pass2 tx-dof-pass2)
|
2017-11-09 18:24:39 +01:00
|
|
|
# MAYBE ? (alias tx-dof-output tx-dof-pass2)
|
2017-11-05 23:26:36 +01:00
|
|
|
|
|
|
|
# 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")
|
2017-11-05 23:26:36 +01:00
|
|
|
|
|
|
|
# Programs
|
|
|
|
(program prg-dof-pass1 "dof-pass1.f.glsl")
|
|
|
|
(program prg-dof-pass2 "dof-pass2.f.glsl")
|
2017-11-09 23:20:48 +01:00
|
|
|
(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)
|
2017-11-05 23:26:36 +01:00
|
|
|
|
|
|
|
# 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
|
2017-11-09 18:24:39 +01:00
|
|
|
{ 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))
|
|
|
|
)
|
|
|
|
}
|
2017-11-05 23:26:36 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
(fn dof-set-uniforms (prog)
|
2017-11-09 23:20:48 +01:00
|
|
|
(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-05 23:26:36 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
(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)
|
2017-11-09 18:24:39 +01:00
|
|
|
|
2017-11-05 23:26:36 +01:00
|
|
|
(use-pipeline pl-dof-pass2)
|
|
|
|
(use-framebuffer rt-dof-pass2)
|
2017-11-09 18:24:39 +01:00
|
|
|
(viewport 0 0 $vp-width $vp-height)
|
2017-11-05 23:26:36 +01:00
|
|
|
(fullscreen)
|
|
|
|
)
|
|
|
|
)
|
2017-11-10 16:01:00 +01:00
|
|
|
|
|
|
|
# vim: syntax=demo-srd
|