From ea9afd66002dc3de45e9f2a5289a676e55372d59 Mon Sep 17 00:00:00 2001
From: Dave Houlton <euclid@lindenlab.com>
Date: Mon, 8 Jun 2020 16:42:34 -0600
Subject: [PATCH] SL-13084 Combined commit for the EEP specular color fix

SL-13084: Fix clouds flipped along East/West axis to match texture preview Cloud Image and direction to match Cloud Scroll

SL-13804: Fix clouds flipped along East/West axis to match texture preview Cloud Image and direction to match Cloud Scroll

SL-13084: Fix inverted cloud scroll with ALM is off

SL-13084: Move texture coords section to top in class2/windlight/cloudsV to match class1/deffered/cloudsV

SL-13084: Add references to other common files
---
 .../shaders/class1/deferred/cloudsV.glsl      |  7 ++--
 .../shaders/class2/windlight/cloudsV.glsl     | 36 +++++++++++--------
 indra/newview/llsettingsvo.cpp                | 11 +++++-
 3 files changed, 36 insertions(+), 18 deletions(-)

diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl
index caa4fe1f65c..495daa2db69 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl
@@ -70,15 +70,18 @@ uniform float cloud_scale;
 // NOTE: Keep these in sync!
 //       indra\newview\app_settings\shaders\class1\deferred\skyV.glsl
 //       indra\newview\app_settings\shaders\class1\deferred\cloudsV.glsl
+//       indra\newview\app-settings\shaders\class2\windlight\cloudsV.glsl
 //       indra\newview\lllegacyatmospherics.cpp
+//       indra\newview\llsettingsvo.cpp
 void main()
 {
-
 	// World / view / projection
 	gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0);
 
 	// Texture coords
-	vary_texcoord0 = texcoord0;
+    // SL-13084 EEP added support for custom cloud textures -- flip them horizontally to match the preview of Clouds > Cloud Scroll
+	vary_texcoord0 = vec2( -texcoord0.x, texcoord0.y ); // See: LLSettingsVOSky::applySpecial
+
 	vary_texcoord0.xy -= 0.5;
 	vary_texcoord0.xy /= cloud_scale;
 	vary_texcoord0.xy += 0.5;
diff --git a/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl b/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl
index 2c1475d5478..a4389f62dc0 100644
--- a/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl
+++ b/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl
@@ -36,6 +36,7 @@ ATTRIBUTE vec2 texcoord0;
 VARYING vec4 vary_CloudColorSun;
 VARYING vec4 vary_CloudColorAmbient;
 VARYING float vary_CloudDensity;
+
 VARYING vec2 vary_texcoord0;
 VARYING vec2 vary_texcoord1;
 VARYING vec2 vary_texcoord2;
@@ -66,13 +67,31 @@ uniform vec4 cloud_color;
 
 uniform float cloud_scale;
 
+// NOTE: Keep these in sync!
+//       indra\newview\app_settings\shaders\class1\deferred\skyV.glsl
+//       indra\newview\app_settings\shaders\class1\deferred\cloudsV.glsl
+//       indra\newview\app-settings\shaders\class2\windlight\cloudsV.glsl
+//       indra\newview\lllegacyatmospherics.cpp
+//       indra\newview\llsettingsvo.cpp
 void main()
 {
-
 	// World / view / projection
 	gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0);
 
-	vary_texcoord0 = texcoord0;
+	// Texture coords
+    // SL-13084 EEP added support for custom cloud textures -- flip them horizontally to match the preview of Clouds > Cloud Scroll
+	vary_texcoord0 = vec2( -texcoord0.x, texcoord0.y ); // See: LLSettingsVOSky::applySpecial
+
+	vary_texcoord0.xy -= 0.5;
+	vary_texcoord0.xy /= cloud_scale;
+	vary_texcoord0.xy += 0.5;
+
+	vary_texcoord1 = vary_texcoord0;
+	vary_texcoord1.x += lightnorm.x * 0.0125;
+	vary_texcoord1.y += lightnorm.z * 0.0125;
+
+	vary_texcoord2 = vary_texcoord0 * 16.;
+	vary_texcoord3 = vary_texcoord1 * 16.;
 
 	// Get relative position
 	vec3 P = position.xyz - camPosLocal.xyz + vec3(0,50,0);
@@ -175,19 +194,6 @@ void main()
 	vary_CloudDensity = 2. * (cloud_shadow - 0.25);
 
 
-	// Texture coords
-	vary_texcoord0 = texcoord0;
-	vary_texcoord0.xy -= 0.5;
-	vary_texcoord0.xy /= cloud_scale;
-	vary_texcoord0.xy += 0.5;
-
-	vary_texcoord1 = vary_texcoord0;
-	vary_texcoord1.x += lightnorm.x * 0.0125;
-	vary_texcoord1.y += lightnorm.z * 0.0125;
-
-	vary_texcoord2 = vary_texcoord0 * 16.;
-	vary_texcoord3 = vary_texcoord1 * 16.;
-
 	// Combine these to minimize register use
 	vary_CloudColorAmbient += oHazeColorBelowCloud;
 
diff --git a/indra/newview/llsettingsvo.cpp b/indra/newview/llsettingsvo.cpp
index c72a0706cdc..5a4427a7b7d 100644
--- a/indra/newview/llsettingsvo.cpp
+++ b/indra/newview/llsettingsvo.cpp
@@ -678,8 +678,17 @@ void LLSettingsVOSky::applySpecial(void *ptarget, bool force)
 	{
     shader->uniform4fv(LLViewerShaderMgr::LIGHTNORM, 1, light_direction.mV);        
 
+    // Legacy? SETTING_CLOUD_SCROLL_RATE("cloud_scroll_rate")
     LLVector4 vect_c_p_d1(mSettings[SETTING_CLOUD_POS_DENSITY1]);
-    vect_c_p_d1 += LLVector4(LLEnvironment::instance().getCloudScrollDelta());
+    LLVector4 cloud_scroll( LLEnvironment::instance().getCloudScrollDelta() );
+
+    // SL-13084 EEP added support for custom cloud textures -- flip them horizontally to match the preview of Clouds > Cloud Scroll
+    // Keep in Sync!
+    // * indra\newview\llsettingsvo.cpp
+    // * indra\newview\app_settings\shaders\class2\windlight\cloudsV.glsl
+    // * indra\newview\app_settings\shaders\class1\deferred\cloudsV.glsl
+    cloud_scroll[0] = -cloud_scroll[0];
+    vect_c_p_d1 += cloud_scroll;
     shader->uniform4fv(LLShaderMgr::CLOUD_POS_DENSITY1, 1, vect_c_p_d1.mV);
 
     LLSettingsSky::ptr_t psky = LLEnvironment::instance().getCurrentSky();
-- 
GitLab