################################################################################ # Depth of Field (fn dof-init () # Sampler used for the inputs (sampler smp-dof (mipmaps no) (wrapping clamp-edge) (sampling linear) (lod 0 0) ) (if $use-compute ( # Textures for both passes (texture tx-dof-pass1 rgba-f16 $vp-width $vp-height) (texture tx-dof-pass2 rgba-f16 $vp-width $vp-height) # Programs (program prg-dof-pass1 "dof-pass1.c.glsl") (program prg-dof-pass2 "dof-pass2.c.glsl") # Pipelines (pipeline pl-dof-pass1 prg-dof-pass1) (pipeline pl-dof-pass2 prg-dof-pass2) )( # 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) # 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) )) # Output debugging (odbg tx-dof-pass1 hdr "DoF - First pass") (odbg tx-dof-pass2 hdr "DoF - Output") # 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)) (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) ) (fn dof-render (in-image in-depth) (profiling "Depth of Field" (uniforms-i prg-dof-pass1 0 0) (uniforms-i prg-dof-pass2 0 0) (if (not $use-compute) ( (use-texture 1 in-depth smp-dof) (uniforms-i prg-dof-pass1 1 1) (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) (if $use-compute ( (image 0 tx-dof-pass1 0) (compute $vp-width $vp-height 1) )( (use-framebuffer rt-dof-pass1) (viewport 0 0 $vp-width $vp-height) (fullscreen) )) # Second pass (call dof-set-uniforms prg-dof-pass2) (use-texture 0 tx-dof-pass1 smp-dof) (use-pipeline pl-dof-pass2) (if $use-compute ( (image 0 tx-dof-pass2 0) (compute $vp-width $vp-height 1) )( (use-framebuffer rt-dof-pass2) (viewport 0 0 $vp-width $vp-height) (fullscreen) )) ) ) # vim: syntax=demo-srd