From 85967398ff8591170d89374652a6998ff6cd3d69 Mon Sep 17 00:00:00 2001
From: RunitaiLinden <davep@lindenlab.com>
Date: Wed, 21 Jun 2023 20:50:50 -0500
Subject: SL-19792 Fix for visible gaps in water between region water and void
 water.

---
 indra/newview/app_settings/settings.xml            | 27 +++++++++-----
 .../shaders/class1/windlight/atmosphericsF.glsl    |  2 --
 indra/newview/llreflectionmapmanager.cpp           |  5 +--
 indra/newview/llsettingsvo.cpp                     |  8 +++--
 indra/newview/llvowater.cpp                        | 41 +++++++++++-----------
 5 files changed, 48 insertions(+), 35 deletions(-)

(limited to 'indra/newview')

diff --git a/indra/newview/app_settings/settings.xml b/indra/newview/app_settings/settings.xml
index 2b2a2d9d1b..f3065d12b8 100644
--- a/indra/newview/app_settings/settings.xml
+++ b/indra/newview/app_settings/settings.xml
@@ -10590,27 +10590,38 @@
       <key>Value</key>
       <integer>3</integer>
     </map>
-  <key>RenderSkyHDRScale</key>
+  <key>RenderSkyAutoAdjustLegacy</key>
   <map>
     <key>Comment</key>
-    <string>Amount to over-brighten sun for HDR effect during the day</string>
+    <string>If true, automatically adjust legacy skies (those without a probe ambiance value) to take advantage of probes and HDR.  This is the "opt-out" button for HDR and tonemapping when coupled with a sky setting that predates PBR.</string>
     <key>Persist</key>
-    <integer>0</integer>
+    <integer>1</integer>
     <key>Type</key>
-    <string>F32</string>
+    <string>Boolean</string>
     <key>Value</key>
-    <real>1.0</real>
+    <integer>1</integer>
   </map>
-  <key>RenderSkyAutoAdjustLegacy</key>
+  <key>RenderSkyAutoAdjustAmbientScale</key>
   <map>
     <key>Comment</key>
-    <string>If true, automatically adjust legacy skies (those without a probe ambiance value) to take advantage of probes and HDR.  This is the "opt-out" button for HDR and tonemapping when coupled with a sky setting that predates PBR.</string>
+    <string>Amount to scale ambient when auto-adjusting legacy skies</string>
     <key>Persist</key>
     <integer>1</integer>
     <key>Type</key>
-    <string>Boolean</string>
+    <string>F32</string>
     <key>Value</key>
+    <real>0.5</real>
+  </map>
+  <key>RenderSkyAutoAdjustHDRScale</key>
+  <map>
+    <key>Comment</key>
+    <string>HDR Scale value to use when auto-adjusting legacy skies</string>
+    <key>Persist</key>
     <integer>1</integer>
+    <key>Type</key>
+    <string>F32</string>
+    <key>Value</key>
+    <real>2.0</real>
   </map>
   <key>RenderReflectionProbeMaxLocalLightAmbiance</key>
   <map>
diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsF.glsl
index 48cf234aa0..41a848a14f 100644
--- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsF.glsl
+++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsF.glsl
@@ -36,8 +36,6 @@ vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten)
 { 
     light *= atten.r;
     additive = srgb_to_linear(additive*2.0);
-    // magic 1.25 here is to match the default RenderSkyHDRScale -- this parameter needs to be plumbed into sky settings or something
-    // so it's available to all shaders that call atmosFragLighting instead of just softenLightF.glsl
     additive *= sky_hdr_scale;
     light += additive;
     return light;
diff --git a/indra/newview/llreflectionmapmanager.cpp b/indra/newview/llreflectionmapmanager.cpp
index e30aba3df7..779fe8bfd9 100644
--- a/indra/newview/llreflectionmapmanager.cpp
+++ b/indra/newview/llreflectionmapmanager.cpp
@@ -924,8 +924,9 @@ void LLReflectionMapManager::updateUniforms()
     static LLCachedControl<bool> should_auto_adjust(gSavedSettings, "RenderSkyAutoAdjustLegacy", true);
     F32 minimum_ambiance = psky->getTotalReflectionProbeAmbiance(cloud_shadow_scale, should_auto_adjust);
 
-    F32 ambscale = gCubeSnapshot && !isRadiancePass() ? 0.f : 1.f;
-    F32 radscale = gCubeSnapshot && !isRadiancePass() ? 0.5f : 1.f;
+    bool is_ambiance_pass = gCubeSnapshot && !isRadiancePass();
+    F32 ambscale = is_ambiance_pass ? 0.f : 1.f;
+    F32 radscale = is_ambiance_pass ? 0.5f : 1.f;
     
     for (auto* refmap : mReflectionMaps)
     {
diff --git a/indra/newview/llsettingsvo.cpp b/indra/newview/llsettingsvo.cpp
index 258cc1c7b2..264359a3a9 100644
--- a/indra/newview/llsettingsvo.cpp
+++ b/indra/newview/llsettingsvo.cpp
@@ -719,6 +719,8 @@ void LLSettingsVOSky::applySpecial(void *ptarget, bool force)
     F32 g = getGamma();
 
     static LLCachedControl<bool> should_auto_adjust(gSavedSettings, "RenderSkyAutoAdjustLegacy", true);
+    static LLCachedControl<F32> auto_adjust_ambient_scale(gSavedSettings, "RenderSkyAutoAdjustAmbientScale", 0.75f);
+    static LLCachedControl<F32> auto_adjust_hdr_scale(gSavedSettings, "RenderSkyAutoAdjustHDRScale", 2.f);
 
     static LLCachedControl<F32> cloud_shadow_scale(gSavedSettings, "RenderCloudShadowAmbianceFactor", 0.125f);
     F32 probe_ambiance = getTotalReflectionProbeAmbiance(cloud_shadow_scale);
@@ -736,9 +738,9 @@ void LLSettingsVOSky::applySpecial(void *ptarget, bool force)
         }
         else if (psky->canAutoAdjust() && should_auto_adjust)
         { // auto-adjust legacy sky to take advantage of probe ambiance 
-            shader->uniform3fv(LLShaderMgr::AMBIENT, (ambient * 0.5f).mV);
-            shader->uniform1f(LLShaderMgr::SKY_HDR_SCALE, 2.f);
-            probe_ambiance = 1.f;
+            shader->uniform3fv(LLShaderMgr::AMBIENT, (ambient * auto_adjust_ambient_scale).mV);
+            shader->uniform1f(LLShaderMgr::SKY_HDR_SCALE, auto_adjust_hdr_scale);
+            probe_ambiance = 1.f;  // NOTE -- must match LLSettingsSky::getReflectionProbeAmbiance value for "auto_adjust" true
         }
         else
         {
diff --git a/indra/newview/llvowater.cpp b/indra/newview/llvowater.cpp
index 608d2cb799..77ad967cef 100644
--- a/indra/newview/llvowater.cpp
+++ b/indra/newview/llvowater.cpp
@@ -142,9 +142,14 @@ BOOL LLVOWater::updateGeometry(LLDrawable *drawable)
 	static const unsigned int vertices_per_quad = 4;
 	static const unsigned int indices_per_quad = 6;
 
-	const S32 size = LLPipeline::sRenderTransparentWater ? 16 : 1;
+    S32 size_x = LLPipeline::sRenderTransparentWater ? 8 : 1;
+    S32 size_y = LLPipeline::sRenderTransparentWater ? 8 : 1;
 
-	const S32 num_quads = size * size;
+    const LLVector3& scale = getScale();
+    size_x *= llmin(llround(scale.mV[0] / 256.f), 8);
+    size_y *= llmin(llround(scale.mV[1] / 256.f), 8);
+
+	const S32 num_quads = size_x * size_y;
 	face->setSize(vertices_per_quad * num_quads,
 				  indices_per_quad * num_quads);
 	
@@ -175,41 +180,37 @@ BOOL LLVOWater::updateGeometry(LLDrawable *drawable)
 	face->mCenterLocal = position_agent;
 
 	S32 x, y;
-	F32 step_x = getScale().mV[0] / size;
-	F32 step_y = getScale().mV[1] / size;
+	F32 step_x = getScale().mV[0] / size_x;
+	F32 step_y = getScale().mV[1] / size_y;
 
 	const LLVector3 up(0.f, step_y * 0.5f, 0.f);
 	const LLVector3 right(step_x * 0.5f, 0.f, 0.f);
 	const LLVector3 normal(0.f, 0.f, 1.f);
 
-	F32 size_inv = 1.f / size;
-
-	F32 z_fudge = 0.f;
+	F32 size_inv_x = 1.f / size_x;
+    F32 size_inv_y = 1.f / size_y;
 
-	if (getIsEdgePatch())
-	{ //bump edge patches down 10 cm to prevent aliasing along edges
-		z_fudge = -0.1f;
-	}
-
-	for (y = 0; y < size; y++)
+	for (y = 0; y < size_y; y++)
 	{
-		for (x = 0; x < size; x++)
+		for (x = 0; x < size_x; x++)
 		{
-			S32 toffset = index_offset + 4*(y*size + x);
+			S32 toffset = index_offset + 4*(y*size_x + x);
 			position_agent = getPositionAgent() - getScale() * 0.5f;
 			position_agent.mV[VX] += (x + 0.5f) * step_x;
 			position_agent.mV[VY] += (y + 0.5f) * step_y;
-			position_agent.mV[VZ] += z_fudge;
+
+            position_agent.mV[VX] = llround(position_agent.mV[VX]);
+            position_agent.mV[VY] = llround(position_agent.mV[VY]);
 
 			*verticesp++  = position_agent - right + up;
 			*verticesp++  = position_agent - right - up;
 			*verticesp++  = position_agent + right + up;
 			*verticesp++  = position_agent + right - up;
 
-			*texCoordsp++ = LLVector2(x*size_inv, (y+1)*size_inv);
-			*texCoordsp++ = LLVector2(x*size_inv, y*size_inv);
-			*texCoordsp++ = LLVector2((x+1)*size_inv, (y+1)*size_inv);
-			*texCoordsp++ = LLVector2((x+1)*size_inv, y*size_inv);
+			*texCoordsp++ = LLVector2(x*size_inv_x, (y+1)*size_inv_y);
+			*texCoordsp++ = LLVector2(x*size_inv_x, y*size_inv_y);
+			*texCoordsp++ = LLVector2((x+1)*size_inv_x, (y+1)*size_inv_y);
+			*texCoordsp++ = LLVector2((x+1)*size_inv_x, y*size_inv_y);
 			
 			*normalsp++   = normal;
 			*normalsp++   = normal;
-- 
cgit v1.2.3