From 28b9a465ac79e7d2284f9d561bb3ffda61c922d8 Mon Sep 17 00:00:00 2001
From: Dave Houlton <euclid@lindenlab.com>
Date: Tue, 19 Jan 2021 11:11:46 -0700
Subject: SL-13629, reconstruct rainbow lookup coord to reduce interior banding

---
 indra/newview/app_settings/shaders/class2/deferred/skyF.glsl | 6 ++++++
 indra/newview/app_settings/shaders/class3/deferred/skyF.glsl | 6 ++++++
 2 files changed, 12 insertions(+)

(limited to 'indra/newview')

diff --git a/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl
index 5a58f9bc8c..6841a8194f 100644
--- a/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl
+++ b/indra/newview/app_settings/shaders/class2/deferred/skyF.glsl
@@ -82,6 +82,12 @@ vec3 rainbow(float d)
     // interesting range, but in reversed order:  i.e. d = (1 - d) - 1.575
     d = clamp(-0.575 - d, 0.0, 1.0);
 
+    // With the colors in the lower 1/4 of the texture, inverting the coords leaves most of it inaccessible.
+    // So, we can stretch the texcoord above the colors (ie > 0.25) to fill the entire remaining coordinate
+    // space. This improves gradation, reduces banding within the rainbow interior. (1-0.25) / (0.425/0.25) = 4.2857
+    float interior_coord = max(0.0, d - 0.25) * 4.2857;
+    d = clamp(d, 0.0, 0.25) + interior_coord;
+
     float rad = (droplet_radius - 5.0f) / 1024.0f;
     return pow(texture2D(rainbow_map, vec2(rad, d)).rgb, vec3(1.8)) * moisture_level;
 }
diff --git a/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl
index 0f908a1d82..a0b082ed7c 100644
--- a/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl
+++ b/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl
@@ -65,6 +65,12 @@ vec3 rainbow(float d)
     // interesting range, but in reversed order:  i.e. d = (1 - d) - 1.575
     d = clamp(-0.575 - d, 0.0, 1.0);
 
+    // With the colors in the lower 1/4 of the texture, inverting the coords leaves most of it inaccessible.
+    // So, we can stretch the texcoord above the colors (ie > 0.25) to fill the entire remaining coordinate
+    // space. This improves gradation, reduces banding within the rainbow interior. (1-0.25) / (0.425/0.25) = 4.2857
+    float interior_coord = max(0.0, d - 0.25) * 4.2857;
+    d = clamp(d, 0.0, 0.25) + interior_coord;
+
     float rad = (droplet_radius - 5.0f) / 1024.0f;
     return pow(texture2D(rainbow_map, vec2(rad, d)).rgb, vec3(1.8)) * moisture_level;
 }
-- 
cgit v1.2.3