64 lines
1.8 KiB
GLSL
64 lines
1.8 KiB
GLSL
#version 450 core
|
|
|
|
//! type fragment
|
|
|
|
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;
|
|
|
|
// 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 )
|
|
{
|
|
vec2 pos = gl_FragCoord.xy / u_OutputSize;
|
|
float f = u_Bloom.x;
|
|
o_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 );
|
|
}
|
|
o_Color = o_Color + bloom / 2.2;
|
|
|
|
// 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;
|
|
|
|
// 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. );
|
|
|
|
// Gamma
|
|
o_Color = pow( o_Color , vec3( 1 ) / ( uColorGamma + 2.2 ) );
|
|
}
|