Bloom ported to new shader stuff

This commit is contained in:
Emmanuel BENOîT 2017-10-04 17:48:25 +02:00
parent 2bd15c41ab
commit 7e6b558f27
5 changed files with 45 additions and 38 deletions

View file

@ -14,9 +14,6 @@ namespace {
T_BloomPass::T_BloomPass(
__rw__ T_Texture& input )
: input_( input ) ,
spHighpass_( GL_FRAGMENT_SHADER ) ,
spDownsample_( GL_FRAGMENT_SHADER ) ,
spBlur_( GL_FRAGMENT_SHADER ) ,
//
txBlur0_( input.width( ) , input.height( ) , E_TexType::RGB16F , BloomLevels ) ,
txBlur1_( input.width( ) , input.height( ) , E_TexType::RGB16F , BloomLevels ) ,
@ -33,21 +30,23 @@ T_BloomPass::T_BloomPass(
rtBlur1_.push_back( T_RendertargetSetup( ).add( txBlur1_ , i ).create( ) );
}
spHighpass_.addFile( "bloom-highpass.glsl" );
spDownsample_.addFile( "downsample.glsl" );
spBlur_.addFile( "blur-pass.glsl" );
spHighpass_.load( );
spDownsample_.load( );
spBlur_.load( );
auto& sm( Globals::Shaders( ) );
spHighpass_ = sm.pipeline({ "fullscreen.v.glsl" , "bloom-highpass.f.glsl" });
spDownsample_ = sm.pipeline({ "fullscreen.v.glsl" , "downsample.f.glsl" });
spBlur_ = sm.pipeline({ "fullscreen.v.glsl" , "blur-pass.f.glsl" });
}
void T_BloomPass::render( )
{
PSTART( );
if ( !( spHighpass_.valid( ) && spBlur_.valid( ) && spDownsample_.valid( ) ) ) {
return;
}
PSTART( );
auto& tm( Globals::Textures( ) );
if ( spHighpass_.activate( ) && rtBlur0_[ 0 ].activate( ) ) {
{
rtBlur0_[ 0 ].activate( );
const auto hpf( spHighpass_.program( E_ShaderType::FRAGMENT ) );
enum {
U_TEXTURE = 0 ,
U_LOD = 1 ,
@ -56,16 +55,16 @@ void T_BloomPass::render( )
};
tm.bind( 0 , input_ );
spHighpass_.enable( );
glUniform1i( U_TEXTURE , 0 );
glUniform1i( U_LOD , 0 );
glUniform2f( U_INPUT_SIZE ,
glProgramUniform1i( hpf , U_TEXTURE , 0 );
glProgramUniform1i( hpf , U_LOD , 0 );
glProgramUniform2f( hpf , U_INPUT_SIZE ,
input_.width( ) ,
input_.height( ) );
glUniform3fv( U_PARAMS , 1 , filterParams_ );
glRectf( -1, -1 , 1 , 1 );
glProgramUniform3fv( hpf , U_PARAMS , 1 , filterParams_ );
glDrawArrays( GL_TRIANGLE_STRIP , 0 , 4 );
}
GL_ASSERT( );
enum {
U_TEXTURE = 0 ,
@ -74,39 +73,41 @@ void T_BloomPass::render( )
U_DIRECTION = 3 ,
U_WEIGHTS = 4 ,
};
const auto dsf( spDownsample_.program( E_ShaderType::FRAGMENT ) );
const auto bpf( spBlur_.program( E_ShaderType::FRAGMENT ) );
glProgramUniform1i( dsf , 0 , 0 );
glProgramUniform4fv( bpf , U_WEIGHTS , 1 , blurWeights_ );
glProgramUniform1i( bpf , U_TEXTURE , 0 );
for ( auto i = 0u ; i < BloomLevels ; i ++ ) {
if ( i > 0 ) {
spDownsample_.activate( );
spDownsample_.enable( );
rtBlur0_[ i ].activate( );
tm.bind( 0 , txBlur0_ );
glUniform1i( 0 , 0 );
glUniform2f( 1 , txBlur0_.width( ) >> i ,
glProgramUniform2f( dsf , 1 , txBlur0_.width( ) >> i ,
txBlur0_.height( ) >> i );
glUniform1i( 2 , i - 1 );
glProgramUniform1i( dsf , 2 , i - 1 );
glRectf( -1 , -1 , 1 , 1 );
glDrawArrays( GL_TRIANGLE_STRIP , 0 , 4 );
}
if ( !spBlur_.activate( ) ) {
break;
}
glUniform4fv( U_WEIGHTS , 1 , blurWeights_ );
glUniform2f( U_OUTPUT_SIZE , rtBlur0_[ i ].width( ) ,
spBlur_.enable( );
glProgramUniform2f( bpf , U_OUTPUT_SIZE , rtBlur0_[ i ].width( ) ,
rtBlur0_[ i ].height( ) );
glUniform1i( U_SOURCE_LOD , i );
glUniform1i( U_TEXTURE , 0 );
glProgramUniform1i( bpf , U_SOURCE_LOD , i );
rtBlur1_[ i ].activate( );
glUniform2f( U_DIRECTION , blurSize_ , 0 );
glProgramUniform2f( bpf , U_DIRECTION , blurSize_ , 0 );
tm.bind( 0 , txBlur0_ );
glRectf( -1 , -1 , 1 , 1 );
glDrawArrays( GL_TRIANGLE_STRIP , 0 , 4 );
rtBlur0_[ i ].activate( );
glUniform2f( U_DIRECTION , 0 , blurSize_ );
glProgramUniform2f( bpf , U_DIRECTION , 0 , blurSize_ );
tm.bind( 0 , txBlur1_ );
glRectf( -1 , -1 , 1 , 1 );
glDrawArrays( GL_TRIANGLE_STRIP , 0 , 4 );
}
PEND( );

View file

@ -4,7 +4,7 @@
#endif
#include "rendertarget.hh"
#include "programs.hh"
#include "shaders.hh"
struct T_BloomPass
@ -25,9 +25,9 @@ struct T_BloomPass
private:
T_Texture& input_;
T_ShaderProgram spHighpass_;
T_ShaderProgram spDownsample_;
T_ShaderProgram spBlur_;
T_ShaderPipeline spHighpass_;
T_ShaderPipeline spDownsample_;
T_ShaderPipeline spBlur_;
T_TextureSampler sampler_;
T_Texture txBlur0_ , txBlur1_;

View file

@ -1,5 +1,7 @@
#version 450 core
//! type fragment
layout( location = 0 ) uniform sampler2D u_Input;
layout( location = 1 ) uniform int u_LOD;
layout( location = 2 ) uniform vec2 u_InputSize;

View file

@ -1,5 +1,7 @@
#version 450 core
//! type fragment
layout( location = 0 ) uniform sampler2D u_InputTexture;
layout( location = 1 ) uniform vec2 u_OutputSize;
layout( location = 2 ) uniform int u_SourceLOD;

View file

@ -1,5 +1,7 @@
#version 450 core
//! type fragment
layout( location = 0 ) uniform sampler2D u_InputTexture;
layout( location = 1 ) uniform vec2 u_OutputSize;
layout( location = 2 ) uniform int u_SourceLOD;