Skip to content

Commit

Permalink
Merge pull request #2466 from RyeMutt/smaa
Browse files Browse the repository at this point in the history
Introduce SMAA and rework post process chain for better visual quality
  • Loading branch information
RyeMutt authored Aug 29, 2024
2 parents 17fed39 + 9c6988c commit 7e58f08
Show file tree
Hide file tree
Showing 32 changed files with 17,835 additions and 322 deletions.
14 changes: 6 additions & 8 deletions indra/llrender/llglslshader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1087,17 +1087,17 @@ void LLGLSLShader::unbind(void)
sCurBoundShaderPtr = NULL;
}

S32 LLGLSLShader::bindTexture(const std::string& uniform, LLTexture* texture, LLTexUnit::eTextureType mode, LLTexUnit::eTextureColorSpace colorspace)
S32 LLGLSLShader::bindTexture(const std::string& uniform, LLTexture* texture, LLTexUnit::eTextureType mode)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER;

S32 channel = 0;
channel = getUniformLocation(uniform);

return bindTexture(channel, texture, mode, colorspace);
return bindTexture(channel, texture, mode);
}

S32 LLGLSLShader::bindTexture(S32 uniform, LLTexture* texture, LLTexUnit::eTextureType mode, LLTexUnit::eTextureColorSpace colorspace)
S32 LLGLSLShader::bindTexture(S32 uniform, LLTexture* texture, LLTexUnit::eTextureType mode)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER;

Expand All @@ -1113,7 +1113,6 @@ S32 LLGLSLShader::bindTexture(S32 uniform, LLTexture* texture, LLTexUnit::eTextu
if (uniform > -1)
{
gGL.getTexUnit(uniform)->bindFast(texture);
gGL.getTexUnit(uniform)->setTextureColorSpace(colorspace);
}

return uniform;
Expand Down Expand Up @@ -1194,7 +1193,7 @@ S32 LLGLSLShader::getTextureChannel(S32 uniform) const
return mTexture[uniform];
}

S32 LLGLSLShader::enableTexture(S32 uniform, LLTexUnit::eTextureType mode, LLTexUnit::eTextureColorSpace space)
S32 LLGLSLShader::enableTexture(S32 uniform, LLTexUnit::eTextureType mode)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER;

Expand All @@ -1211,12 +1210,11 @@ S32 LLGLSLShader::enableTexture(S32 uniform, LLTexUnit::eTextureType mode, LLTex
{
gGL.getTexUnit(index)->activate();
gGL.getTexUnit(index)->enable(mode);
gGL.getTexUnit(index)->setTextureColorSpace(space);
}
return index;
}

S32 LLGLSLShader::disableTexture(S32 uniform, LLTexUnit::eTextureType mode, LLTexUnit::eTextureColorSpace space)
S32 LLGLSLShader::disableTexture(S32 uniform, LLTexUnit::eTextureType mode)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER;

Expand All @@ -1229,7 +1227,7 @@ S32 LLGLSLShader::disableTexture(S32 uniform, LLTexUnit::eTextureType mode, LLTe
S32 index = mTexture[uniform];
if (index != -1 && gGL.getTexUnit(index)->getCurrType() != LLTexUnit::TT_NONE)
{
if (gDebugGL && gGL.getTexUnit(index)->getCurrType() != mode && gGL.getTexUnit(index)->getCurrColorSpace() != space)
if (gDebugGL && gGL.getTexUnit(index)->getCurrType() != mode)
{
if (gDebugSession)
{
Expand Down
12 changes: 8 additions & 4 deletions indra/llrender/llglslshader.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,10 @@ class LLGLSLShader

void clearPermutations();
void addPermutation(std::string name, std::string value);
void addPermutations(const std::map<std::string, std::string>& defines)
{
mDefines.insert(defines.begin(), defines.end());
}
void removePermutation(std::string name);

void addConstant(const LLGLSLShader::eShaderConsts shader_const);
Expand All @@ -249,16 +253,16 @@ class LLGLSLShader
//if given texture uniform is active in the shader,
//the corresponding channel will be active upon return
//returns channel texture is enabled in from [0-MAX)
S32 enableTexture(S32 uniform, LLTexUnit::eTextureType mode = LLTexUnit::TT_TEXTURE, LLTexUnit::eTextureColorSpace space = LLTexUnit::TCS_LINEAR);
S32 disableTexture(S32 uniform, LLTexUnit::eTextureType mode = LLTexUnit::TT_TEXTURE, LLTexUnit::eTextureColorSpace space = LLTexUnit::TCS_LINEAR);
S32 enableTexture(S32 uniform, LLTexUnit::eTextureType mode = LLTexUnit::TT_TEXTURE);
S32 disableTexture(S32 uniform, LLTexUnit::eTextureType mode = LLTexUnit::TT_TEXTURE);

// get the texture channel of the given uniform, or -1 if uniform is not used as a texture
S32 getTextureChannel(S32 uniform) const;

// bindTexture returns the texture unit we've bound the texture to.
// You can reuse the return value to unbind a texture when required.
S32 bindTexture(const std::string& uniform, LLTexture* texture, LLTexUnit::eTextureType mode = LLTexUnit::TT_TEXTURE, LLTexUnit::eTextureColorSpace space = LLTexUnit::TCS_LINEAR);
S32 bindTexture(S32 uniform, LLTexture* texture, LLTexUnit::eTextureType mode = LLTexUnit::TT_TEXTURE, LLTexUnit::eTextureColorSpace space = LLTexUnit::TCS_LINEAR);
S32 bindTexture(const std::string& uniform, LLTexture* texture, LLTexUnit::eTextureType mode = LLTexUnit::TT_TEXTURE);
S32 bindTexture(S32 uniform, LLTexture* texture, LLTexUnit::eTextureType mode = LLTexUnit::TT_TEXTURE);
S32 bindTexture(const std::string& uniform, LLRenderTarget* texture, bool depth = false, LLTexUnit::eTextureFilterOptions mode = LLTexUnit::TFO_BILINEAR);
S32 bindTexture(S32 uniform, LLRenderTarget* texture, bool depth = false, LLTexUnit::eTextureFilterOptions mode = LLTexUnit::TFO_BILINEAR, U32 index = 0);
S32 unbindTexture(const std::string& uniform, LLTexUnit::eTextureType mode = LLTexUnit::TT_TEXTURE);
Expand Down
17 changes: 1 addition & 16 deletions indra/llrender/llrender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ static const GLenum sGLBlendFactor[] =

LLTexUnit::LLTexUnit(S32 index)
: mCurrTexType(TT_NONE),
mCurrColorScale(1), mCurrAlphaScale(1), mCurrTexture(0), mTexColorSpace(TCS_LINEAR),
mCurrColorScale(1), mCurrAlphaScale(1), mCurrTexture(0),
mHasMipMaps(false),
mIndex(index)
{
Expand Down Expand Up @@ -145,8 +145,6 @@ void LLTexUnit::refreshState(void)
{
glBindTexture(GL_TEXTURE_2D, 0);
}

setTextureColorSpace(mTexColorSpace);
}

void LLTexUnit::activate(void)
Expand Down Expand Up @@ -241,7 +239,6 @@ bool LLTexUnit::bind(LLTexture* texture, bool for_rendering, bool forceBind)
setTextureAddressMode(gl_tex->mAddressMode);
setTextureFilteringOption(gl_tex->mFilterOption);
}
setTextureColorSpace(mTexColorSpace);
}
}
else
Expand Down Expand Up @@ -318,7 +315,6 @@ bool LLTexUnit::bind(LLImageGL* texture, bool for_rendering, bool forceBind, S32
setTextureFilteringOption(texture->mFilterOption);
stop_glerror();
}
setTextureColorSpace(mTexColorSpace);
}

stop_glerror();
Expand Down Expand Up @@ -354,7 +350,6 @@ bool LLTexUnit::bind(LLCubeMap* cubeMap)
setTextureAddressMode(cubeMap->mImages[0]->mAddressMode);
setTextureFilteringOption(cubeMap->mImages[0]->mFilterOption);
}
setTextureColorSpace(mTexColorSpace);
return true;
}
else
Expand Down Expand Up @@ -403,7 +398,6 @@ bool LLTexUnit::bindManual(eTextureType type, U32 texture, bool hasMips)
mCurrTexture = texture;
glBindTexture(sGLTextureType[type], texture);
mHasMipMaps = hasMips;
setTextureColorSpace(mTexColorSpace);
}
return true;
}
Expand All @@ -424,8 +418,6 @@ void LLTexUnit::unbind(eTextureType type)
{
mCurrTexture = 0;

// Always make sure our texture color space is reset to linear. SRGB sampling should be opt-in in the vast majority of cases. Also prevents color space "popping".
mTexColorSpace = TCS_LINEAR;
if (type == LLTexUnit::TT_TEXTURE)
{
glBindTexture(sGLTextureType[type], sWhiteTexture);
Expand All @@ -447,8 +439,6 @@ void LLTexUnit::unbindFast(eTextureType type)
{
mCurrTexture = 0;

// Always make sure our texture color space is reset to linear. SRGB sampling should be opt-in in the vast majority of cases. Also prevents color space "popping".
mTexColorSpace = TCS_LINEAR;
if (type == LLTexUnit::TT_TEXTURE)
{
glBindTexture(sGLTextureType[type], sWhiteTexture);
Expand Down Expand Up @@ -642,11 +632,6 @@ void LLTexUnit::debugTextureUnit(void)
}
}

void LLTexUnit::setTextureColorSpace(eTextureColorSpace space)
{
mTexColorSpace = space;
}

LLLightState::LLLightState(S32 index)
: mIndex(index),
mEnabled(false),
Expand Down
5 changes: 0 additions & 5 deletions indra/llrender/llrender.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,17 +219,12 @@ class LLTexUnit

void setHasMipMaps(bool hasMips) { mHasMipMaps = hasMips; }

void setTextureColorSpace(eTextureColorSpace space);

eTextureColorSpace getCurrColorSpace() { return mTexColorSpace; }

protected:
friend class LLRender;

S32 mIndex;
U32 mCurrTexture;
eTextureType mCurrTexType;
eTextureColorSpace mTexColorSpace;
S32 mCurrColorScale;
S32 mCurrAlphaScale;
bool mHasMipMaps;
Expand Down
1 change: 0 additions & 1 deletion indra/llrender/llrendertarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,6 @@ void LLRenderTarget::bindTexture(U32 index, S32 channel, LLTexUnit::eTextureFilt
}

gGL.getTexUnit(channel)->setTextureFilteringOption(filter_options);
gGL.getTexUnit(channel)->setTextureColorSpace(isSRGB ? LLTexUnit::TCS_SRGB : LLTexUnit::TCS_LINEAR);
}

void LLRenderTarget::flush()
Expand Down
14 changes: 14 additions & 0 deletions indra/llrender/llshadermgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,15 @@ GLuint LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shader_lev
}
}

if (type == GL_FRAGMENT_SHADER)
{
extra_code_text[extra_code_count++] = strdup("#define FRAGMENT_SHADER 1\n");
}
else
{
extra_code_text[extra_code_count++] = strdup("#define VERTEX_SHADER 1\n");
}

// Use alpha float to store bit flags
// See: C++: addDeferredAttachment(), shader: frag_data[2]
extra_code_text[extra_code_count++] = strdup("#define GBUFFER_FLAG_SKIP_ATMOS 0.0 \n"); // atmo kill
Expand Down Expand Up @@ -1468,6 +1477,11 @@ void LLShaderMgr::initAttribsAndUniforms()

mReservedUniforms.push_back("debug_normal_draw_length");

mReservedUniforms.push_back("edgesTex");
mReservedUniforms.push_back("areaTex");
mReservedUniforms.push_back("searchTex");
mReservedUniforms.push_back("blendTex");

llassert(mReservedUniforms.size() == END_RESERVED_UNIFORMS);

std::set<std::string> dupe_check;
Expand Down
5 changes: 5 additions & 0 deletions indra/llrender/llshadermgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,11 @@ class LLShaderMgr

DEBUG_NORMAL_DRAW_LENGTH, // "debug_normal_draw_length"

SMAA_EDGE_TEX, // "edgesTex"
SMAA_AREA_TEX, // "areaTex"
SMAA_SEARCH_TEX, // "searchTex"
SMAA_BLEND_TEX, // "blendTex"

END_RESERVED_UNIFORMS
} eGLSLReservedUniforms;
// clang-format on
Expand Down
Loading

0 comments on commit 7e58f08

Please sign in to comment.