Bloom ported to new shader stuff
This commit is contained in:
parent
2bd15c41ab
commit
7e6b558f27
5 changed files with 45 additions and 38 deletions
69
bloom.cc
69
bloom.cc
|
@ -14,9 +14,6 @@ namespace {
|
||||||
T_BloomPass::T_BloomPass(
|
T_BloomPass::T_BloomPass(
|
||||||
__rw__ T_Texture& input )
|
__rw__ T_Texture& input )
|
||||||
: input_( input ) ,
|
: input_( input ) ,
|
||||||
spHighpass_( GL_FRAGMENT_SHADER ) ,
|
|
||||||
spDownsample_( GL_FRAGMENT_SHADER ) ,
|
|
||||||
spBlur_( GL_FRAGMENT_SHADER ) ,
|
|
||||||
//
|
//
|
||||||
txBlur0_( input.width( ) , input.height( ) , E_TexType::RGB16F , BloomLevels ) ,
|
txBlur0_( input.width( ) , input.height( ) , E_TexType::RGB16F , BloomLevels ) ,
|
||||||
txBlur1_( 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( ) );
|
rtBlur1_.push_back( T_RendertargetSetup( ).add( txBlur1_ , i ).create( ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
spHighpass_.addFile( "bloom-highpass.glsl" );
|
auto& sm( Globals::Shaders( ) );
|
||||||
spDownsample_.addFile( "downsample.glsl" );
|
spHighpass_ = sm.pipeline({ "fullscreen.v.glsl" , "bloom-highpass.f.glsl" });
|
||||||
spBlur_.addFile( "blur-pass.glsl" );
|
spDownsample_ = sm.pipeline({ "fullscreen.v.glsl" , "downsample.f.glsl" });
|
||||||
|
spBlur_ = sm.pipeline({ "fullscreen.v.glsl" , "blur-pass.f.glsl" });
|
||||||
spHighpass_.load( );
|
|
||||||
spDownsample_.load( );
|
|
||||||
spBlur_.load( );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void T_BloomPass::render( )
|
void T_BloomPass::render( )
|
||||||
{
|
{
|
||||||
PSTART( );
|
if ( !( spHighpass_.valid( ) && spBlur_.valid( ) && spDownsample_.valid( ) ) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
PSTART( );
|
||||||
auto& tm( Globals::Textures( ) );
|
auto& tm( Globals::Textures( ) );
|
||||||
if ( spHighpass_.activate( ) && rtBlur0_[ 0 ].activate( ) ) {
|
{
|
||||||
|
rtBlur0_[ 0 ].activate( );
|
||||||
|
const auto hpf( spHighpass_.program( E_ShaderType::FRAGMENT ) );
|
||||||
enum {
|
enum {
|
||||||
U_TEXTURE = 0 ,
|
U_TEXTURE = 0 ,
|
||||||
U_LOD = 1 ,
|
U_LOD = 1 ,
|
||||||
|
@ -56,16 +55,16 @@ void T_BloomPass::render( )
|
||||||
};
|
};
|
||||||
|
|
||||||
tm.bind( 0 , input_ );
|
tm.bind( 0 , input_ );
|
||||||
|
spHighpass_.enable( );
|
||||||
|
|
||||||
glUniform1i( U_TEXTURE , 0 );
|
glProgramUniform1i( hpf , U_TEXTURE , 0 );
|
||||||
glUniform1i( U_LOD , 0 );
|
glProgramUniform1i( hpf , U_LOD , 0 );
|
||||||
glUniform2f( U_INPUT_SIZE ,
|
glProgramUniform2f( hpf , U_INPUT_SIZE ,
|
||||||
input_.width( ) ,
|
input_.width( ) ,
|
||||||
input_.height( ) );
|
input_.height( ) );
|
||||||
glUniform3fv( U_PARAMS , 1 , filterParams_ );
|
glProgramUniform3fv( hpf , U_PARAMS , 1 , filterParams_ );
|
||||||
glRectf( -1, -1 , 1 , 1 );
|
glDrawArrays( GL_TRIANGLE_STRIP , 0 , 4 );
|
||||||
}
|
}
|
||||||
GL_ASSERT( );
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
U_TEXTURE = 0 ,
|
U_TEXTURE = 0 ,
|
||||||
|
@ -74,39 +73,41 @@ void T_BloomPass::render( )
|
||||||
U_DIRECTION = 3 ,
|
U_DIRECTION = 3 ,
|
||||||
U_WEIGHTS = 4 ,
|
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 ++ ) {
|
for ( auto i = 0u ; i < BloomLevels ; i ++ ) {
|
||||||
if ( i > 0 ) {
|
if ( i > 0 ) {
|
||||||
spDownsample_.activate( );
|
spDownsample_.enable( );
|
||||||
rtBlur0_[ i ].activate( );
|
rtBlur0_[ i ].activate( );
|
||||||
|
|
||||||
tm.bind( 0 , txBlur0_ );
|
tm.bind( 0 , txBlur0_ );
|
||||||
|
|
||||||
glUniform1i( 0 , 0 );
|
glProgramUniform2f( dsf , 1 , txBlur0_.width( ) >> i ,
|
||||||
glUniform2f( 1 , txBlur0_.width( ) >> i ,
|
|
||||||
txBlur0_.height( ) >> 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( ) ) {
|
spBlur_.enable( );
|
||||||
break;
|
glProgramUniform2f( bpf , U_OUTPUT_SIZE , rtBlur0_[ i ].width( ) ,
|
||||||
}
|
|
||||||
glUniform4fv( U_WEIGHTS , 1 , blurWeights_ );
|
|
||||||
glUniform2f( U_OUTPUT_SIZE , rtBlur0_[ i ].width( ) ,
|
|
||||||
rtBlur0_[ i ].height( ) );
|
rtBlur0_[ i ].height( ) );
|
||||||
glUniform1i( U_SOURCE_LOD , i );
|
glProgramUniform1i( bpf , U_SOURCE_LOD , i );
|
||||||
glUniform1i( U_TEXTURE , 0 );
|
|
||||||
|
|
||||||
rtBlur1_[ i ].activate( );
|
rtBlur1_[ i ].activate( );
|
||||||
glUniform2f( U_DIRECTION , blurSize_ , 0 );
|
glProgramUniform2f( bpf , U_DIRECTION , blurSize_ , 0 );
|
||||||
tm.bind( 0 , txBlur0_ );
|
tm.bind( 0 , txBlur0_ );
|
||||||
glRectf( -1 , -1 , 1 , 1 );
|
glDrawArrays( GL_TRIANGLE_STRIP , 0 , 4 );
|
||||||
|
|
||||||
rtBlur0_[ i ].activate( );
|
rtBlur0_[ i ].activate( );
|
||||||
glUniform2f( U_DIRECTION , 0 , blurSize_ );
|
glProgramUniform2f( bpf , U_DIRECTION , 0 , blurSize_ );
|
||||||
tm.bind( 0 , txBlur1_ );
|
tm.bind( 0 , txBlur1_ );
|
||||||
glRectf( -1 , -1 , 1 , 1 );
|
glDrawArrays( GL_TRIANGLE_STRIP , 0 , 4 );
|
||||||
}
|
}
|
||||||
|
|
||||||
PEND( );
|
PEND( );
|
||||||
|
|
8
bloom.hh
8
bloom.hh
|
@ -4,7 +4,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "rendertarget.hh"
|
#include "rendertarget.hh"
|
||||||
#include "programs.hh"
|
#include "shaders.hh"
|
||||||
|
|
||||||
|
|
||||||
struct T_BloomPass
|
struct T_BloomPass
|
||||||
|
@ -25,9 +25,9 @@ struct T_BloomPass
|
||||||
private:
|
private:
|
||||||
T_Texture& input_;
|
T_Texture& input_;
|
||||||
|
|
||||||
T_ShaderProgram spHighpass_;
|
T_ShaderPipeline spHighpass_;
|
||||||
T_ShaderProgram spDownsample_;
|
T_ShaderPipeline spDownsample_;
|
||||||
T_ShaderProgram spBlur_;
|
T_ShaderPipeline spBlur_;
|
||||||
|
|
||||||
T_TextureSampler sampler_;
|
T_TextureSampler sampler_;
|
||||||
T_Texture txBlur0_ , txBlur1_;
|
T_Texture txBlur0_ , txBlur1_;
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#version 450 core
|
#version 450 core
|
||||||
|
|
||||||
|
//! type fragment
|
||||||
|
|
||||||
layout( location = 0 ) uniform sampler2D u_Input;
|
layout( location = 0 ) uniform sampler2D u_Input;
|
||||||
layout( location = 1 ) uniform int u_LOD;
|
layout( location = 1 ) uniform int u_LOD;
|
||||||
layout( location = 2 ) uniform vec2 u_InputSize;
|
layout( location = 2 ) uniform vec2 u_InputSize;
|
|
@ -1,5 +1,7 @@
|
||||||
#version 450 core
|
#version 450 core
|
||||||
|
|
||||||
|
//! type fragment
|
||||||
|
|
||||||
layout( location = 0 ) uniform sampler2D u_InputTexture;
|
layout( location = 0 ) uniform sampler2D u_InputTexture;
|
||||||
layout( location = 1 ) uniform vec2 u_OutputSize;
|
layout( location = 1 ) uniform vec2 u_OutputSize;
|
||||||
layout( location = 2 ) uniform int u_SourceLOD;
|
layout( location = 2 ) uniform int u_SourceLOD;
|
|
@ -1,5 +1,7 @@
|
||||||
#version 450 core
|
#version 450 core
|
||||||
|
|
||||||
|
//! type fragment
|
||||||
|
|
||||||
layout( location = 0 ) uniform sampler2D u_InputTexture;
|
layout( location = 0 ) uniform sampler2D u_InputTexture;
|
||||||
layout( location = 1 ) uniform vec2 u_OutputSize;
|
layout( location = 1 ) uniform vec2 u_OutputSize;
|
||||||
layout( location = 2 ) uniform int u_SourceLOD;
|
layout( location = 2 ) uniform int u_SourceLOD;
|
Loading…
Reference in a new issue