2017-12-29 11:33:15 +01:00
|
|
|
(include "fx-bloom/fx-bloom.srd")
|
|
|
|
(include "fx-dof/fx-dof.srd")
|
|
|
|
(include "fx-combine/fx-combine.srd")
|
|
|
|
(include "fx-fxaa/fx-fxaa.srd")
|
2017-12-28 10:33:59 +01:00
|
|
|
|
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
|
|
|
|
2017-12-29 11:33:15 +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
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2017-11-10 18:28:56 +01:00
|
|
|
|
2017-11-10 16:01:00 +01:00
|
|
|
# vim: syntax=demo-srd
|