Improve FXAA quality and performance when GL version is greater then 4

Adds gather4 support under GLSL 4.0+
meow-7.2.2
Rye Cogtail 2024-08-23 22:06:28 -04:00 committed by Rye Mutt
parent cbca178256
commit 2ca193ce46
3 changed files with 27 additions and 5 deletions

View File

@ -595,8 +595,6 @@ GLuint LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shader_lev
extra_code_text[extra_code_count++] = strdup("precision highp float;\n");
}
}
extra_code_text[extra_code_count++] = strdup("#define FXAA_GLSL_130 1\n");
}
// Use alpha float to store bit flags

View File

@ -256,6 +256,10 @@ A. Or use FXAA_GREEN_AS_LUMA.
#define FXAA_GLSL_130 0
#endif
/*--------------------------------------------------------------------------*/
#ifndef FXAA_GLSL_400
#define FXAA_GLSL_400 0
#endif
/*--------------------------------------------------------------------------*/
#ifndef FXAA_HLSL_3
#define FXAA_HLSL_3 0
#endif
@ -342,8 +346,8 @@ A. Or use FXAA_GREEN_AS_LUMA.
// 1 = API supports gather4 on alpha channel.
// 0 = API does not support gather4 on alpha channel.
//
#if (FXAA_GLSL_130 == 0)
#define FXAA_GATHER4_ALPHA 0
#if (FXAA_GLSL_400 == 1)
#define FXAA_GATHER4_ALPHA 1
#endif
#if (FXAA_HLSL_5 == 1)
#define FXAA_GATHER4_ALPHA 1
@ -652,7 +656,7 @@ NOTE the other tuning knobs are now in the shader function inputs!
API PORTING
============================================================================*/
#if (FXAA_GLSL_120 == 1) || (FXAA_GLSL_130 == 1)
#if (FXAA_GLSL_120 == 1) || (FXAA_GLSL_130 == 1) || (FXAA_GLSL_400 == 1)
#define FxaaBool bool
#define FxaaDiscard discard
#define FxaaFloat float
@ -714,6 +718,16 @@ NOTE the other tuning knobs are now in the shader function inputs!
#endif
#endif
/*--------------------------------------------------------------------------*/
#if (FXAA_GLSL_400 == 1)
// Requires "#version 400" or better
#define FxaaTexTop(t, p) textureLod(t, p, 0.0)
#define FxaaTexOff(t, p, o, r) textureLodOffset(t, p, 0.0, o)
#define FxaaTexAlpha4(t, p) textureGather(t, p, 3)
#define FxaaTexOffAlpha4(t, p, o) textureGatherOffset(t, p, o, 3)
#define FxaaTexGreen4(t, p) textureGather(t, p, 1)
#define FxaaTexOffGreen4(t, p, o) textureGatherOffset(t, p, o, 1)
#endif
/*--------------------------------------------------------------------------*/
#if (FXAA_HLSL_3 == 1) || (FXAA_360 == 1) || (FXAA_PS3 == 1)
#define FxaaInt2 float2
#define FxaaTex sampler2D

View File

@ -2345,6 +2345,16 @@ bool LLViewerShaderMgr::loadShadersDeferred()
gFXAAProgram.mShaderFiles.clear();
gFXAAProgram.mShaderFiles.push_back(make_pair("deferred/postDeferredV.glsl", GL_VERTEX_SHADER));
gFXAAProgram.mShaderFiles.push_back(make_pair("deferred/fxaaF.glsl", GL_FRAGMENT_SHADER));
if (gGLManager.mGLVersion > 3.9)
{
gFXAAProgram.addPermutation("FXAA_GLSL_400", "1");
}
else
{
gFXAAProgram.addPermutation("FXAA_GLSL_130", "1");
}
gFXAAProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
success = gFXAAProgram.createShader();
llassert(success);