(init # Compute viewport size (if (cmp-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 scene-init) (call dof-init) ) (frame (profiling "Frame render" (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) (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") ) (fn scene-main () (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) ) # FIXME MOAR UNIFORMS! (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 dof-sampler (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-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) (viewport 0 0 $vp-width $vp-height) (fullscreen) ) ) # vim: syntax=demo-srd