2017-10-01 18:51:02 +02:00
|
|
|
#include "externals.hh"
|
|
|
|
#include "dof.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_( "DoF" );
|
|
|
|
}
|
|
|
|
|
|
|
|
#define PSTART() T_Profiler::Profiler.start( Name_ )
|
|
|
|
#define PEND() do { glFinish( ); T_Profiler::Profiler.end( Name_ ); } while ( 0 )
|
|
|
|
|
|
|
|
|
|
|
|
T_DoFPass::T_DoFPass(
|
|
|
|
__rw__ T_Texture& imageInput ,
|
|
|
|
__rw__ T_Texture& depthInput )
|
|
|
|
: imageInput_( imageInput ) , depthInput_( depthInput ) ,
|
2017-10-04 11:20:27 +02:00
|
|
|
spPass1_( GL_FRAGMENT_SHADER ) ,
|
|
|
|
spPass2_( GL_FRAGMENT_SHADER ) ,
|
2017-10-01 18:51:02 +02:00
|
|
|
txPass1_( imageInput.width( ) , imageInput.height( ) ,
|
|
|
|
E_TexType::RGB16F ) ,
|
|
|
|
txOutput_( imageInput.width( ) , imageInput.height( ) ,
|
|
|
|
E_TexType::RGB16F ) ,
|
|
|
|
rtPass1_( T_RendertargetSetup( ).add( txPass1_ ).create( ) ) ,
|
|
|
|
rtPass2_( T_RendertargetSetup( ).add( txOutput_ ).create( ) ) ,
|
2017-10-03 09:29:04 +02:00
|
|
|
filterParams_{ 15 , 25 , 100 , 16 } ,
|
2017-10-01 18:51:02 +02:00
|
|
|
nSamples_( 16 )
|
|
|
|
{
|
2017-10-01 19:40:38 +02:00
|
|
|
txPass1_.wrap( E_TexWrap::CLAMP_EDGE );
|
|
|
|
|
2017-10-01 18:51:02 +02:00
|
|
|
spPass1_.addFile( "dof-common.glsl" );
|
|
|
|
spPass1_.addFile( "dof-pass1.glsl" );
|
|
|
|
spPass1_.load( );
|
|
|
|
|
|
|
|
spPass2_.addFile( "dof-common.glsl" );
|
|
|
|
spPass2_.addFile( "dof-pass2.glsl" );
|
|
|
|
spPass2_.load( );
|
|
|
|
}
|
|
|
|
|
|
|
|
void T_DoFPass::render( )
|
|
|
|
{
|
|
|
|
PSTART( );
|
|
|
|
enum {
|
|
|
|
U_INPUT = 0 ,
|
|
|
|
U_DEPTH = 1 ,
|
|
|
|
U_PARAMS = 2 ,
|
|
|
|
U_SAMPLES = 3 ,
|
|
|
|
U_RES_TIME = 4
|
|
|
|
};
|
2017-10-02 14:48:16 +02:00
|
|
|
|
2017-10-04 11:20:27 +02:00
|
|
|
auto& tm( Globals::Textures( ) );
|
2017-10-01 18:51:02 +02:00
|
|
|
if ( spPass1_.activate( ) && rtPass1_.activate( ) ) {
|
2017-10-02 14:48:16 +02:00
|
|
|
glUniform1i( U_INPUT , 0 );
|
|
|
|
glUniform1i( U_DEPTH , 1 );
|
2017-10-01 18:51:02 +02:00
|
|
|
glUniform4fv( U_PARAMS , 1 , filterParams_ );
|
|
|
|
glUniform1f( U_SAMPLES , nSamples_ );
|
|
|
|
glUniform3f( U_RES_TIME , imageInput_.width( ) ,
|
|
|
|
imageInput_.height( ) ,
|
|
|
|
0 );
|
2017-10-02 14:48:16 +02:00
|
|
|
|
|
|
|
tm.bind( 0 , imageInput_ , *tm.sampler( "linear-edge" ) );
|
|
|
|
tm.bind( 1 , depthInput_ , *tm.sampler( "linear-edge" ) );
|
|
|
|
|
2017-10-01 18:51:02 +02:00
|
|
|
glRectf( -1 , -1 , 1 , 1 );
|
|
|
|
}
|
|
|
|
if ( spPass2_.activate( ) && rtPass2_.activate( ) ) {
|
2017-10-02 14:48:16 +02:00
|
|
|
glUniform1i( U_INPUT , 0 );
|
|
|
|
glUniform1i( U_DEPTH , 1 );
|
2017-10-01 18:51:02 +02:00
|
|
|
glUniform4fv( U_PARAMS , 1 , filterParams_ );
|
|
|
|
glUniform1f( U_SAMPLES , nSamples_ );
|
|
|
|
glUniform3f( U_RES_TIME , imageInput_.width( ) ,
|
|
|
|
imageInput_.height( ) ,
|
|
|
|
0 );
|
2017-10-02 14:48:16 +02:00
|
|
|
|
|
|
|
tm.bind( 0 , txPass1_ , *tm.sampler( "linear-edge" ) );
|
|
|
|
|
2017-10-01 18:51:02 +02:00
|
|
|
glRectf( -1 , -1 , 1 , 1 );
|
|
|
|
}
|
|
|
|
PEND( );
|
|
|
|
}
|
|
|
|
|
|
|
|
void T_DoFPass::makeUI( )
|
|
|
|
{
|
2017-10-01 19:22:28 +02:00
|
|
|
if ( !ImGui::CollapsingHeader( "Depth of field" ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::DragFloat( "Sharp distance" , filterParams_ , .25 , 0.25 , 1000 );
|
|
|
|
ImGui::DragFloat( "Sharp range" , &filterParams_[ 1 ] , .1 , 0.1 , 100 );
|
|
|
|
ImGui::DragFloat( "Blur falloff" , &filterParams_[ 2 ] , .5 , 0.5 , 1000 );
|
|
|
|
ImGui::DragFloat( "Max blur" , &filterParams_[ 3 ] , .1 , .1 , 100 );
|
|
|
|
|
|
|
|
ImGui::DragInt( "Samples" , &nSamples_ , .2 , 1 , 32 );
|
2017-10-01 18:51:02 +02:00
|
|
|
}
|