Test - Use compute shader for combine stage

This commit is contained in:
Emmanuel BENOîT 2017-12-24 11:40:06 +01:00
parent 4394d911c2
commit 81ff8a8da6
2 changed files with 87 additions and 6 deletions

View file

@ -17,6 +17,7 @@
(program prg-fullscreen "fullscreen.v.glsl")
(set use-compute 1)
(call scene-init)
(call dof-init)
(call bloom-init)
@ -410,9 +411,15 @@
(lod 0 100))
(texture tx-combined rgba-nu8 $vp-width $vp-height)
(odbg tx-combined ldr-alpha "Combined output")
(framebuffer rt-combined tx-combined)
(program prg-combine "combine.f.glsl")
(pipeline pl-combine prg-fullscreen prg-combine)
(if $use-compute (
(program prg-combine "combine.c.glsl")
(pipeline pl-combine prg-combine)
(set combine-compute-size 16)
)(
(framebuffer rt-combined tx-combined)
(program prg-combine "combine.f.glsl")
(pipeline pl-combine prg-fullscreen prg-combine)
))
# Bloom parameters
(input bloom-strength .45)
@ -472,7 +479,9 @@
(uniforms prg-combine 2 $vp-width $vp-height)
(use-pipeline pl-combine)
(use-framebuffer rt-combined)
(if (not $use-compute) (
(use-framebuffer rt-combined)
))
(use-texture 0 in-main smp-combine-input)
(use-texture 1 in-bloom smp-combine-bloom)
(uniforms prg-combine 3
@ -498,8 +507,17 @@
(get-input cg-gamma-r)
(get-input cg-gamma-g)
(get-input cg-gamma-b))
(viewport 0 0 $vp-width $vp-height)
(fullscreen)
(if $use-compute (
(image 0 tx-combined 0)
(compute
(add 1 (div $vp-width $combine-compute-size))
(add 1 (div $vp-height $combine-compute-size))
1)
)(
(viewport 0 0 $vp-width $vp-height)
(fullscreen)
))
)
)

View 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 ) ) );
}