From de73cf7599e934441fe760f53163b0504c03adc7 Mon Sep 17 00:00:00 2001
From: Dave Parks <davep@lindenlab.com>
Date: Fri, 7 Apr 2023 11:06:09 -0500
Subject: [PATCH] SL-19538 Remove clouds from irradiance maps and don't
 conflate max probe samples with max probe neighbors, and don't move manual
 probes after they are complete (removes flickering around Sponza).

---
 .../shaders/class3/deferred/reflectionProbeF.glsl        | 2 +-
 indra/newview/lldrawpoolwlsky.cpp                        | 6 +++++-
 indra/newview/llreflectionmap.cpp                        | 2 +-
 indra/newview/llreflectionmapmanager.cpp                 | 9 +++++++++
 4 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl
index e73e396b8e3..e1b18935e80 100644
--- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl
+++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl
@@ -134,7 +134,7 @@ void preProbeSample(vec3 pos)
             int neighborIdx = refIndex[i].y;
             if (neighborIdx != -1)
             {
-                int neighborCount = min(refIndex[i].z, REF_SAMPLE_COUNT-1);
+                int neighborCount = refIndex[i].z;
 
                 int count = 0;
                 while (count < neighborCount)
diff --git a/indra/newview/lldrawpoolwlsky.cpp b/indra/newview/lldrawpoolwlsky.cpp
index b49fe358511..820073b3e0a 100644
--- a/indra/newview/lldrawpoolwlsky.cpp
+++ b/indra/newview/lldrawpoolwlsky.cpp
@@ -442,7 +442,11 @@ void LLDrawPoolWLSky::renderDeferred(S32 pass)
         {
             renderStarsDeferred(origin);
         }
-        renderSkyCloudsDeferred(origin, camHeightLocal, cloud_shader);
+
+        if (!gCubeSnapshot || gPipeline.mReflectionMapManager.isRadiancePass()) // don't draw clouds in irradiance maps to avoid popping
+        {
+            renderSkyCloudsDeferred(origin, camHeightLocal, cloud_shader);
+        }
     }
     gGL.setColorMask(true, true);
 }
diff --git a/indra/newview/llreflectionmap.cpp b/indra/newview/llreflectionmap.cpp
index 89ac0df2864..261aa51d62b 100644
--- a/indra/newview/llreflectionmap.cpp
+++ b/indra/newview/llreflectionmap.cpp
@@ -70,7 +70,7 @@ void LLReflectionMap::autoAdjustOrigin()
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_DISPLAY;
 
-    if (mGroup)
+    if (mGroup && !mComplete)
     {
         const LLVector4a* bounds = mGroup->getBounds();
         auto* node = mGroup->getOctreeNode();
diff --git a/indra/newview/llreflectionmapmanager.cpp b/indra/newview/llreflectionmapmanager.cpp
index 8252b4be366..dc84b0b10e6 100644
--- a/indra/newview/llreflectionmapmanager.cpp
+++ b/indra/newview/llreflectionmapmanager.cpp
@@ -861,6 +861,9 @@ void LLReflectionMapManager::updateUniforms()
         {
             //LL_PROFILE_ZONE_NAMED_CATEGORY_DISPLAY("rmmsu - refNeighbors");
             //pack neghbor list
+            const U32 max_neighbors = 64;
+            U32 neighbor_count = 0;
+
             for (auto& neighbor : refmap->mNeighbors)
             {
                 if (ni >= 4096)
@@ -876,6 +879,12 @@ void LLReflectionMapManager::updateUniforms()
 
                 // this neighbor may be sampled
                 rpd.refNeighbor[ni++] = idx;
+
+                neighbor_count++;
+                if (neighbor_count >= max_neighbors)
+                {
+                    break;
+                }
             }
         }
 
-- 
GitLab