demotool/shaders/combine.f.glsl

65 lines
1.8 KiB
Text
Raw Normal View History

#version 450 core
2017-10-04 18:06:39 +02:00
//! type fragment
layout( location = 0 ) uniform sampler2D u_MainInput;
layout( location = 1 ) uniform sampler2D u_BlurInput;
layout( location = 2 ) uniform vec2 u_OutputSize;
2017-10-05 10:09:34 +02:00
layout( location = 3 ) uniform vec2 u_Bloom;
2017-10-05 10:09:34 +02:00
// Vignette parameters
// 1.x = shape multiplier
// 1.y = shape power
// 1.z = aspect ratio
// 1.w = reverse power multiplier
// 2.x = apply base
// 2.y = apply max
layout( location = 4 ) uniform vec4 u_Vignette1;
layout( location = 5 ) uniform vec2 u_Vignette2;
#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 vec3 o_Color;
void main( void )
{
2017-10-05 10:09:34 +02:00
vec2 pos = gl_FragCoord.xy / u_OutputSize;
float f = u_Bloom.x;
o_Color = textureLod( u_MainInput , pos , 0 ).rgb;
// Bloom
2017-09-30 21:22:38 +02:00
vec3 bloom = vec3( 0 );
2017-09-30 21:27:50 +02:00
for ( int i = 0 ; i < 6 ; i ++ ) {
2017-10-05 10:09:34 +02:00
bloom += f * textureLod( u_BlurInput , pos , i ).rgb;
f = pow( f , u_Bloom.y + 1 );
}
2017-10-05 10:09:34 +02:00
o_Color = o_Color + bloom / 2.2;
2017-10-05 11:47:33 +02:00
// Color grading test
vec3 uColorGain = vec3( .95 , 1.1 , 1.4 ) ,
uColorLift = vec3( 0 , 0 , .003 ) ,
uColorGamma = vec3( -.2 , 0.1 , .1 );
o_Color = ( o_Color * ( uColorGain - uColorLift ) ) + uColorLift;
2017-10-05 10:09:34 +02:00
// 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 ) );
o_Color *= uVigApplyBase + smoothstep(
uVigApplyBase , uVigApplyBase + uVigApplyMax , vignette );
// Reinhart
o_Color = o_Color / ( o_Color + 1. );
2017-09-30 19:41:45 +02:00
2017-10-05 10:09:34 +02:00
// Gamma
2017-10-05 11:47:33 +02:00
o_Color = pow( o_Color , vec3( 1 ) / ( uColorGamma + 2.2 ) );
}