2017-11-06 10:15:38 +01:00
|
|
|
(init
|
2017-11-05 23:26:36 +01:00
|
|
|
# Compute viewport size
|
2017-11-15 23:09:52 +01:00
|
|
|
(locals aspect-ratio)
|
|
|
|
(set aspect-ratio (div 16 9))
|
|
|
|
(if (cmp-gt (div $width $aspect-ratio) $height)
|
2017-11-05 23:26:36 +01:00
|
|
|
(
|
2017-11-09 18:24:39 +01:00
|
|
|
(set vp-height $height)
|
2017-11-15 23:09:52 +01:00
|
|
|
(set vp-width (mul $height $aspect-ratio))
|
2017-11-05 23:26:36 +01:00
|
|
|
)(
|
2017-11-09 18:24:39 +01:00
|
|
|
(set vp-width $width)
|
2017-11-15 23:09:52 +01:00
|
|
|
(set vp-height (div $width $aspect-ratio))
|
2017-11-05 23:26:36 +01:00
|
|
|
)
|
|
|
|
)
|
2017-11-12 22:20:11 +01:00
|
|
|
# Viewport location
|
|
|
|
(set vp-x (div (sub $width $vp-width) 2))
|
|
|
|
(set vp-y (div (sub $height $vp-height) 2))
|
2017-11-05 23:26:36 +01:00
|
|
|
|
|
|
|
(program prg-fullscreen "fullscreen.v.glsl")
|
2017-11-09 18:24:39 +01:00
|
|
|
|
2017-12-24 11:40:06 +01:00
|
|
|
(set use-compute 1)
|
2017-12-25 10:12:17 +01:00
|
|
|
|
2017-11-09 18:24:39 +01:00
|
|
|
(call scene-init)
|
2017-11-05 23:26:36 +01:00
|
|
|
(call dof-init)
|
2017-11-10 18:28:56 +01:00
|
|
|
(call bloom-init)
|
2017-11-10 21:24:47 +01:00
|
|
|
(call combine-init)
|
2017-11-10 21:46:15 +01:00
|
|
|
(call fxaa-init)
|
2017-11-05 23:26:36 +01:00
|
|
|
)
|
|
|
|
|
2017-11-06 10:15:38 +01:00
|
|
|
(frame
|
2017-11-05 23:26:36 +01:00
|
|
|
(profiling "Frame render"
|
2017-11-10 21:24:47 +01:00
|
|
|
(call scene-render)
|
2017-12-25 18:41:16 +01:00
|
|
|
(if $use-compute (
|
|
|
|
(call dof-render tx-scene-output tx-scene-output)
|
|
|
|
)(
|
|
|
|
(call dof-render tx-scene-output tx-scene-depth)
|
|
|
|
))
|
2017-11-10 21:24:47 +01:00
|
|
|
(call bloom-render tx-scene-output)
|
|
|
|
(call combine-render tx-dof-pass2 tx-bloom1)
|
2017-11-10 21:46:15 +01:00
|
|
|
(call fxaa-render tx-combined)
|
2017-11-09 18:24:39 +01:00
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# Scene
|
|
|
|
|
|
|
|
(fn scene-init ()
|
2017-11-14 22:04:00 +01:00
|
|
|
(texture tx-scene-depth r-f16 $vp-width $vp-height)
|
2017-12-25 10:12:17 +01:00
|
|
|
(if $use-compute (
|
|
|
|
(texture tx-scene-output rgba-f16 $vp-width $vp-height)
|
2017-11-09 18:24:39 +01:00
|
|
|
|
2017-12-25 10:12:17 +01:00
|
|
|
(program prg-scene-p1 "scene.c.glsl")
|
|
|
|
(pipeline pl-scene-p1 prg-scene-p1)
|
|
|
|
)(
|
|
|
|
(texture tx-scene-output rgb-f16 $vp-width $vp-height)
|
|
|
|
|
|
|
|
(framebuffer rt-scene
|
|
|
|
(color tx-scene-output)
|
|
|
|
(color tx-scene-depth))
|
|
|
|
|
|
|
|
(program prg-scene-p1 "scene.f.glsl")
|
|
|
|
(pipeline pl-scene-p1 prg-fullscreen prg-scene-p1)
|
|
|
|
))
|
2017-11-09 18:24:39 +01:00
|
|
|
|
2017-11-10 12:48:57 +01:00
|
|
|
(odbg tx-scene-output hdr "Scene output")
|
|
|
|
(odbg tx-scene-depth depth "Scene depth")
|
2017-11-10 18:28:56 +01:00
|
|
|
|
|
|
|
(input camera-pos-x 0)
|
|
|
|
(input camera-pos-y 0)
|
2017-11-15 09:46:07 +01:00
|
|
|
(input camera-pos-z 30)
|
2017-11-10 18:28:56 +01:00
|
|
|
(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)
|
2017-11-19 08:51:23 +01:00
|
|
|
|
|
|
|
(ui-overrides
|
|
|
|
(section "Scenes"
|
|
|
|
(section "Raymarcher"
|
|
|
|
(int "Iterations" raymarcher-iterations
|
|
|
|
(min 1) (max 2048) (step .05))
|
|
|
|
(float "Step size" raymarcher-step
|
|
|
|
(min 0) (max 2) (slider))
|
|
|
|
(float "Epsilon" raymarcher-epsilon
|
|
|
|
(min 1e-10) (max 1) (power 1)
|
|
|
|
(decimals 12) (step 1e-8))
|
|
|
|
(float "Maximal distance" raymarcher-max-dist
|
|
|
|
(min 1e-2) (max 1000000) (decimals 0)
|
|
|
|
(step .05))
|
|
|
|
(int "Correction steps" raymarcher-correction
|
|
|
|
(min 0) (max 100) (slider))
|
|
|
|
)
|
2017-11-20 10:05:09 +01:00
|
|
|
(camera "Camera"
|
|
|
|
(near-plane camera-nearplane)
|
|
|
|
(position camera-pos-x camera-pos-y camera-pos-z)
|
|
|
|
(up camera-up-x camera-up-y camera-up-z)
|
|
|
|
(look-at camera-lookat-x camera-lookat-y camera-lookat-z))
|
2017-11-19 08:51:23 +01:00
|
|
|
(float "Fog" fog
|
|
|
|
(min 0) (max 1) (step .000005) (decimals 5))
|
|
|
|
)
|
|
|
|
)
|
2017-11-09 18:24:39 +01:00
|
|
|
)
|
|
|
|
|
2017-11-10 21:24:47 +01:00
|
|
|
(fn scene-render ()
|
2017-11-09 18:24:39 +01:00
|
|
|
(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)
|
|
|
|
)
|
2017-11-10 18:28:56 +01:00
|
|
|
(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))
|
2017-11-14 23:44:13 +01:00
|
|
|
(uniforms-i prg-scene-p1 8 (get-input raymarcher-correction))
|
2017-11-09 23:20:48 +01:00
|
|
|
(use-pipeline pl-scene-p1)
|
2017-12-25 10:12:17 +01:00
|
|
|
(if $use-compute (
|
|
|
|
(image 0 tx-scene-output 0)
|
2017-12-25 20:39:56 +01:00
|
|
|
(compute $vp-width $vp-height 1)
|
2017-12-25 10:12:17 +01:00
|
|
|
)(
|
|
|
|
(uniforms prg-scene-p1 1 $vp-width $vp-height)
|
|
|
|
(use-framebuffer rt-scene)
|
|
|
|
(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-11 16:53:21 +01:00
|
|
|
(sampler smp-dof
|
2017-11-10 17:18:29 +01:00
|
|
|
(mipmaps no)
|
|
|
|
(wrapping clamp-edge)
|
|
|
|
(sampling linear)
|
|
|
|
(lod 0 0)
|
|
|
|
)
|
2017-11-05 23:26:36 +01:00
|
|
|
|
2017-12-25 18:41:16 +01:00
|
|
|
(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")
|
2017-11-05 23:26:36 +01:00
|
|
|
|
2017-12-25 18:41:16 +01:00
|
|
|
# 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)
|
|
|
|
))
|
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
|
|
|
|
|
|
|
# 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-17 14:09:36 +01:00
|
|
|
(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))
|
2017-11-18 15:17:42 +01:00
|
|
|
(int "Samples" dof-samples
|
|
|
|
(min 1) (max 64) (slider))
|
2017-11-16 12:20:21 +01:00
|
|
|
)
|
2017-11-09 18:24:39 +01:00
|
|
|
)
|
2017-11-17 14:09:36 +01:00
|
|
|
)
|
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
|
|
|
)
|
|
|
|
|
2017-11-10 21:24:47 +01:00
|
|
|
(fn dof-render (in-image in-depth)
|
2017-11-05 23:26:36 +01:00
|
|
|
(profiling "Depth of Field"
|
2017-11-15 09:46:07 +01:00
|
|
|
(uniforms-i prg-dof-pass1 0 0)
|
|
|
|
(uniforms-i prg-dof-pass2 0 0)
|
2017-12-25 18:41:16 +01:00
|
|
|
|
2017-12-25 20:39:56 +01:00
|
|
|
(if (not $use-compute) (
|
2017-12-25 18:41:16 +01:00
|
|
|
(use-texture 1 in-depth smp-dof)
|
|
|
|
(uniforms-i prg-dof-pass1 1 1)
|
|
|
|
(uniforms-i prg-dof-pass2 1 1)
|
|
|
|
))
|
2017-11-15 09:46:07 +01:00
|
|
|
|
2017-11-05 23:26:36 +01:00
|
|
|
# First pass
|
|
|
|
(call dof-set-uniforms prg-dof-pass1)
|
2017-11-11 16:53:21 +01:00
|
|
|
(use-texture 0 in-image smp-dof)
|
2017-11-05 23:26:36 +01:00
|
|
|
(use-pipeline pl-dof-pass1)
|
2017-12-25 18:41:16 +01:00
|
|
|
(if $use-compute (
|
|
|
|
(image 0 tx-dof-pass1 0)
|
2017-12-25 20:39:56 +01:00
|
|
|
(compute $vp-width $vp-height 1)
|
2017-12-25 18:41:16 +01:00
|
|
|
)(
|
|
|
|
(use-framebuffer rt-dof-pass1)
|
|
|
|
(viewport 0 0 $vp-width $vp-height)
|
|
|
|
(fullscreen)
|
|
|
|
))
|
2017-11-05 23:26:36 +01:00
|
|
|
|
|
|
|
# Second pass
|
|
|
|
(call dof-set-uniforms prg-dof-pass2)
|
2017-11-11 16:53:21 +01:00
|
|
|
(use-texture 0 tx-dof-pass1 smp-dof)
|
2017-11-05 23:26:36 +01:00
|
|
|
(use-pipeline pl-dof-pass2)
|
2017-12-25 18:41:16 +01:00
|
|
|
(if $use-compute (
|
|
|
|
(image 0 tx-dof-pass2 0)
|
2017-12-25 20:39:56 +01:00
|
|
|
(compute $vp-width $vp-height 1)
|
2017-12-25 18:41:16 +01:00
|
|
|
)(
|
|
|
|
(use-framebuffer rt-dof-pass2)
|
|
|
|
(viewport 0 0 $vp-width $vp-height)
|
|
|
|
(fullscreen)
|
|
|
|
))
|
2017-11-05 23:26:36 +01:00
|
|
|
)
|
|
|
|
)
|
2017-11-10 16:01:00 +01:00
|
|
|
|
2017-11-10 18:28:56 +01:00
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# Bloom
|
|
|
|
|
|
|
|
(fn bloom-init ()
|
|
|
|
# Samplers
|
|
|
|
(sampler smp-bloom-blur
|
|
|
|
(sampling linear)
|
2017-11-15 09:46:07 +01:00
|
|
|
(mipmaps linear)
|
|
|
|
(lod 0 100)
|
2017-11-10 18:28:56 +01:00
|
|
|
(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))
|
2017-11-15 09:46:07 +01:00
|
|
|
(odbg tx-bloom2 hdr "Bloom (partial)")
|
2017-11-10 18:28:56 +01:00
|
|
|
|
|
|
|
# High pass program
|
|
|
|
(program prg-bloom-highpass "bloom-highpass.f.glsl")
|
|
|
|
(pipeline pl-bloom-highpass prg-fullscreen prg-bloom-highpass)
|
|
|
|
|
|
|
|
# Downsampling program
|
|
|
|
(program prg-bloom-downsample "downsample.f.glsl")
|
|
|
|
(pipeline pl-bloom-downsample prg-fullscreen prg-bloom-downsample)
|
|
|
|
|
|
|
|
# Blur pass
|
|
|
|
(program prg-bloom-blur "blur-pass.f.glsl")
|
|
|
|
(pipeline pl-bloom-blur prg-fullscreen prg-bloom-blur)
|
|
|
|
|
|
|
|
# Inputs that control the high pass filter
|
2017-11-18 16:13:07 +01:00
|
|
|
(input bloom-power 1.6)
|
|
|
|
(input bloom-factor 1.2)
|
|
|
|
(input bloom-output-factor 1.05)
|
2017-11-10 18:28:56 +01:00
|
|
|
|
|
|
|
# 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)
|
2017-11-18 16:13:07 +01:00
|
|
|
|
|
|
|
# Input overrides
|
|
|
|
(ui-overrides
|
|
|
|
(section "Post-processing"
|
|
|
|
(section "Bloom"
|
|
|
|
(section "Input filter"
|
|
|
|
(float "Input power" bloom-power
|
|
|
|
(min .5) (max 4) (slider))
|
|
|
|
(float "Input factor" bloom-factor
|
|
|
|
(min .5) (max 4) (slider))
|
|
|
|
(float "Output factor" bloom-output-factor
|
|
|
|
(min .5) (max 4) (slider))
|
|
|
|
)
|
|
|
|
(section "Blur"
|
|
|
|
(float "Size" bloom-blur-size
|
|
|
|
(min .5) (max 4) (slider))
|
|
|
|
(float4 "Weights"
|
|
|
|
bloom-bw0 bloom-bw1 bloom-bw2 bloom-bw3
|
|
|
|
(min 0) (max 1) (step .00005))
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
2017-11-10 18:28:56 +01:00
|
|
|
)
|
|
|
|
|
2017-11-10 21:24:47 +01:00
|
|
|
(fn bloom-render (in-scene)
|
2017-11-10 18:28:56 +01:00
|
|
|
(profiling "BLOOOOM!"
|
2017-11-15 09:46:07 +01:00
|
|
|
(uniforms-i prg-bloom-highpass 0 0)
|
|
|
|
(uniforms-i prg-bloom-highpass 1 0)
|
|
|
|
(uniforms prg-bloom-highpass 2 $vp-width $vp-height)
|
|
|
|
(uniforms-i prg-bloom-downsample 0 0)
|
|
|
|
(uniforms-i prg-bloom-blur 0 0)
|
|
|
|
|
2017-11-10 18:28:56 +01:00
|
|
|
# High pass
|
|
|
|
(use-texture 0 in-scene smp-bloom-input)
|
|
|
|
(uniforms prg-bloom-highpass 3
|
2017-11-18 16:13:07 +01:00
|
|
|
(get-input bloom-power)
|
|
|
|
(get-input bloom-factor)
|
|
|
|
(get-input bloom-output-factor)
|
2017-11-10 18:28:56 +01:00
|
|
|
)
|
|
|
|
(use-framebuffer rt-bloom1-lod0)
|
2017-11-18 16:13:07 +01:00
|
|
|
(use-pipeline pl-bloom-highpass)
|
2017-11-10 18:28:56 +01:00
|
|
|
(viewport 0 0 $vp-width $vp-height)
|
|
|
|
(fullscreen)
|
|
|
|
|
2017-11-15 09:46:07 +01:00
|
|
|
# Set up blur weights
|
|
|
|
(uniforms prg-bloom-blur 4
|
|
|
|
(get-input bloom-bw0)
|
|
|
|
(get-input bloom-bw1)
|
|
|
|
(get-input bloom-bw2)
|
|
|
|
(get-input bloom-bw3))
|
|
|
|
|
2017-11-10 18:28:56 +01:00
|
|
|
# Blur & downsample
|
2017-11-15 09:46:07 +01:00
|
|
|
(uniforms prg-bloom-blur 1 $vp-width $vp-height)
|
2017-11-10 18:28:56 +01:00
|
|
|
(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)
|
2017-11-10 21:01:35 +01:00
|
|
|
(locals m w h)
|
2017-12-17 15:59:29 +01:00
|
|
|
(set m (pow 2 $level))
|
|
|
|
(set w (div $vp-width $m))
|
|
|
|
(set h (div $vp-height $m))
|
2017-11-10 18:28:56 +01:00
|
|
|
|
|
|
|
(use-pipeline pl-bloom-downsample)
|
|
|
|
(use-framebuffer target)
|
|
|
|
(use-texture 0 tx-bloom1 smp-bloom-blur)
|
|
|
|
(uniforms prg-bloom-downsample 1 $w $h)
|
2017-11-14 23:44:13 +01:00
|
|
|
(uniforms-i prg-bloom-downsample 2 (sub $level 1))
|
2017-11-10 18:28:56 +01:00
|
|
|
(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)
|
2017-11-14 23:44:13 +01:00
|
|
|
(uniforms-i prg-bloom-blur 2 $lod)
|
2017-11-10 18:28:56 +01:00
|
|
|
|
|
|
|
# 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)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2017-11-10 21:24:47 +01:00
|
|
|
################################################################################
|
|
|
|
# Combine
|
|
|
|
|
|
|
|
(fn combine-init ()
|
|
|
|
# Assets
|
|
|
|
(sampler smp-combine-input (sampling nearest))
|
2017-11-15 09:46:07 +01:00
|
|
|
(sampler smp-combine-bloom
|
|
|
|
(sampling linear)
|
|
|
|
(mipmaps nearest)
|
|
|
|
(lod 0 100))
|
2017-11-10 21:24:47 +01:00
|
|
|
(texture tx-combined rgba-nu8 $vp-width $vp-height)
|
|
|
|
(odbg tx-combined ldr-alpha "Combined output")
|
2017-12-24 11:40:06 +01:00
|
|
|
(if $use-compute (
|
|
|
|
(program prg-combine "combine.c.glsl")
|
|
|
|
(pipeline pl-combine prg-combine)
|
|
|
|
)(
|
|
|
|
(framebuffer rt-combined tx-combined)
|
|
|
|
(program prg-combine "combine.f.glsl")
|
|
|
|
(pipeline pl-combine prg-fullscreen prg-combine)
|
|
|
|
))
|
2017-11-10 21:24:47 +01:00
|
|
|
|
|
|
|
# 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)
|
2017-11-18 16:13:07 +01:00
|
|
|
|
|
|
|
# Input overrides
|
|
|
|
(ui-overrides
|
|
|
|
(section "Post-processing"
|
|
|
|
(section "Bloom"
|
|
|
|
(section "Output"
|
|
|
|
(float "Strength" bloom-strength
|
|
|
|
(min 0) (max 1) (slider))
|
|
|
|
(float "Attenuation / level" bloom-attenuation
|
|
|
|
(min 0) (max 1) (slider))
|
|
|
|
)
|
|
|
|
)
|
2017-11-19 21:54:13 +01:00
|
|
|
|
|
|
|
(section "Color grading"
|
|
|
|
(color-grading "Lift"
|
|
|
|
cg-lift-r cg-lift-g cg-lift-b
|
2017-11-19 22:59:41 +01:00
|
|
|
(base -.1) (unit .1))
|
2017-11-19 21:54:13 +01:00
|
|
|
(color-grading "Gain"
|
|
|
|
cg-gain-r cg-gain-g cg-gain-b
|
|
|
|
(base 0) (unit 1))
|
|
|
|
(color-grading "Gamma"
|
|
|
|
cg-gamma-r cg-gamma-g cg-gamma-b
|
2017-11-19 22:59:41 +01:00
|
|
|
(base -.9) (unit .9))
|
2017-11-19 21:54:13 +01:00
|
|
|
)
|
2017-11-18 16:13:07 +01:00
|
|
|
)
|
2017-11-19 10:21:08 +01:00
|
|
|
# FIXME: overrides for vignette
|
2017-11-18 16:13:07 +01:00
|
|
|
)
|
2017-11-10 21:24:47 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
(fn combine-render (in-main in-bloom)
|
|
|
|
(profiling "Combine"
|
2017-11-15 09:46:07 +01:00
|
|
|
(uniforms-i prg-combine 0 0)
|
|
|
|
(uniforms-i prg-combine 1 1)
|
|
|
|
|
2017-11-10 21:24:47 +01:00
|
|
|
(use-pipeline pl-combine)
|
2017-12-24 11:40:06 +01:00
|
|
|
(if (not $use-compute) (
|
2017-12-24 13:16:07 +01:00
|
|
|
(uniforms prg-combine 2 $vp-width $vp-height)
|
2017-12-24 11:40:06 +01:00
|
|
|
(use-framebuffer rt-combined)
|
|
|
|
))
|
2017-11-10 21:24:47 +01:00
|
|
|
(use-texture 0 in-main smp-combine-input)
|
2017-11-15 09:46:07 +01:00
|
|
|
(use-texture 1 in-bloom smp-combine-bloom)
|
2017-11-10 21:24:47 +01:00
|
|
|
(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))
|
2017-12-24 11:40:06 +01:00
|
|
|
|
|
|
|
(if $use-compute (
|
|
|
|
(image 0 tx-combined 0)
|
2017-12-25 20:39:56 +01:00
|
|
|
(compute $vp-width $vp-height 1)
|
2017-12-24 11:40:06 +01:00
|
|
|
)(
|
|
|
|
(viewport 0 0 $vp-width $vp-height)
|
|
|
|
(fullscreen)
|
|
|
|
))
|
2017-11-10 21:24:47 +01:00
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2017-11-10 21:46:15 +01:00
|
|
|
################################################################################
|
|
|
|
# FXAA
|
|
|
|
|
|
|
|
(fn fxaa-init ()
|
|
|
|
(program prg-fxaa "fxaa.f.glsl")
|
|
|
|
(pipeline pl-fxaa prg-fullscreen prg-fxaa)
|
|
|
|
|
|
|
|
(sampler smp-fxaa
|
|
|
|
(sampling linear)
|
|
|
|
(wrapping clamp-border))
|
|
|
|
|
|
|
|
(input fxaa-subpixel .5)
|
|
|
|
(input fxaa-et .166)
|
|
|
|
(input fxaa-et-min .0833)
|
2017-11-18 17:34:29 +01:00
|
|
|
|
|
|
|
(ui-overrides
|
|
|
|
(section "Post-processing"
|
|
|
|
(section "FXAA"
|
|
|
|
(float "Sub-pixel quality" fxaa-subpixel
|
|
|
|
(min 0) (max 1) (slider))
|
|
|
|
(float "Edge threshold" fxaa-et
|
|
|
|
(min .063) (max .333) (slider))
|
|
|
|
(float "Edge threshold min." fxaa-et-min
|
|
|
|
(min .0312) (max .0833) (decimals 4)
|
|
|
|
(slider))
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
2017-11-10 21:46:15 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
(fn fxaa-render (in-image)
|
|
|
|
(profiling "FXAA"
|
2017-11-15 09:46:07 +01:00
|
|
|
(uniforms-i prg-fxaa 0 0)
|
2017-11-15 23:09:52 +01:00
|
|
|
(uniforms prg-fxaa 1
|
|
|
|
$vp-x $vp-y $vp-width $vp-height)
|
2017-11-15 09:46:07 +01:00
|
|
|
|
2017-11-10 21:46:15 +01:00
|
|
|
(main-output)
|
2017-11-10 22:12:24 +01:00
|
|
|
(viewport 0 0 $width $height)
|
|
|
|
(clear 0 0 0 0)
|
|
|
|
|
2017-11-10 21:46:15 +01:00
|
|
|
(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)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2017-11-10 18:28:56 +01:00
|
|
|
|
2017-11-10 16:01:00 +01:00
|
|
|
# vim: syntax=demo-srd
|