demotool/fxaa.cc

62 lines
1.4 KiB
C++
Raw Normal View History

2017-10-05 18:35:35 +02:00
#include "externals.hh"
#include "fxaa.hh"
#include "profiling.hh"
#include "globals.hh"
namespace {
static const std::string Name_( "FXAA" );
}
#define PSTART() Globals::Profiler( ).start( Name_ )
#define PEND() do { glFinish( ); Globals::Profiler( ).end( Name_ ); } while ( 0 )
T_FXAAPass::T_FXAAPass(
__rw__ T_Texture& input )
: txInput_( input ) ,
parameters_{ .5 , .166 , .0833 }
{
program_ = Globals::Shaders( ).pipeline({
"fullscreen.v.glsl" , "fxaa.f.glsl" });
}
void T_FXAAPass::render( )
{
PSTART( );
T_Rendertarget::MainOutput( );
glClearColor( 1 , 0 , 1 , 1 );
glClear( GL_COLOR_BUFFER_BIT );
if ( program_.valid( ) ) {
enum {
U_INPUT ,
U_RESOLUTION ,
U_PARAMETERS ,
};
auto& tm( Globals::Textures( ) );
tm.bind( 0 , txInput_ );
const auto id( program_.program( E_ShaderType::FRAGMENT ) );
program_.enable( );
glProgramUniform1i( id , U_INPUT , 0 );
glProgramUniform2f( id , U_RESOLUTION ,
txInput_.width( ) , txInput_.height( ) );
glProgramUniform3fv( id , U_PARAMETERS , 1 , parameters_ );
glDrawArrays( GL_TRIANGLE_STRIP , 0 , 4 );
}
PEND( );
}
void T_FXAAPass::makeUI( )
{
using namespace ImGui;
if ( !CollapsingHeader( "FXAA" ) ) {
return;
}
DragFloat( "Sub-pixel q." , &parameters_[ 0 ] , .001f , 0 , 1 );
DragFloat( "Edge threshold" , &parameters_[ 1 ] , .0001f , .063 , .333 );
DragFloat( "Edge threshold min" , &parameters_[ 2 ] , .0001f , .0312 , .0833 );
}