112 lines
3.3 KiB
C++
112 lines
3.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 ) ,
|
|
txOutput_( image.width( ) , image.height( ) , E_TexType::RGBA8 ) ,
|
|
rtOutput_( T_RendertargetSetup( ).add( txOutput_ ).create( ) ) ,
|
|
bloomStrength_( 0.45 ) ,
|
|
bloomAttenuation_( 0.3 ) ,
|
|
vignette_{
|
|
1 , 8 , .5 , 1 , 0 , 1
|
|
} ,
|
|
cgLift_{ 0 , 0 , 0 } ,
|
|
cgGain_{ 1 , 1 , 1 } ,
|
|
cgGamma_{ 0 , 0 , 0 }
|
|
{
|
|
program_ = Globals::Shaders( ).pipeline({
|
|
"fullscreen.v.glsl" , "combine.f.glsl" });
|
|
}
|
|
|
|
void T_CombinePass::render( )
|
|
{
|
|
PSTART( );
|
|
rtOutput_.activate( );
|
|
glClearColor( 1 , 0 , 1 , .413f );
|
|
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 ,
|
|
U_CG_LIFT ,
|
|
U_CG_GAIN ,
|
|
U_CG_GAMMA ,
|
|
};
|
|
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 );
|
|
glProgramUniform3fv( id , U_CG_LIFT , 1 , cgLift_ );
|
|
glProgramUniform3fv( id , U_CG_GAIN , 1 , cgGain_ );
|
|
glProgramUniform3fv( id , U_CG_GAMMA , 1 , cgGamma_ );
|
|
|
|
glDrawArrays( GL_TRIANGLE_STRIP , 0 , 4 );
|
|
}
|
|
PEND( );
|
|
}
|
|
|
|
void T_CombinePass::makeUI( )
|
|
{
|
|
using namespace ImGui;
|
|
if ( !CollapsingHeader( "Combine" ) ) {
|
|
return;
|
|
}
|
|
|
|
if ( TreeNode( "combine-bloom" , "Bloom" ) ) {
|
|
DragFloat( "Strength" , &bloomStrength_ , .001f , 0. , 10 );
|
|
DragFloat( "Attenuation" , &bloomAttenuation_ , .001f , 0. , 1 );
|
|
TreePop( );
|
|
}
|
|
|
|
if ( TreeNode( "Vignette" ) ) {
|
|
DragFloat( "Shape mult." , &vignette_[ 0 ] , .01f , 0.5 , 20 );
|
|
DragFloat( "Shape power" , &vignette_[ 1 ] , .01f , .5 , 50 );
|
|
DragFloat( "Aspect ratio" , &vignette_[ 2 ] , .001f , 0 , 1 );
|
|
DragFloat( "Shape reverse" , &vignette_[ 3 ] , .001f , .2 , 5 );
|
|
DragFloat( "Apply base" , &vignette_[ 4 ] , .001f , 0 , 1 );
|
|
DragFloat( "Apply max" , &vignette_[ 5 ] , .001f , 0 , 1 );
|
|
TreePop( );
|
|
}
|
|
|
|
if ( TreeNode( "Color grading" ) ) {
|
|
DragFloat( "Lift / R" , &cgLift_[ 0 ] , .0001f , -1 , 1 );
|
|
DragFloat( "Lift / G" , &cgLift_[ 1 ] , .0001f , -1 , 1 );
|
|
DragFloat( "Lift / B" , &cgLift_[ 2 ] , .0001f , -1 , 1 );
|
|
DragFloat( "Gain / R" , &cgGain_[ 0 ] , .001f , 0 , 2 );
|
|
DragFloat( "Gain / G" , &cgGain_[ 1 ] , .001f , 0 , 2 );
|
|
DragFloat( "Gain / B" , &cgGain_[ 2 ] , .001f , 0 , 2 );
|
|
DragFloat( "Gamma / R" , &cgGamma_[ 0 ] , .001f , -2 , 10 );
|
|
DragFloat( "Gamma / G" , &cgGamma_[ 1 ] , .001f , -2 , 10 );
|
|
DragFloat( "Gamma / B" , &cgGamma_[ 2 ] , .001f , -2 , 10 );
|
|
TreePop( );
|
|
}
|
|
}
|