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,69 @@
#version 450 core
layout(
local_size_x = 8 ,
local_size_y = 32
) in;
//! type compute
//! include /lib/utils.glsl
layout( location = 0 ) uniform sampler2D u_MainInput;
layout( location = 1 ) uniform sampler2D u_BlurInput;
layout( location = 2 ) uniform vec2 u_OutputSize;
layout( location = 3 ) uniform vec2 u_Bloom;
layout( location = 4 ) uniform vec4 u_Vignette1;
layout( location = 5 ) uniform vec2 u_Vignette2;
layout( location = 6 ) uniform vec3 u_ColorLift;
layout( location = 7 ) uniform vec3 u_ColorGain;
layout( location = 8 ) uniform vec3 u_ColorGamma;
layout( binding = 0 , rgba8 ) writeonly uniform image2D u_Output;
#define uVigShapeMul (u_Vignette1.x)
#define uVigShapePow (u_Vignette1.y)
#define uVigAspect (u_Vignette1.z)
#define uVigShapeReverse (u_Vignette1.w)
#define uVigApplyBase (u_Vignette2.x)
#define uVigApplyMax (u_Vignette2.y)
void main( void )
{
ivec2 coords = ivec2( gl_GlobalInvocationID.xy );
vec2 pos = vec2( coords ) / vec2( imageSize( u_Output ) );
if ( pos.x > 1. || pos.y > 1. ) {
return;
}
float f = u_Bloom.x;
vec3 color = textureLod( u_MainInput , pos , 0 ).rgb;
// Bloom
vec3 bloom = vec3( 0 );
for ( int i = 0 ; i < 6 ; i ++ ) {
bloom += f * textureLod( u_BlurInput , pos , i ).rgb;
f = pow( f , u_Bloom.y + 1 );
}
color = color + bloom / 2.2;
// Color grading
color = ( color * ( u_ColorGain - u_ColorLift ) ) + u_ColorLift;
// Vignette
vec2 vShape = pow( abs( pos * 2 - 1 ) * uVigShapeMul ,
vec2( uVigShapePow ) );
float vignette = 1 - pow(
2 * ( uVigAspect * vShape.x + ( 1 - uVigAspect) * vShape.y ) ,
1 / ( uVigShapePow * uVigShapeReverse ) );
color *= uVigApplyBase + smoothstep(
uVigApplyBase , uVigApplyBase + uVigApplyMax , vignette );
// Reinhart
color = color / ( color + 1. );
// Gamma
color = pow( color , vec3( 1 ) / ( u_ColorGamma + 2.2 ) );
// Write it
imageStore( u_Output , coords ,
vec4( color , M_Luminosity( color ) ) );
}

View file

@ -0,0 +1,59 @@
#version 450 core
//! type fragment
//! include /lib/utils.glsl
layout( location = 0 ) uniform sampler2D u_MainInput;
layout( location = 1 ) uniform sampler2D u_BlurInput;
layout( location = 2 ) uniform vec2 u_OutputSize;
layout( location = 3 ) uniform vec2 u_Bloom;
layout( location = 4 ) uniform vec4 u_Vignette1;
layout( location = 5 ) uniform vec2 u_Vignette2;
layout( location = 6 ) uniform vec3 u_ColorLift;
layout( location = 7 ) uniform vec3 u_ColorGain;
layout( location = 8 ) uniform vec3 u_ColorGamma;
#define uVigShapeMul (u_Vignette1.x)
#define uVigShapePow (u_Vignette1.y)
#define uVigAspect (u_Vignette1.z)
#define uVigShapeReverse (u_Vignette1.w)
#define uVigApplyBase (u_Vignette2.x)
#define uVigApplyMax (u_Vignette2.y)
layout( location = 0 ) out vec4 o_Color;
void main( void )
{
vec2 pos = gl_FragCoord.xy / u_OutputSize;
float f = u_Bloom.x;
vec3 color = textureLod( u_MainInput , pos , 0 ).rgb;
// Bloom
vec3 bloom = vec3( 0 );
for ( int i = 0 ; i < 6 ; i ++ ) {
bloom += f * textureLod( u_BlurInput , pos , i ).rgb;
f = pow( f , u_Bloom.y + 1 );
}
color = color + bloom / 2.2;
// Color grading
color = ( color * ( u_ColorGain - u_ColorLift ) ) + u_ColorLift;
// Vignette
vec2 vShape = pow( abs( pos * 2 - 1 ) * uVigShapeMul ,
vec2( uVigShapePow ) );
float vignette = 1 - pow(
2 * ( uVigAspect * vShape.x + ( 1 - uVigAspect) * vShape.y ) ,
1 / ( uVigShapePow * uVigShapeReverse ) );
color *= uVigApplyBase + smoothstep(
uVigApplyBase , uVigApplyBase + uVigApplyMax , vignette );
// Reinhart
color = color / ( color + 1. );
// Gamma
color = pow( color , vec3( 1 ) / ( u_ColorGamma + 2.2 ) );
o_Color = vec4( color , M_Luminosity( color ) );
}

View file

@ -0,0 +1,120 @@
################################################################################
# Combine
(fn combine-init ()
# Assets
(sampler smp-combine-input (sampling nearest))
(sampler smp-combine-bloom
(sampling linear)
(mipmaps nearest)
(lod 0 100))
(texture tx-combined rgba-nu8 $vp-width $vp-height)
(odbg tx-combined ldr-alpha "Combined output")
(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)
))
# 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)
# 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))
)
)
(section "Color grading"
(color-grading "Lift"
cg-lift-r cg-lift-g cg-lift-b
(base -.1) (unit .1))
(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
(base -.9) (unit .9))
)
)
# FIXME: overrides for vignette
)
)
(fn combine-render (in-main in-bloom)
(profiling "Combine"
(uniforms-i prg-combine 0 0)
(uniforms-i prg-combine 1 1)
(use-pipeline pl-combine)
(if (not $use-compute) (
(uniforms prg-combine 2 $vp-width $vp-height)
(use-framebuffer rt-combined)
))
(use-texture 0 in-main smp-combine-input)
(use-texture 1 in-bloom smp-combine-bloom)
(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))
(if $use-compute (
(image 0 tx-combined 0)
(compute $vp-width $vp-height 1)
)(
(viewport 0 0 $vp-width $vp-height)
(fullscreen)
))
)
)
# vim: syntax=demo-srd