2017-10-05 18:35:35 +02:00
|
|
|
#include "externals.hh"
|
|
|
|
#include "fxaa.hh"
|
|
|
|
#include "profiling.hh"
|
|
|
|
#include "globals.hh"
|
|
|
|
|
|
|
|
namespace {
|
2017-11-03 11:55:26 +01:00
|
|
|
static char const* const Name_( "FXAA" );
|
2017-10-05 18:35:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#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( ) );
|
2017-10-06 10:52:33 +02:00
|
|
|
tm.bind( 0 , txInput_ , *tm.sampler( "linear-border" ) );
|
2017-10-05 18:35:35 +02:00
|
|
|
|
|
|
|
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." , ¶meters_[ 0 ] , .001f , 0 , 1 );
|
|
|
|
DragFloat( "Edge threshold" , ¶meters_[ 1 ] , .0001f , .063 , .333 );
|
|
|
|
DragFloat( "Edge threshold min" , ¶meters_[ 2 ] , .0001f , .0312 , .0833 );
|
|
|
|
}
|
|
|
|
|