demotool/shaders/combine.f.glsl

57 lines
1.6 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;
layout( location = 4 ) uniform vec4 u_Vignette1;
layout( location = 5 ) uniform vec2 u_Vignette2;
2017-10-05 12:56:52 +02:00
layout( location = 6 ) uniform vec3 u_ColorLift;
layout( location = 7 ) uniform vec3 u_ColorGain;
layout( location = 8 ) uniform vec3 u_ColorGamma;
2017-10-05 10:09:34 +02:00
#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 12:56:52 +02:00
// Color grading
o_Color = ( o_Color * ( u_ColorGain - u_ColorLift ) ) + u_ColorLift;
2017-10-05 11:47:33 +02:00
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 12:56:52 +02:00
o_Color = pow( o_Color , vec3( 1 ) / ( u_ColorGamma + 2.2 ) );
}