From 0edb7cad6bdeaf02cbd89d1f2dd38c47d6078c03 Mon Sep 17 00:00:00 2001
From: RunitaiLinden <davep@lindenlab.com>
Date: Tue, 14 Nov 2023 13:33:11 -0600
Subject: [PATCH] SL-20340 Fix for off-by-epsilon hack falling off when
 serializing overrides as LLSD. (#513)

---
 indra/llprimitive/llgltfmaterial.cpp | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/indra/llprimitive/llgltfmaterial.cpp b/indra/llprimitive/llgltfmaterial.cpp
index c1f2a041540..9945c230a27 100644
--- a/indra/llprimitive/llgltfmaterial.cpp
+++ b/indra/llprimitive/llgltfmaterial.cpp
@@ -691,24 +691,44 @@ void LLGLTFMaterial::applyOverrideLLSD(const LLSD& data)
     if (bc.isDefined())
     {
         mBaseColor.setValue(bc);
+        if (mBaseColor == getDefaultBaseColor())
+        {
+            // HACK -- nudge by epsilon if we receive a default value (indicates override to default)
+            mBaseColor.mV[3] -= FLT_EPSILON;
+        }
     }
 
     const LLSD& ec = data["ec"];
     if (ec.isDefined())
     {
         mEmissiveColor.setValue(ec);
+        if (mEmissiveColor == getDefaultEmissiveColor())
+        {
+            // HACK -- nudge by epsilon if we receive a default value (indicates override to default)
+            mEmissiveColor.mV[0] += FLT_EPSILON;
+        }
     }
 
     const LLSD& mf = data["mf"];
     if (mf.isReal())
     {
         mMetallicFactor = mf.asReal();
+        if (mMetallicFactor == getDefaultMetallicFactor())
+        { 
+            // HACK -- nudge by epsilon if we receive a default value (indicates override to default)
+            mMetallicFactor -= FLT_EPSILON;
+        }
     }
 
     const LLSD& rf = data["rf"];
     if (rf.isReal())
     {
         mRoughnessFactor = rf.asReal();
+        if (mRoughnessFactor == getDefaultRoughnessFactor())
+        { 
+            // HACK -- nudge by epsilon if we receive a default value (indicates override to default)
+            mRoughnessFactor -= FLT_EPSILON;
+        }
     }
 
     const LLSD& am = data["am"];
@@ -722,6 +742,11 @@ void LLGLTFMaterial::applyOverrideLLSD(const LLSD& data)
     if (ac.isReal())
     {
         mAlphaCutoff = ac.asReal();
+        if (mAlphaCutoff == getDefaultAlphaCutoff())
+        {
+            // HACK -- nudge by epsilon if we receive a default value (indicates override to default)
+            mAlphaCutoff -= FLT_EPSILON;
+        }
     }
 
     const LLSD& ds = data["ds"];
-- 
GitLab