demotool/combine.cc
2017-10-05 10:09:34 +02:00

84 lines
2.3 KiB
C++

#include "externals.hh"
#include "combine.hh"
#include "bloom.hh"
#include "profiling.hh"
#include "globals.hh"
namespace {
static const std::string Name_( "Combine" );
}
#define PSTART() Globals::Profiler( ).start( Name_ )
#define PEND() do { glFinish( ); Globals::Profiler( ).end( Name_ ); } while ( 0 )
T_CombinePass::T_CombinePass(
__rw__ T_Texture& image ,
__rw__ T_Texture& bloom )
: txImage_( image ) , txBloom_( bloom ) ,
bloomStrength_( 0.45 ) ,
bloomAttenuation_( 0.3 ) ,
vignette_{
1 , 8 , .5 , 1 , 0 , 1
}
{
program_ = Globals::Shaders( ).pipeline({
"fullscreen.v.glsl" , "combine.f.glsl" });
}
void T_CombinePass::render( )
{
PSTART( );
T_Rendertarget::MainOutput( );
glClearColor( 1 , 0 , 1 , 1 );
glClear( GL_COLOR_BUFFER_BIT );
if ( program_.valid( ) ) {
enum {
U_MAIN_INPUT ,
U_BLOOM_INPUT ,
U_OUTPUT_SIZE ,
U_BLOOM_PARAMETERS ,
U_VIGNETTE_PARAMETERS_1 ,
U_VIGNETTE_PARAMETERS_2 ,
};
auto& tm( Globals::Textures( ) );
tm.bind( 0 , txImage_ );
tm.bind( 1 , txBloom_ );
const auto id( program_.program( E_ShaderType::FRAGMENT ) );
program_.enable( );
glProgramUniform1i( id , U_MAIN_INPUT , 0 );
glProgramUniform1i( id , U_BLOOM_INPUT , 1 );
glProgramUniform2f( id , U_OUTPUT_SIZE ,
txImage_.width( ) , txImage_.height( ) );
glProgramUniform2f( id , U_BLOOM_PARAMETERS ,
bloomStrength_ , bloomAttenuation_ );
glProgramUniform4fv( id , U_VIGNETTE_PARAMETERS_1 , 1 ,
vignette_ );
glProgramUniform2fv( id , U_VIGNETTE_PARAMETERS_2 , 1 ,
vignette_ + 4 );
glDrawArrays( GL_TRIANGLE_STRIP , 0 , 4 );
}
PEND( );
}
void T_CombinePass::makeUI( )
{
if ( !ImGui::CollapsingHeader( "Combine" ) ) {
return;
}
ImGui::Text( "Bloom" );
ImGui::DragFloat( "Strength" , &bloomStrength_ , .001f , 0. , 10 );
ImGui::DragFloat( "Attenuation" , &bloomAttenuation_ , .001f , 0. , 1 );
ImGui::Text( "Vignette" );
ImGui::DragFloat( "Shape mult." , &vignette_[ 0 ] , .01f , 0.5 , 20 );
ImGui::DragFloat( "Shape power" , &vignette_[ 1 ] , .01f , .5 , 50 );
ImGui::DragFloat( "Aspect ratio" , &vignette_[ 2 ] , .001f , 0 , 1 );
ImGui::DragFloat( "Shape reverse" , &vignette_[ 3 ] , .001f , .2 , 5 );
ImGui::DragFloat( "Apply base" , &vignette_[ 4 ] , .001f , 0 , 1 );
ImGui::DragFloat( "Apply max" , &vignette_[ 5 ] , .001f , 0 , 1 );
}