From d72c0f1d6aff3fc3ea011e38f58b209ffa0bb639 Mon Sep 17 00:00:00 2001
From: Dave Parks <davep@lindenlab.com>
Date: Wed, 21 Sep 2022 12:48:10 -0500
Subject: [PATCH] SL-18190 Fix for fullbright alpha blended legacy materials
 appearing in wrong color space

---
 .../shaders/class3/deferred/materialF.glsl        | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)

diff --git a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl
index fcda50c4dec..07f50af7e3d 100644
--- a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl
+++ b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl
@@ -244,11 +244,6 @@ void main()
     }
 #endif
 
-#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND)
-	vec3 gamma_diff = diffcol.rgb;
-	diffcol.rgb = srgb_to_linear(diffcol.rgb);
-#endif
-
 #ifdef HAS_SPECULAR_MAP
     vec4 spec = texture2D(specularMap, vary_texcoord2.xy);
     spec.rgb *= specular_color.rgb;
@@ -293,7 +288,7 @@ void main()
 
 #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND)
 
-    //forward rendering, output just lit sRGBA
+    //forward rendering, output lit linear color
     vec3 pos = vary_position;
 
     float shadow = 1.0f;
@@ -355,7 +350,7 @@ void main()
 
     color += sun_contrib;
 
-    color *= gamma_diff.rgb;
+    color *= diffcol.rgb;
 
     float glare = 0.0;
 
@@ -378,9 +373,6 @@ void main()
 #endif
     }
 
-
-    color = mix(color.rgb, diffcol.rgb, diffuse.a);
-
 #ifdef HAS_REFLECTION_PROBES
     if (envIntensity > 0.0)
     {  // add environmentmap
@@ -439,12 +431,13 @@ void main()
     al = temp.a;
 #endif
 
+    color = mix(color.rgb, srgb_to_linear(diffcol.rgb), diffuse.a);
     frag_color = vec4(color, al);
 
 #else // mode is not DIFFUSE_ALPHA_MODE_BLEND, encode to gbuffer 
 
     // deferred path               // See: C++: addDeferredAttachment(), shader: softenLightF.glsl
-    frag_data[0] = final_color;    // gbuffer is sRGB
+    frag_data[0] = final_color;    // gbuffer is sRGB for legacy materials
     frag_data[1] = final_specular; // XYZ = Specular color. W = Specular exponent.
     frag_data[2] = final_normal;   // XY = Normal.  Z = Env. intensity. W = 1 skip atmos (mask off fog)
 #endif
-- 
GitLab