69 lines
1.9 KiB
GLSL
69 lines
1.9 KiB
GLSL
#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 ) ) );
|
|
}
|