Shaders - Relative paths

Shaders are no longer found under /shaders in the project; they can be
anywhere. In addition, paths for both (program) instructions in the
script and include directives in shader source code are relative to the
file which contains them.
This commit is contained in:
Emmanuel BENOîT 2017-12-29 11:33:15 +01:00
parent 3344f96af0
commit 68d01ca42e
41 changed files with 198 additions and 132 deletions

View file

@ -0,0 +1,20 @@
#version 450 core
//! type fragment
layout( location = 0 ) uniform sampler2D u_Input;
layout( location = 1 ) uniform int u_LOD;
layout( location = 2 ) uniform vec2 u_InputSize;
layout( location = 3 ) uniform vec3 u_FilterParams;
layout( location = 0 ) out vec3 color;
void main( void )
{
const vec3 c = textureLod( u_Input ,
gl_FragCoord.xy / u_InputSize.xy , u_LOD ).xyz;
color = max( vec3( 0 ) ,
( pow( c , vec3( u_FilterParams.x ) ) * u_FilterParams.y - c )
* u_FilterParams.z );
}

View file

@ -0,0 +1,29 @@
#version 450 core
//! type fragment
layout( location = 0 ) uniform sampler2D u_InputTexture;
layout( location = 1 ) uniform vec2 u_OutputSize;
layout( location = 2 ) uniform int u_SourceLOD;
layout( location = 3 ) uniform vec2 u_Direction;
layout( location = 4 ) uniform vec4 u_Weights;
layout( location = 0 ) out vec3 color;
void main( void )
{
vec2 tmp = gl_FragCoord.xy / u_OutputSize;
vec2 disp = u_Direction / u_OutputSize;
color = u_Weights.x * textureLod( u_InputTexture , tmp , u_SourceLOD ).xyz
+ u_Weights.y * (
textureLod( u_InputTexture , tmp + disp , u_SourceLOD ).xyz
+ textureLod( u_InputTexture , tmp - disp , u_SourceLOD ).xyz )
+ u_Weights.z * (
textureLod( u_InputTexture , tmp + disp * 2 , u_SourceLOD ).xyz
+ textureLod( u_InputTexture , tmp - disp * 2 , u_SourceLOD ).xyz )
+ u_Weights.w * (
textureLod( u_InputTexture , tmp + disp * 3 , u_SourceLOD ).xyz
+ textureLod( u_InputTexture , tmp - disp * 3 , u_SourceLOD ).xyz )
;
color /= u_Weights.x + 2 * ( u_Weights.y + u_Weights.z + u_Weights.w );
}

View file

@ -0,0 +1,20 @@
#version 450 core
//! type fragment
layout( location = 0 ) uniform sampler2D u_InputTexture;
layout( location = 1 ) uniform vec2 u_OutputSize;
layout( location = 2 ) uniform int u_SourceLOD;
layout( location = 0 ) out vec3 color;
void main( void )
{
const vec2 c = gl_FragCoord.xy;
color = ( .25 * (
textureLod( u_InputTexture , ( c + vec2( .5 , .5 ) ) / u_OutputSize , u_SourceLOD )
+ textureLod( u_InputTexture , ( c + vec2(-.5 , .5 ) ) / u_OutputSize , u_SourceLOD )
+ textureLod( u_InputTexture , ( c + vec2( .5 ,-.5 ) ) / u_OutputSize , u_SourceLOD )
+ textureLod( u_InputTexture , ( c + vec2(-.5 ,-.5 ) ) / u_OutputSize , u_SourceLOD )
) ).rgb;
}

167
test/fx-bloom/fx-bloom.srd Normal file
View file

@ -0,0 +1,167 @@
################################################################################
# Bloom
(fn bloom-init ()
# Samplers
(sampler smp-bloom-blur
(sampling linear)
(mipmaps linear)
(lod 0 100)
(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))
(odbg tx-bloom2 hdr "Bloom (partial)")
# 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
(input bloom-power 1.6)
(input bloom-factor 1.2)
(input bloom-output-factor 1.05)
# 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)
# 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))
)
)
)
)
)
(fn bloom-render (in-scene)
(profiling "BLOOOOM!"
(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)
# High pass
(use-texture 0 in-scene smp-bloom-input)
(uniforms prg-bloom-highpass 3
(get-input bloom-power)
(get-input bloom-factor)
(get-input bloom-output-factor)
)
(use-framebuffer rt-bloom1-lod0)
(use-pipeline pl-bloom-highpass)
(viewport 0 0 $vp-width $vp-height)
(fullscreen)
# 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))
# Blur & downsample
(uniforms prg-bloom-blur 1 $vp-width $vp-height)
(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)
(locals m w h)
(set m (pow 2 $level))
(set w (div $vp-width $m))
(set h (div $vp-height $m))
(use-pipeline pl-bloom-downsample)
(use-framebuffer target)
(use-texture 0 tx-bloom1 smp-bloom-blur)
(uniforms prg-bloom-downsample 1 $w $h)
(uniforms-i prg-bloom-downsample 2 (sub $level 1))
(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)
(uniforms-i prg-bloom-blur 2 $lod)
# 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)
)
# vim: syntax=demo-srd