demotool/test/fx-combine/combine.f.glsl
Emmanuel BENOîT 68d01ca42e 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.
2017-12-29 11:33:15 +01:00

59 lines
1.7 KiB
GLSL

#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 ) );
}