Test - Use compute shader for combine stage
This commit is contained in:
parent
4394d911c2
commit
81ff8a8da6
2 changed files with 87 additions and 6 deletions
test/shaders
63
test/shaders/combine.c.glsl
Normal file
63
test/shaders/combine.c.glsl
Normal file
|
@ -0,0 +1,63 @@
|
|||
#version 450 core
|
||||
|
||||
layout( local_size_x = 16 , local_size_y = 16 ) 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 ub_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 ) / 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 ) );
|
||||
|
||||
// Write it
|
||||
imageStore( ub_Output , coords ,
|
||||
vec4( color , M_Luminosity( color ) ) );
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue