FXAA
This commit is contained in:
parent
883dd9e2a6
commit
7483769714
11 changed files with 2213 additions and 16 deletions
15
Makefile
15
Makefile
|
@ -13,23 +13,24 @@ DEMO = \
|
||||||
main.cc \
|
main.cc \
|
||||||
imgui_impl_sdl.cc \
|
imgui_impl_sdl.cc \
|
||||||
\
|
\
|
||||||
filewatcher.cc \
|
|
||||||
window.cc \
|
|
||||||
utilities.cc \
|
utilities.cc \
|
||||||
texture.cc \
|
texture.cc \
|
||||||
rendertarget.cc \
|
rendertarget.cc \
|
||||||
shaders.cc \
|
|
||||||
camera.cc \
|
camera.cc \
|
||||||
demo.cc \
|
\
|
||||||
|
filewatcher.cc \
|
||||||
|
window.cc \
|
||||||
globals.cc \
|
globals.cc \
|
||||||
|
profiling.cc \
|
||||||
|
shaders.cc \
|
||||||
|
\
|
||||||
|
demo.cc \
|
||||||
\
|
\
|
||||||
raymarcher.cc \
|
raymarcher.cc \
|
||||||
\
|
|
||||||
bloom.cc \
|
bloom.cc \
|
||||||
dof.cc \
|
dof.cc \
|
||||||
combine.cc \
|
combine.cc \
|
||||||
\
|
fxaa.cc
|
||||||
profiling.cc
|
|
||||||
|
|
||||||
|
|
||||||
IMGUI_OBJS = $(addprefix $(OUTDIR)/, $(addsuffix .o, $(basename $(IMGUI))))
|
IMGUI_OBJS = $(addprefix $(OUTDIR)/, $(addsuffix .o, $(basename $(IMGUI))))
|
||||||
|
|
|
@ -16,6 +16,8 @@ T_CombinePass::T_CombinePass(
|
||||||
__rw__ T_Texture& image ,
|
__rw__ T_Texture& image ,
|
||||||
__rw__ T_Texture& bloom )
|
__rw__ T_Texture& bloom )
|
||||||
: txImage_( image ) , txBloom_( bloom ) ,
|
: txImage_( image ) , txBloom_( bloom ) ,
|
||||||
|
txOutput_( image.width( ) , image.height( ) , E_TexType::RGBA8 ) ,
|
||||||
|
rtOutput_( T_RendertargetSetup( ).add( txOutput_ ).create( ) ) ,
|
||||||
bloomStrength_( 0.45 ) ,
|
bloomStrength_( 0.45 ) ,
|
||||||
bloomAttenuation_( 0.3 ) ,
|
bloomAttenuation_( 0.3 ) ,
|
||||||
vignette_{
|
vignette_{
|
||||||
|
@ -32,8 +34,8 @@ T_CombinePass::T_CombinePass(
|
||||||
void T_CombinePass::render( )
|
void T_CombinePass::render( )
|
||||||
{
|
{
|
||||||
PSTART( );
|
PSTART( );
|
||||||
T_Rendertarget::MainOutput( );
|
rtOutput_.activate( );
|
||||||
glClearColor( 1 , 0 , 1 , 1 );
|
glClearColor( 1 , 0 , 1 , .413f );
|
||||||
glClear( GL_COLOR_BUFFER_BIT );
|
glClear( GL_COLOR_BUFFER_BIT );
|
||||||
if ( program_.valid( ) ) {
|
if ( program_.valid( ) ) {
|
||||||
enum {
|
enum {
|
||||||
|
|
|
@ -16,10 +16,16 @@ struct T_CombinePass
|
||||||
void render( );
|
void render( );
|
||||||
void makeUI( );
|
void makeUI( );
|
||||||
|
|
||||||
|
T_Texture& output( )
|
||||||
|
{ return txOutput_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
T_Texture& txImage_;
|
T_Texture& txImage_;
|
||||||
T_Texture& txBloom_;
|
T_Texture& txBloom_;
|
||||||
|
|
||||||
|
T_Texture txOutput_;
|
||||||
|
T_Rendertarget rtOutput_;
|
||||||
|
|
||||||
T_ShaderPipeline program_;
|
T_ShaderPipeline program_;
|
||||||
|
|
||||||
float bloomStrength_;
|
float bloomStrength_;
|
||||||
|
|
4
demo.cc
4
demo.cc
|
@ -18,6 +18,8 @@ bool T_Demo::initialise( )
|
||||||
raymarcher->output( ) );
|
raymarcher->output( ) );
|
||||||
combine = std::make_unique< T_CombinePass >(
|
combine = std::make_unique< T_CombinePass >(
|
||||||
dof->output( ) , bloom->output( ) );
|
dof->output( ) , bloom->output( ) );
|
||||||
|
fxaa = std::make_unique< T_FXAAPass >(
|
||||||
|
combine->output( ) );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,6 +29,7 @@ void T_Demo::makeUI( )
|
||||||
dof->makeUI( );
|
dof->makeUI( );
|
||||||
bloom->makeUI( );
|
bloom->makeUI( );
|
||||||
combine->makeUI( );
|
combine->makeUI( );
|
||||||
|
fxaa->makeUI( );
|
||||||
}
|
}
|
||||||
|
|
||||||
void T_Demo::render( )
|
void T_Demo::render( )
|
||||||
|
@ -35,6 +38,7 @@ void T_Demo::render( )
|
||||||
dof->render( );
|
dof->render( );
|
||||||
bloom->render( );
|
bloom->render( );
|
||||||
combine->render( );
|
combine->render( );
|
||||||
|
fxaa->render( );
|
||||||
}
|
}
|
||||||
|
|
||||||
void T_Demo::handleDND(
|
void T_Demo::handleDND(
|
||||||
|
|
2
demo.hh
2
demo.hh
|
@ -4,6 +4,7 @@
|
||||||
#include "dof.hh"
|
#include "dof.hh"
|
||||||
#include "bloom.hh"
|
#include "bloom.hh"
|
||||||
#include "combine.hh"
|
#include "combine.hh"
|
||||||
|
#include "fxaa.hh"
|
||||||
#include "profiling.hh"
|
#include "profiling.hh"
|
||||||
|
|
||||||
|
|
||||||
|
@ -43,4 +44,5 @@ struct T_Demo
|
||||||
std::unique_ptr< T_DoFPass > dof;
|
std::unique_ptr< T_DoFPass > dof;
|
||||||
std::unique_ptr< T_BloomPass > bloom;
|
std::unique_ptr< T_BloomPass > bloom;
|
||||||
std::unique_ptr< T_CombinePass > combine;
|
std::unique_ptr< T_CombinePass > combine;
|
||||||
|
std::unique_ptr< T_FXAAPass > fxaa;
|
||||||
};
|
};
|
||||||
|
|
61
fxaa.cc
Normal file
61
fxaa.cc
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
#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." , ¶meters_[ 0 ] , .001f , 0 , 1 );
|
||||||
|
DragFloat( "Edge threshold" , ¶meters_[ 1 ] , .0001f , .063 , .333 );
|
||||||
|
DragFloat( "Edge threshold min" , ¶meters_[ 2 ] , .0001f , .0312 , .0833 );
|
||||||
|
}
|
||||||
|
|
22
fxaa.hh
Normal file
22
fxaa.hh
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "rendertarget.hh"
|
||||||
|
#include "shaders.hh"
|
||||||
|
|
||||||
|
|
||||||
|
struct T_FXAAPass
|
||||||
|
{
|
||||||
|
T_FXAAPass( ) = delete;
|
||||||
|
T_FXAAPass( T_FXAAPass const& ) = delete;
|
||||||
|
T_FXAAPass( T_FXAAPass&& ) = delete;
|
||||||
|
|
||||||
|
T_FXAAPass( __rw__ T_Texture& input );
|
||||||
|
|
||||||
|
void render( );
|
||||||
|
void makeUI( );
|
||||||
|
|
||||||
|
private:
|
||||||
|
T_Texture& txInput_;
|
||||||
|
T_ShaderPipeline program_;
|
||||||
|
float parameters_[ 3 ];
|
||||||
|
};
|
6
main.cc
6
main.cc
|
@ -188,10 +188,16 @@ void T_Main::render( )
|
||||||
Globals::Profiler( ).start( "Render" );
|
Globals::Profiler( ).start( "Render" );
|
||||||
demo->render( );
|
demo->render( );
|
||||||
glFinish( ); Globals::Profiler( ).end( "Render" );
|
glFinish( ); Globals::Profiler( ).end( "Render" );
|
||||||
|
} else {
|
||||||
|
T_Rendertarget::MainOutput( );
|
||||||
|
glClearColor( 0 , 0 , 0 , 1 );
|
||||||
|
glClear( GL_COLOR_BUFFER_BIT );
|
||||||
}
|
}
|
||||||
|
T_Rendertarget::MainOutput( );
|
||||||
glUseProgram( 0 );
|
glUseProgram( 0 );
|
||||||
glBindProgramPipeline( 0 );
|
glBindProgramPipeline( 0 );
|
||||||
Globals::Textures( ).reset( );
|
Globals::Textures( ).reset( );
|
||||||
|
glClearColor( 0 , 0 , 0 , 1 );
|
||||||
ImGui::Render( );
|
ImGui::Render( );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
2047
shaders/chunks/fxaa-3.11.glsl
Normal file
2047
shaders/chunks/fxaa-3.11.glsl
Normal file
File diff suppressed because it is too large
Load diff
|
@ -1,6 +1,7 @@
|
||||||
#version 450 core
|
#version 450 core
|
||||||
|
|
||||||
//! type fragment
|
//! type fragment
|
||||||
|
//! include lib/utils.glsl
|
||||||
|
|
||||||
layout( location = 0 ) uniform sampler2D u_MainInput;
|
layout( location = 0 ) uniform sampler2D u_MainInput;
|
||||||
layout( location = 1 ) uniform sampler2D u_BlurInput;
|
layout( location = 1 ) uniform sampler2D u_BlurInput;
|
||||||
|
@ -20,13 +21,13 @@ layout( location = 8 ) uniform vec3 u_ColorGamma;
|
||||||
#define uVigApplyMax (u_Vignette2.y)
|
#define uVigApplyMax (u_Vignette2.y)
|
||||||
|
|
||||||
|
|
||||||
layout( location = 0 ) out vec3 o_Color;
|
layout( location = 0 ) out vec4 o_Color;
|
||||||
|
|
||||||
void main( void )
|
void main( void )
|
||||||
{
|
{
|
||||||
vec2 pos = gl_FragCoord.xy / u_OutputSize;
|
vec2 pos = gl_FragCoord.xy / u_OutputSize;
|
||||||
float f = u_Bloom.x;
|
float f = u_Bloom.x;
|
||||||
o_Color = textureLod( u_MainInput , pos , 0 ).rgb;
|
vec3 color = textureLod( u_MainInput , pos , 0 ).rgb;
|
||||||
|
|
||||||
// Bloom
|
// Bloom
|
||||||
vec3 bloom = vec3( 0 );
|
vec3 bloom = vec3( 0 );
|
||||||
|
@ -34,10 +35,10 @@ void main( void )
|
||||||
bloom += f * textureLod( u_BlurInput , pos , i ).rgb;
|
bloom += f * textureLod( u_BlurInput , pos , i ).rgb;
|
||||||
f = pow( f , u_Bloom.y + 1 );
|
f = pow( f , u_Bloom.y + 1 );
|
||||||
}
|
}
|
||||||
o_Color = o_Color + bloom / 2.2;
|
color = color + bloom / 2.2;
|
||||||
|
|
||||||
// Color grading
|
// Color grading
|
||||||
o_Color = ( o_Color * ( u_ColorGain - u_ColorLift ) ) + u_ColorLift;
|
color = ( color * ( u_ColorGain - u_ColorLift ) ) + u_ColorLift;
|
||||||
|
|
||||||
// Vignette
|
// Vignette
|
||||||
vec2 vShape = pow( abs( pos * 2 - 1 ) * uVigShapeMul ,
|
vec2 vShape = pow( abs( pos * 2 - 1 ) * uVigShapeMul ,
|
||||||
|
@ -45,12 +46,14 @@ void main( void )
|
||||||
float vignette = 1 - pow(
|
float vignette = 1 - pow(
|
||||||
2 * ( uVigAspect * vShape.x + ( 1 - uVigAspect) * vShape.y ) ,
|
2 * ( uVigAspect * vShape.x + ( 1 - uVigAspect) * vShape.y ) ,
|
||||||
1 / ( uVigShapePow * uVigShapeReverse ) );
|
1 / ( uVigShapePow * uVigShapeReverse ) );
|
||||||
o_Color *= uVigApplyBase + smoothstep(
|
color *= uVigApplyBase + smoothstep(
|
||||||
uVigApplyBase , uVigApplyBase + uVigApplyMax , vignette );
|
uVigApplyBase , uVigApplyBase + uVigApplyMax , vignette );
|
||||||
|
|
||||||
// Reinhart
|
// Reinhart
|
||||||
o_Color = o_Color / ( o_Color + 1. );
|
color = color / ( color + 1. );
|
||||||
|
|
||||||
// Gamma
|
// Gamma
|
||||||
o_Color = pow( o_Color , vec3( 1 ) / ( u_ColorGamma + 2.2 ) );
|
color = pow( color , vec3( 1 ) / ( u_ColorGamma + 2.2 ) );
|
||||||
|
|
||||||
|
o_Color = vec4( color , M_Luminosity( color ) );
|
||||||
}
|
}
|
||||||
|
|
43
shaders/fxaa.f.glsl
Normal file
43
shaders/fxaa.f.glsl
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
#version 450 core
|
||||||
|
|
||||||
|
//! type fragment
|
||||||
|
|
||||||
|
#define FXAA_PC 1
|
||||||
|
#define FXAA_GLSL_130 1
|
||||||
|
#define FXAA_FAST_PIXEL_OFFSET 1
|
||||||
|
#define FXAA_GATHER4_ALPHA 1
|
||||||
|
#define FXAA_QUALITY__PRESET 39
|
||||||
|
|
||||||
|
//! include chunks/fxaa-3.11.glsl
|
||||||
|
|
||||||
|
layout( location = 0 ) uniform sampler2D u_Input;
|
||||||
|
layout( location = 1 ) uniform vec2 u_Resolution;
|
||||||
|
layout( location = 2 ) uniform vec3 u_Parameters;
|
||||||
|
|
||||||
|
#define uSPQuality (u_Parameters.x)
|
||||||
|
#define uEdgeThreshold (u_Parameters.y)
|
||||||
|
#define uEdgeThresholdMin (u_Parameters.z)
|
||||||
|
|
||||||
|
layout( location = 0 ) out vec4 o_Color;
|
||||||
|
|
||||||
|
void main( void )
|
||||||
|
{
|
||||||
|
o_Color = FxaaPixelShader(
|
||||||
|
( gl_FragCoord.xy / u_Resolution ) , // pos (vec2)
|
||||||
|
vec4( 0 ) , // unused (vec4)
|
||||||
|
u_Input , // input texture
|
||||||
|
u_Input , // (unused) input texture
|
||||||
|
u_Input , // (unused) input texture
|
||||||
|
vec2( 1 ) / u_Resolution , // 1/resolution (vec2)
|
||||||
|
vec4( 0 ) , // unused (vec4)
|
||||||
|
vec4( 0 ) , // unused (vec4)
|
||||||
|
vec4( 0 ) , // unused (vec4)
|
||||||
|
uSPQuality , // sub-pixel quality (float in [0;1])
|
||||||
|
uEdgeThreshold , // edge threshold (float, [.063;.333], lower = better)
|
||||||
|
uEdgeThresholdMin , // edge threshold min (float, [0.0312;0.0833],
|
||||||
|
// higher = better)
|
||||||
|
0 , // unused (float)
|
||||||
|
0 , // unused (float)
|
||||||
|
0 , // unused (float)
|
||||||
|
vec4( 0 ) ); // unused (vec4)
|
||||||
|
}
|
Loading…
Reference in a new issue