diff options
author | Ptolemy <ptolemy@lindenlab.com> | 2021-04-29 08:41:50 -0700 |
---|---|---|
committer | Ptolemy <ptolemy@lindenlab.com> | 2021-04-29 08:42:55 -0700 |
commit | 7c3a511935a16e0e99b8a5a57edd69a9290465a2 (patch) | |
tree | 2328493e7186e095dd1fd8617bfc55e13656c16c | |
parent | 26f3c078363e3a8bd0ee284c7cd54e9f2b979e7b (diff) |
SL-14113: Remove magic numbers. Take advantage of existing shader #defines injection by extending shader loading to make use of addConstant() instead of hard-coding magic number constants in each GLSL file.
10 files changed, 48 insertions, 8 deletions
diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index 74cfa60b27..458f83aabe 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -62,6 +62,23 @@ U32 LLGLSLShader::sTotalDrawCalls = 0; LLGLSLShader gUIProgram; LLGLSLShader gSolidColorProgram; +// NOTE:Keep gShaderConsts* and LLGLSLShader::ShaderConsts_e in sync! +const std::string gShaderConstsKey[ LLGLSLShader::NUM_SHADER_CONSTS ] = +{ + "LL_SHADER_CONST_CLOUD_DEPTH" + , "LL_SHADER_CONST_MOON_DEPTH" + , "LL_SHADER_CONST_STAR_DEPTH" +}; + +// NOTE:Keep gShaderConsts* and LLGLSLShader::ShaderConsts_e in sync! +const std::string gShaderConstsVal[ LLGLSLShader::NUM_SHADER_CONSTS ] = +{ + "0.999985" // SHADER_CONST_CLOUD_DEPTH // SL-14113 + , "0.999985" // SHADER_CONST_MOON_DEPTH // SL-14113 + , "0.999995" // SHADER_CONST_STAR_DEPTH // SL-14113 +}; + + BOOL shouldChange(const LLVector4& v1, const LLVector4& v2) { return v1 != v2; @@ -755,6 +772,11 @@ void LLGLSLShader::addPermutation(std::string name, std::string value) mDefines[name] = value; } +void LLGLSLShader::addConstant( const LLGLSLShader::eShaderConsts shader_const ) +{ + addPermutation( gShaderConstsKey[ shader_const ], gShaderConstsVal[ shader_const ] ); +} + void LLGLSLShader::removePermutation(std::string name) { mDefines[name].erase(); diff --git a/indra/llrender/llglslshader.h b/indra/llrender/llglslshader.h index 7cf6d3c941..35e796e961 100644 --- a/indra/llrender/llglslshader.h +++ b/indra/llrender/llglslshader.h @@ -67,6 +67,14 @@ public: class LLGLSLShader { public: + // NOTE:Keep gShaderConsts and LLGLSLShader::ShaderConsts_e in sync! + enum eShaderConsts + { + SHADER_CONST_CLOUD_DEPTH + , SHADER_CONST_MOON_DEPTH + , SHADER_CONST_STAR_DEPTH + , NUM_SHADER_CONSTS + }; enum { @@ -149,7 +157,9 @@ public: void clearPermutations(); void addPermutation(std::string name, std::string value); void removePermutation(std::string name); - + + void addConstant( const LLGLSLShader::eShaderConsts shader_const ); + //enable/disable texture channel for specified uniform //if given texture uniform is active in the shader, //the corresponding channel will be active upon return diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl index 187fed72e1..ad8ab771b8 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl @@ -126,6 +126,6 @@ void main() frag_data[1] = vec4(0.0,0.0,0.0,0.0); frag_data[2] = vec4(0,0,0,1); - gl_FragDepth = 0.999985; // SL-14113 Stars and Clouds need same depth + gl_FragDepth = LL_SHADER_CONST_CLOUD_DEPTH; // SL-14113 Stars and Clouds need same depth } diff --git a/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl index 5906194437..ffeaf2b600 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl @@ -74,6 +74,6 @@ void main() frag_data[1] = vec4(0.0); frag_data[2] = vec4(0.0f); - gl_FragDepth = 0.999985f; + gl_FragDepth = LL_SHADER_CONST_MOON_DEPTH; // SL-14113 } diff --git a/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl b/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl index b028c40ed9..8d9c7e3507 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl @@ -67,6 +67,6 @@ void main() frag_data[1] = vec4(0.0f); frag_data[2] = vec4(0.0, 1.0, 0.0, 1.0); - gl_FragDepth = 0.999995f; // SL-14113 Moon Haze -- Stars need to depth test behind the moon + gl_FragDepth = LL_SHADER_CONST_STAR_DEPTH; // SL-14113 Moon Haze -- Stars need to depth test behind the moon } diff --git a/indra/newview/app_settings/shaders/class1/environment/moonF.glsl b/indra/newview/app_settings/shaders/class1/environment/moonF.glsl index e1592c19fb..983cd17979 100644 --- a/indra/newview/app_settings/shaders/class1/environment/moonF.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/moonF.glsl @@ -47,5 +47,5 @@ void main() discard; frag_color = color; - gl_FragDepth = 0.999985f; // SL-14113 Moon is infront of stars + gl_FragDepth = LL_SHADER_CONST_MOON_DEPTH; // SL-14113 Moon is infront of stars } diff --git a/indra/newview/app_settings/shaders/class1/environment/starsF.glsl b/indra/newview/app_settings/shaders/class1/environment/starsF.glsl index 95ab4cbf8b..e1a9cc6387 100644 --- a/indra/newview/app_settings/shaders/class1/environment/starsF.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/starsF.glsl @@ -47,5 +47,5 @@ void main() color.a *= max(custom_alpha, vertex_color.a); frag_color = color; - gl_FragDepth = 0.999995f; // SL-14113 Moon Haze -- Stars need to depth test behind the moon + gl_FragDepth = LL_SHADER_CONST_STAR_DEPTH; // SL-14113 Moon Haze -- Stars need to depth test behind the moon } diff --git a/indra/newview/app_settings/shaders/class1/windlight/moonF.glsl b/indra/newview/app_settings/shaders/class1/windlight/moonF.glsl index 327accbd3b..293e09620f 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/moonF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/moonF.glsl @@ -68,6 +68,6 @@ void main() c.rgb = scaleSoftClip(c.rgb); frag_color = vec4(c.rgb, c.a); - gl_FragDepth = 0.999985f; // SL-14113 + gl_FragDepth = LL_SHADER_CONST_MOON_DEPTH; // SL-14113 } diff --git a/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl index 1c592402d4..ec53ae75f9 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl @@ -132,6 +132,6 @@ void main() // camera above water: class1\deferred\cloudsF.glsl // camera below water: class2\windlight\coudsV.glsl // See: starsV.glsl, cloudsV.glsl, moonF.glsl - gl_FragDepth = 0.999985; + gl_FragDepth = LL_SHADER_CONST_CLOUD_DEPTH; } diff --git a/indra/newview/llviewershadermgr.cpp b/indra/newview/llviewershadermgr.cpp index 8eb57799c9..1dcd9289ef 100644 --- a/indra/newview/llviewershadermgr.cpp +++ b/indra/newview/llviewershadermgr.cpp @@ -1063,6 +1063,7 @@ BOOL LLViewerShaderMgr::loadShadersEnvironment() gStarsProgram.mShaderFiles.push_back(make_pair("environment/starsV.glsl", GL_VERTEX_SHADER_ARB)); gStarsProgram.mShaderFiles.push_back(make_pair("environment/starsF.glsl", GL_FRAGMENT_SHADER_ARB)); gStarsProgram.mShaderLevel = mShaderLevel[SHADER_ENVIRONMENT]; + gStarsProgram.addConstant( LLGLSLShader::SHADER_CONST_STAR_DEPTH ); // SL-14113 success = gStarsProgram.createShader(NULL, NULL); llassert(success); } @@ -1074,8 +1075,10 @@ BOOL LLViewerShaderMgr::loadShadersEnvironment() gMoonProgram.mShaderFiles.push_back(make_pair("environment/moonV.glsl", GL_VERTEX_SHADER_ARB)); gMoonProgram.mShaderFiles.push_back(make_pair("environment/moonF.glsl", GL_FRAGMENT_SHADER_ARB)); gMoonProgram.mShaderLevel = mShaderLevel[SHADER_ENVIRONMENT]; + gMoonProgram.addConstant( LLGLSLShader::SHADER_CONST_MOON_DEPTH ); // SL-14113 success = gMoonProgram.createShader(NULL, NULL); if (success) + { gMoonProgram.bind(); gMoonProgram.uniform1i(sTex0, 0); @@ -2750,6 +2753,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredWLCloudProgram.mShaderFiles.push_back(make_pair("deferred/cloudsF.glsl", GL_FRAGMENT_SHADER_ARB)); gDeferredWLCloudProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED]; gDeferredWLCloudProgram.mShaderGroup = LLGLSLShader::SG_SKY; + gDeferredWLCloudProgram.addConstant( LLGLSLShader::SHADER_CONST_CLOUD_DEPTH ); // SL-14113 success = gDeferredWLCloudProgram.createShader(NULL, NULL); llassert(success); } @@ -2789,6 +2793,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredWLMoonProgram.mShaderFiles.push_back(make_pair("deferred/moonF.glsl", GL_FRAGMENT_SHADER_ARB)); gDeferredWLMoonProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED]; gDeferredWLMoonProgram.mShaderGroup = LLGLSLShader::SG_SKY; + gDeferredWLMoonProgram.addConstant( LLGLSLShader::SHADER_CONST_MOON_DEPTH ); // SL-14113 success = gDeferredWLMoonProgram.createShader(NULL, NULL); llassert(success); } @@ -2801,6 +2806,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredStarProgram.mShaderFiles.push_back(make_pair("deferred/starsF.glsl", GL_FRAGMENT_SHADER_ARB)); gDeferredStarProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED]; gDeferredStarProgram.mShaderGroup = LLGLSLShader::SG_SKY; + gDeferredStarProgram.addConstant( LLGLSLShader::SHADER_CONST_STAR_DEPTH ); // SL-14113 success = gDeferredStarProgram.createShader(NULL, NULL); llassert(success); } @@ -4157,6 +4163,7 @@ BOOL LLViewerShaderMgr::loadShadersWindLight() gWLCloudProgram.mShaderFiles.push_back(make_pair("windlight/cloudsF.glsl", GL_FRAGMENT_SHADER_ARB)); gWLCloudProgram.mShaderLevel = mShaderLevel[SHADER_WINDLIGHT]; gWLCloudProgram.mShaderGroup = LLGLSLShader::SG_SKY; + gWLCloudProgram.addConstant( LLGLSLShader::SHADER_CONST_CLOUD_DEPTH ); // SL-14113 success = gWLCloudProgram.createShader(NULL, NULL); } @@ -4193,6 +4200,7 @@ BOOL LLViewerShaderMgr::loadShadersWindLight() gWLMoonProgram.mShaderFiles.push_back(make_pair("windlight/moonF.glsl", GL_FRAGMENT_SHADER_ARB)); gWLMoonProgram.mShaderLevel = mShaderLevel[SHADER_WINDLIGHT]; gWLMoonProgram.mShaderGroup = LLGLSLShader::SG_SKY; + gWLMoonProgram.addConstant( LLGLSLShader::SHADER_CONST_MOON_DEPTH ); // SL-14113 success = gWLMoonProgram.createShader(NULL, NULL); } |