2017-10-01 18:51:02 +02:00
|
|
|
#include "externals.hh"
|
|
|
|
#include "combine.hh"
|
|
|
|
#include "bloom.hh"
|
|
|
|
#include "profiling.hh"
|
2017-10-04 11:20:27 +02:00
|
|
|
#include "globals.hh"
|
2017-10-01 18:51:02 +02:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
static const std::string Name_( "Combine" );
|
|
|
|
}
|
|
|
|
|
2017-10-04 18:08:37 +02:00
|
|
|
#define PSTART() Globals::Profiler( ).start( Name_ )
|
|
|
|
#define PEND() do { glFinish( ); Globals::Profiler( ).end( Name_ ); } while ( 0 )
|
2017-10-01 18:51:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
T_CombinePass::T_CombinePass(
|
|
|
|
__rw__ T_Texture& image ,
|
|
|
|
__rw__ T_Texture& bloom )
|
|
|
|
: txImage_( image ) , txBloom_( bloom ) ,
|
2017-10-05 18:35:35 +02:00
|
|
|
txOutput_( image.width( ) , image.height( ) , E_TexType::RGBA8 ) ,
|
|
|
|
rtOutput_( T_RendertargetSetup( ).add( txOutput_ ).create( ) ) ,
|
2017-10-01 18:51:02 +02:00
|
|
|
bloomStrength_( 0.45 ) ,
|
2017-10-05 10:09:34 +02:00
|
|
|
bloomAttenuation_( 0.3 ) ,
|
|
|
|
vignette_{
|
|
|
|
1 , 8 , .5 , 1 , 0 , 1
|
2017-10-05 12:56:52 +02:00
|
|
|
} ,
|
|
|
|
cgLift_{ 0 , 0 , 0 } ,
|
|
|
|
cgGain_{ 1 , 1 , 1 } ,
|
|
|
|
cgGamma_{ 0 , 0 , 0 }
|
2017-10-01 18:51:02 +02:00
|
|
|
{
|
2017-10-04 18:06:39 +02:00
|
|
|
program_ = Globals::Shaders( ).pipeline({
|
|
|
|
"fullscreen.v.glsl" , "combine.f.glsl" });
|
2017-10-01 18:51:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void T_CombinePass::render( )
|
|
|
|
{
|
|
|
|
PSTART( );
|
2017-10-05 18:35:35 +02:00
|
|
|
rtOutput_.activate( );
|
|
|
|
glClearColor( 1 , 0 , 1 , .413f );
|
2017-10-01 18:51:02 +02:00
|
|
|
glClear( GL_COLOR_BUFFER_BIT );
|
2017-10-04 18:06:39 +02:00
|
|
|
if ( program_.valid( ) ) {
|
2017-10-05 10:09:34 +02:00
|
|
|
enum {
|
|
|
|
U_MAIN_INPUT ,
|
|
|
|
U_BLOOM_INPUT ,
|
|
|
|
U_OUTPUT_SIZE ,
|
|
|
|
U_BLOOM_PARAMETERS ,
|
|
|
|
U_VIGNETTE_PARAMETERS_1 ,
|
|
|
|
U_VIGNETTE_PARAMETERS_2 ,
|
2017-10-05 12:56:52 +02:00
|
|
|
U_CG_LIFT ,
|
|
|
|
U_CG_GAIN ,
|
|
|
|
U_CG_GAMMA ,
|
2017-10-05 10:09:34 +02:00
|
|
|
};
|
2017-10-04 11:20:27 +02:00
|
|
|
auto& tm( Globals::Textures( ) );
|
2017-10-02 14:48:16 +02:00
|
|
|
tm.bind( 0 , txImage_ );
|
|
|
|
tm.bind( 1 , txBloom_ );
|
2017-10-04 18:06:39 +02:00
|
|
|
|
|
|
|
const auto id( program_.program( E_ShaderType::FRAGMENT ) );
|
|
|
|
program_.enable( );
|
2017-10-05 10:09:34 +02:00
|
|
|
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 );
|
2017-10-05 12:56:52 +02:00
|
|
|
glProgramUniform3fv( id , U_CG_LIFT , 1 , cgLift_ );
|
|
|
|
glProgramUniform3fv( id , U_CG_GAIN , 1 , cgGain_ );
|
|
|
|
glProgramUniform3fv( id , U_CG_GAMMA , 1 , cgGamma_ );
|
2017-10-04 18:06:39 +02:00
|
|
|
|
|
|
|
glDrawArrays( GL_TRIANGLE_STRIP , 0 , 4 );
|
2017-10-01 18:51:02 +02:00
|
|
|
}
|
|
|
|
PEND( );
|
|
|
|
}
|
|
|
|
|
|
|
|
void T_CombinePass::makeUI( )
|
|
|
|
{
|
2017-10-05 12:56:52 +02:00
|
|
|
using namespace ImGui;
|
|
|
|
if ( !CollapsingHeader( "Combine" ) ) {
|
2017-10-01 18:51:02 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-10-05 12:56:52 +02:00
|
|
|
if ( TreeNode( "combine-bloom" , "Bloom" ) ) {
|
|
|
|
DragFloat( "Strength" , &bloomStrength_ , .001f , 0. , 10 );
|
|
|
|
DragFloat( "Attenuation" , &bloomAttenuation_ , .001f , 0. , 1 );
|
|
|
|
TreePop( );
|
|
|
|
}
|
2017-10-05 10:09:34 +02:00
|
|
|
|
2017-10-05 12:56:52 +02:00
|
|
|
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( );
|
|
|
|
}
|
2017-10-01 18:51:02 +02:00
|
|
|
|
2017-10-05 12:56:52 +02:00
|
|
|
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( );
|
|
|
|
}
|
|
|
|
}
|