From c8fb3ad4de0575a0538b9532e819319f655613d1 Mon Sep 17 00:00:00 2001
From: Dave Parks <davep@lindenlab.com>
Date: Mon, 6 Feb 2023 10:28:26 -0600
Subject: [PATCH] SL-19148 Decruft followthrough -- fix for crash when running
 from installer.  Feed fresnel component into PBR alpha.  Remove obsolete
 "shader_hierarchy.txt", remove redundant LL_PROFILE_ZONE_SCOPED, remove
 unused shader feature flag.

---
 indra/llrender/llglslshader.cpp                   |  3 +--
 indra/llrender/llglslshader.h                     |  1 -
 indra/llrender/llshadermgr.cpp                    |  2 +-
 .../shaders/class2/deferred/pbralphaF.glsl        | 14 +++++++++++++-
 .../app_settings/shaders/shader_hierarchy.txt     | 15 ---------------
 indra/newview/lldrawpooltree.cpp                  |  1 -
 6 files changed, 15 insertions(+), 21 deletions(-)
 delete mode 100644 indra/newview/app_settings/shaders/shader_hierarchy.txt

diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp
index 6b56c23fcd3..4e32e2bd257 100644
--- a/indra/llrender/llglslshader.cpp
+++ b/indra/llrender/llglslshader.cpp
@@ -82,8 +82,7 @@ BOOL shouldChange(const LLVector4& v1, const LLVector4& v2)
 }
 
 LLShaderFeatures::LLShaderFeatures()
-    : atmosphericHelpers(false)
-    , calculatesLighting(false)
+    : calculatesLighting(false)
     , calculatesAtmospherics(false)
     , hasLighting(false)
     , isAlphaLighting(false)
diff --git a/indra/llrender/llglslshader.h b/indra/llrender/llglslshader.h
index edf7b594912..2b709cc6b43 100644
--- a/indra/llrender/llglslshader.h
+++ b/indra/llrender/llglslshader.h
@@ -35,7 +35,6 @@
 class LLShaderFeatures
 {
 public:
-    bool atmosphericHelpers;
     bool calculatesLighting;
     bool calculatesAtmospherics;
     bool hasLighting; // implies no transport (it's possible to have neither though)
diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp
index 646c9a821b1..16f2769411a 100644
--- a/indra/llrender/llshadermgr.cpp
+++ b/indra/llrender/llshadermgr.cpp
@@ -616,7 +616,7 @@ GLuint LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shader_lev
         */
 
  		LL_DEBUGS("ShaderLoading") << "Looking in " << open_file_name << LL_ENDL;
-		file = LLFile::fopen(open_file_name, "r+");		/* Flawfinder: ignore */
+		file = LLFile::fopen(open_file_name, "r");		/* Flawfinder: ignore */
 		if (file)
 		{
 			LL_DEBUGS("ShaderLoading") << "Loading file: " << open_file_name << " (Want class " << gpu_class << ")" << LL_ENDL;            
diff --git a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl
index ccf20942e31..35e22ef3a2e 100644
--- a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl
+++ b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl
@@ -113,6 +113,8 @@ vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor,
                     vec3 v, // surface point to camera
                     vec3 l); //surface point to light
 
+vec2 BRDF(float NoV, float roughness);
+
 vec3 calcPointLightOrSpotLight(vec3 diffuseColor, vec3 specularColor, 
                     float perceptualRoughness, 
                     float metallic,
@@ -217,8 +219,12 @@ void main()
     calcDiffuseSpecular(col.rgb, metallic, diffuseColor, specularColor);
 
     vec3 v = -normalize(pos.xyz);
+
     color = pbrBaseLight(diffuseColor, specularColor, metallic, v, norm.xyz, perceptualRoughness, light_dir, sunlit, scol, radiance, irradiance, colorEmissive, ao, additive, atten);
 
+    float nv = clamp(abs(dot(norm.xyz, v)), 0.001, 1.0);
+    vec2 brdf = BRDF(clamp(nv, 0, 1), 1.0-perceptualRoughness);
+
     vec3 light = vec3(0);
 
     // Punctual lights
@@ -235,5 +241,11 @@ void main()
     color.rgb += light.rgb;
 
     
-    frag_color = vec4(color.rgb,basecolor.a * vertex_color.a);
+    float a = basecolor.a*vertex_color.a;
+    vec3 spec = radiance; // *specularColor;
+    float lum = max(max(spec.r, spec.g), spec.b);
+    
+    float f = brdf.y;
+    a += f;
+    frag_color = vec4(color.rgb,a);
 }
diff --git a/indra/newview/app_settings/shaders/shader_hierarchy.txt b/indra/newview/app_settings/shaders/shader_hierarchy.txt
deleted file mode 100644
index 81e13271784..00000000000
--- a/indra/newview/app_settings/shaders/shader_hierarchy.txt
+++ /dev/null
@@ -1,15 +0,0 @@
-Second Life shader variants are referred to as "classes."  
-
-When a shader of a particular class is loaded, a lower class may 
-be loaded if the class requested doesn't exist or fails to load 
-for any reason.  In general, shaders that require more resources
-or later hardware capabilities should be higher class and 
-lower classes can be used for fallback implementations or lower
-detail settings.
-
-Which class is chosen will generally depend on graphics preferences. 
-
-Previously, someone tried to enumerate the shaders here, but don't do 
-that.  It messes with searches and the shader hierarchy changes often.
-
-
diff --git a/indra/newview/lldrawpooltree.cpp b/indra/newview/lldrawpooltree.cpp
index 7fa72abb5c8..57146c432a0 100644
--- a/indra/newview/lldrawpooltree.cpp
+++ b/indra/newview/lldrawpooltree.cpp
@@ -65,7 +65,6 @@ void LLDrawPoolTree::beginDeferredPass(S32 pass)
 void LLDrawPoolTree::renderDeferred(S32 pass)
 {
     LL_PROFILE_ZONE_SCOPED;
-    LL_PROFILE_ZONE_SCOPED;
 
     if (mDrawFace.empty())
     {
-- 
GitLab