Skip to content

Commit 60fc015

Browse files
committed
renderer: implement luminance-based FXAA
1 parent e6c9f58 commit 60fc015

File tree

5 files changed

+39
-3
lines changed

5 files changed

+39
-3
lines changed

src/engine/renderer/gl_shader.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,16 @@ static std::string GenEngineConstants() {
795795
AddDefine( str, "r_colorGrading", 1 );
796796
}
797797

798+
if ( r_showLuminance.Get() )
799+
{
800+
AddDefine( str, "r_showLuminance", 1 );
801+
}
802+
803+
if ( r_FXAA.Get() )
804+
{
805+
AddDefine( str, "r_FXAA", 1 );
806+
}
807+
798808
if ( r_highPrecisionRendering.Get() ) {
799809
AddDefine( str, "r_highPrecisionRendering", 1 );
800810
}
@@ -3066,4 +3076,4 @@ GlobalUBOProxy::GlobalUBOProxy() :
30663076
u_Tonemap( this ),
30673077
u_TonemapParms( this ),
30683078
u_Exposure( this ) {
3069-
}
3079+
}

src/engine/renderer/glsl_source/cameraEffects_fp.glsl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,5 +111,23 @@ void main()
111111

112112
color.xyz = pow(color.xyz, vec3(u_InverseGamma));
113113

114+
#if defined(r_FXAA) || defined(r_showLuminance)
115+
{
116+
// That luminance vector comes from a comment in fxaa3_11_fp.glsl.
117+
vec3 luminanceVector = vec3( 0.299, 0.587, 0.114 );
118+
119+
float luminance = dot( color.rgb, luminanceVector );
120+
121+
#if defined(r_showLuminance)
122+
color.rgb = vec3( luminance );
123+
#endif
124+
125+
#if defined(r_FXAA)
126+
// Encode luminance in alpha channel.
127+
color.a = luminance;
128+
#endif
129+
}
130+
#endif
131+
114132
outputColor = color;
115133
}

src/engine/renderer/glsl_source/fxaa_fp.glsl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
4242

4343
#define FXAA_PC 1
4444
#define FXAA_QUALITY_PRESET 12
45-
#define FXAA_GREEN_AS_LUMA 1
45+
#define FXAA_GREEN_AS_LUMA 0
4646

4747
#insert fxaa3_11_fp
4848

@@ -56,7 +56,7 @@ out vec4 outputColor;
5656

5757
void main()
5858
{
59-
outputColor = FxaaPixelShader(
59+
vec4 color = FxaaPixelShader(
6060
gl_FragCoord.xy / r_FBufSize, //pos
6161
vec4(0.0), //not used
6262
u_ColorMap, //tex
@@ -74,4 +74,6 @@ void main()
7474
0.0, //not used
7575
vec4(0.0) //not used
7676
);
77+
78+
outputColor = vec4( color.rgb, 1.0f );
7779
}

src/engine/renderer/tr_init.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@ Cvar::Cvar<int> r_rendererAPI( "r_rendererAPI", "Renderer API: 0: OpenGL, 1: Vul
286286
Cvar::Cvar<float> r_bloomBlur( "r_bloomBlur", "Bloom strength", Cvar::NONE, 0.2 );
287287
Cvar::Cvar<int> r_bloomPasses( "r_bloomPasses", "Amount of bloom passes in each direction", Cvar::NONE, 2 );
288288

289+
Cvar::Cvar<bool> r_showLuminance( "r_showLuminance", "Show luminance", Cvar::CHEAT, false );
290+
289291
Cvar::Cvar<bool> r_FXAA( "r_FXAA", "Fast approximate anti-aliasing", Cvar::NONE, false );
290292

291293
Cvar::Range<Cvar::Cvar<int>> r_msaa( "r_msaa", "Amount of MSAA samples. 0 to disable", Cvar::NONE, 0, 0, 64 );
@@ -1210,6 +1212,8 @@ ScreenshotCmd screenshotPNGRegistration("screenshotPNG", ssFormat_t::SSF_PNG, "p
12101212
Cvar::Latch( r_bloom );
12111213
Cvar::Latch( r_ssao );
12121214

1215+
Cvar::Latch( r_showLuminance );
1216+
12131217
Cvar::Latch( r_FXAA );
12141218

12151219
Cvar::Latch( r_msaa );

src/engine/renderer/tr_local.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2780,6 +2780,8 @@ enum
27802780
extern Cvar::Cvar<int> r_bloomPasses;
27812781
extern Cvar::Range<Cvar::Cvar<int>> r_ssao;
27822782

2783+
extern Cvar::Cvar<bool> r_showLuminance;
2784+
27832785
extern Cvar::Cvar<bool> r_FXAA;
27842786

27852787
extern Cvar::Range<Cvar::Cvar<int>> r_msaa;

0 commit comments

Comments
 (0)