demotool/dof.cc

81 lines
2.1 KiB
C++

#include "externals.hh"
#include "utilities.hh"
#include "texture.hh"
#include "rendertarget.hh"
#include "dof.hh"
#include "profiling.hh"
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_FilesWatcher& watcher ,
__rw__ T_Texture& imageInput ,
__rw__ T_Texture& depthInput )
: imageInput_( imageInput ) , depthInput_( depthInput ) ,
spPass1_( GL_FRAGMENT_SHADER , watcher ) ,
spPass2_( GL_FRAGMENT_SHADER , watcher ) ,
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( ) ) ,
filterParams_{ 10 , 2 , 5 , 16 } ,
nSamples_( 16 )
{
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
};
T_TextureBinding tb0( 0 ) , tb1( 1 );
if ( spPass1_.activate( ) && rtPass1_.activate( ) ) {
tb0.set( U_INPUT , imageInput_ );
tb1.set( U_DEPTH , depthInput_ );
tb0.bind( );
tb1.bind( );
glUniform4fv( U_PARAMS , 1 , filterParams_ );
glUniform1f( U_SAMPLES , nSamples_ );
glUniform3f( U_RES_TIME , imageInput_.width( ) ,
imageInput_.height( ) ,
0 );
glRectf( -1 , -1 , 1 , 1 );
}
if ( spPass2_.activate( ) && rtPass2_.activate( ) ) {
tb0.set( U_INPUT , txPass1_ );
tb1.set( U_DEPTH , depthInput_ );
tb0.bind( );
tb1.bind( );
glUniform4fv( U_PARAMS , 1 , filterParams_ );
glUniform1f( U_SAMPLES , nSamples_ );
glUniform3f( U_RES_TIME , imageInput_.width( ) ,
imageInput_.height( ) ,
0 );
glRectf( -1 , -1 , 1 , 1 );
}
PEND( );
}
void T_DoFPass::makeUI( )
{
}