From 37e6ce24a2060a7d943b45c8015576f016021e5e Mon Sep 17 00:00:00 2001 From: Homer Horwitz Date: Sat, 13 Sep 2008 22:48:30 +0000 Subject: Fixed several cases of inverted colors and alpha in DNE and XEngine. Added clamping to 0.0 - 1.0 for R, G, B, and A. --- .../ScriptEngine/Common/LSL_BuiltIn_Commands.cs | 70 +++++++++++----------- .../Shared/Api/Implementation/LSL_Api.cs | 70 +++++++++++----------- 2 files changed, 70 insertions(+), 70 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs b/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs index f2add80..1090c42 100644 --- a/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs +++ b/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs @@ -1340,7 +1340,7 @@ namespace OpenSim.Region.ScriptEngine.Common if (face > -1) { texcolor = tex.CreateFace((uint)face).RGBA; - texcolor.A = (float)Math.Abs(alpha - 1); + texcolor.A = (float)Math.Min(Math.Max(alpha, 0.0), 1.0); tex.FaceTextures[face].RGBA = texcolor; part.UpdateTexture(tex); return; @@ -1352,12 +1352,12 @@ namespace OpenSim.Region.ScriptEngine.Common if (tex.FaceTextures[i] != null) { texcolor = tex.FaceTextures[i].RGBA; - texcolor.A = (float)Math.Abs(alpha - 1); + texcolor.A = (float)Math.Min(Math.Max(alpha, 0.0), 1.0); tex.FaceTextures[i].RGBA = texcolor; } } texcolor = tex.DefaultTexture.RGBA; - texcolor.A = (float)Math.Abs(alpha - 1); + texcolor.A = (float)Math.Min(Math.Max(alpha, 0.0), 1.0); tex.DefaultTexture.RGBA = texcolor; part.UpdateTexture(tex); return; @@ -2866,9 +2866,9 @@ namespace OpenSim.Region.ScriptEngine.Common if (face > -1) { texcolor = tex.CreateFace((uint)face).RGBA; - texcolor.R = (float)Math.Abs(color.x - 1); - texcolor.G = (float)Math.Abs(color.y - 1); - texcolor.B = (float)Math.Abs(color.z - 1); + texcolor.R = (float)Math.Min(Math.Max(color.x, 0.0), 1.0); + texcolor.G = (float)Math.Min(Math.Max(color.y, 0.0), 1.0); + texcolor.B = (float)Math.Min(Math.Max(color.z, 0.0), 1.0); tex.FaceTextures[face].RGBA = texcolor; part.UpdateTexture(tex); return; @@ -2876,25 +2876,25 @@ namespace OpenSim.Region.ScriptEngine.Common else if (face == -1) { texcolor = tex.DefaultTexture.RGBA; - texcolor.R = (float)Math.Abs(color.x - 1); - texcolor.G = (float)Math.Abs(color.y - 1); - texcolor.B = (float)Math.Abs(color.z - 1); + texcolor.R = (float)Math.Min(Math.Max(color.x, 0.0), 1.0); + texcolor.G = (float)Math.Min(Math.Max(color.y, 0.0), 1.0); + texcolor.B = (float)Math.Min(Math.Max(color.z, 0.0), 1.0); tex.DefaultTexture.RGBA = texcolor; for (uint i = 0; i < 32; i++) { if (tex.FaceTextures[i] != null) { texcolor = tex.FaceTextures[i].RGBA; - texcolor.R = (float)Math.Abs(color.x - 1); - texcolor.G = (float)Math.Abs(color.y - 1); - texcolor.B = (float)Math.Abs(color.z - 1); + texcolor.R = (float)Math.Min(Math.Max(color.x, 0.0), 1.0); + texcolor.G = (float)Math.Min(Math.Max(color.y, 0.0), 1.0); + texcolor.B = (float)Math.Min(Math.Max(color.z, 0.0), 1.0); tex.FaceTextures[i].RGBA = texcolor; } } texcolor = tex.DefaultTexture.RGBA; - texcolor.R = (float)Math.Abs(color.x - 1); - texcolor.G = (float)Math.Abs(color.y - 1); - texcolor.B = (float)Math.Abs(color.z - 1); + texcolor.R = (float)Math.Min(Math.Max(color.x, 0.0), 1.0); + texcolor.G = (float)Math.Min(Math.Max(color.y, 0.0), 1.0); + texcolor.B = (float)Math.Min(Math.Max(color.z, 0.0), 1.0); tex.DefaultTexture.RGBA = texcolor; part.UpdateTexture(tex); return; @@ -2913,34 +2913,34 @@ namespace OpenSim.Region.ScriptEngine.Common if (face > -1) { texcolor = tex.CreateFace((uint)face).RGBA; - texcolor.R = (float)Math.Abs(color.x - 1); - texcolor.G = (float)Math.Abs(color.y - 1); - texcolor.B = (float)Math.Abs(color.z - 1); + texcolor.R = (float)Math.Min(Math.Max(color.x, 0.0), 1.0); + texcolor.G = (float)Math.Min(Math.Max(color.y, 0.0), 1.0); + texcolor.B = (float)Math.Min(Math.Max(color.z, 0.0), 1.0); tex.FaceTextures[face].RGBA = texcolor; part.UpdateTexture(tex); } else if (face == -1) { texcolor = tex.DefaultTexture.RGBA; - texcolor.R = (float)Math.Abs(color.x - 1); - texcolor.G = (float)Math.Abs(color.y - 1); - texcolor.B = (float)Math.Abs(color.z - 1); + texcolor.R = (float)Math.Min(Math.Max(color.x, 0.0), 1.0); + texcolor.G = (float)Math.Min(Math.Max(color.y, 0.0), 1.0); + texcolor.B = (float)Math.Min(Math.Max(color.z, 0.0), 1.0); tex.DefaultTexture.RGBA = texcolor; for (uint i = 0; i < 32; i++) { if (tex.FaceTextures[i] != null) { texcolor = tex.FaceTextures[i].RGBA; - texcolor.R = (float)Math.Abs(color.x - 1); - texcolor.G = (float)Math.Abs(color.y - 1); - texcolor.B = (float)Math.Abs(color.z - 1); + texcolor.R = (float)Math.Min(Math.Max(color.x, 0.0), 1.0); + texcolor.G = (float)Math.Min(Math.Max(color.y, 0.0), 1.0); + texcolor.B = (float)Math.Min(Math.Max(color.z, 0.0), 1.0); tex.FaceTextures[i].RGBA = texcolor; } } texcolor = tex.DefaultTexture.RGBA; - texcolor.R = (float)Math.Abs(color.x - 1); - texcolor.G = (float)Math.Abs(color.y - 1); - texcolor.B = (float)Math.Abs(color.z - 1); + texcolor.R = (float)Math.Min(Math.Max(color.x, 0.0), 1.0); + texcolor.G = (float)Math.Min(Math.Max(color.y, 0.0), 1.0); + texcolor.B = (float)Math.Min(Math.Max(color.z, 0.0), 1.0); tex.DefaultTexture.RGBA = texcolor; part.UpdateTexture(tex); } @@ -6154,7 +6154,7 @@ namespace OpenSim.Region.ScriptEngine.Common if (face > -1) { texcolor = tex.CreateFace((uint)face).RGBA; - texcolor.A = (float)Math.Abs(alpha - 1); + texcolor.A = (float)Math.Min(Math.Max(alpha, 0.0), 1.0); tex.FaceTextures[face].RGBA = texcolor; part.UpdateTexture(tex); return; @@ -6162,19 +6162,19 @@ namespace OpenSim.Region.ScriptEngine.Common else if (face == -1) { texcolor = tex.DefaultTexture.RGBA; - texcolor.A = (float)Math.Abs(alpha - 1); + texcolor.A = (float)Math.Min(Math.Max(alpha, 0.0), 1.0); tex.DefaultTexture.RGBA = texcolor; for (uint i = 0; i < 32; i++) { if (tex.FaceTextures[i] != null) { texcolor = tex.FaceTextures[i].RGBA; - texcolor.A = (float)Math.Abs(alpha - 1); + texcolor.A = (float)Math.Min(Math.Max(alpha, 0.0), 1.0); tex.FaceTextures[i].RGBA = texcolor; } } texcolor = tex.DefaultTexture.RGBA; - texcolor.A = (float)Math.Abs(alpha - 1); + texcolor.A = (float)Math.Min(Math.Max(alpha, 0.0), 1.0); tex.DefaultTexture.RGBA = texcolor; part.UpdateTexture(tex); return; @@ -6193,26 +6193,26 @@ namespace OpenSim.Region.ScriptEngine.Common if (face > -1) { texcolor = tex.CreateFace((uint)face).RGBA; - texcolor.A = (float)Math.Abs(alpha - 1); + texcolor.A = (float)Math.Min(Math.Max(alpha, 0.0), 1.0); tex.FaceTextures[face].RGBA = texcolor; part.UpdateTexture(tex); } else if (face == -1) { texcolor = tex.DefaultTexture.RGBA; - texcolor.A = (float)Math.Abs(alpha - 1); + texcolor.A = (float)Math.Min(Math.Max(alpha, 0.0), 1.0); tex.DefaultTexture.RGBA = texcolor; for (uint i = 0; i < 32; i++) { if (tex.FaceTextures[i] != null) { texcolor = tex.FaceTextures[i].RGBA; - texcolor.A = (float)Math.Abs(alpha - 1); + texcolor.A = (float)Math.Min(Math.Max(alpha, 0.0), 1.0); tex.FaceTextures[i].RGBA = texcolor; } } texcolor = tex.DefaultTexture.RGBA; - texcolor.A = (float)Math.Abs(alpha - 1); + texcolor.A = (float)Math.Min(Math.Max(alpha, 0.0), 1.0); tex.DefaultTexture.RGBA = texcolor; part.UpdateTexture(tex); } diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index b27aa07..24f19a0 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -1149,7 +1149,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (face > -1) { texcolor = tex.CreateFace((uint)face).RGBA; - texcolor.A = (float)Math.Abs(alpha); + texcolor.A = (float)Math.Min(Math.Max(alpha, 0.0), 1.0); tex.FaceTextures[face].RGBA = texcolor; part.UpdateTexture(tex); return; @@ -1161,12 +1161,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (tex.FaceTextures[i] != null) { texcolor = tex.FaceTextures[i].RGBA; - texcolor.A = (float)Math.Abs(alpha); + texcolor.A = (float)Math.Min(Math.Max(alpha, 0.0), 1.0); tex.FaceTextures[i].RGBA = texcolor; } } texcolor = tex.DefaultTexture.RGBA; - texcolor.A = (float)Math.Abs(alpha); + texcolor.A = (float)Math.Min(Math.Max(alpha, 0.0), 1.0); tex.DefaultTexture.RGBA = texcolor; part.UpdateTexture(tex); return; @@ -2710,9 +2710,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (face > -1) { texcolor = tex.CreateFace((uint)face).RGBA; - texcolor.R = (float)Math.Abs(color.x - 1); - texcolor.G = (float)Math.Abs(color.y - 1); - texcolor.B = (float)Math.Abs(color.z - 1); + texcolor.R = (float)Math.Min(Math.Max(color.x, 0.0), 1.0); + texcolor.G = (float)Math.Min(Math.Max(color.y, 0.0), 1.0); + texcolor.B = (float)Math.Min(Math.Max(color.z, 0.0), 1.0); tex.FaceTextures[face].RGBA = texcolor; part.UpdateTexture(tex); return; @@ -2720,25 +2720,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api else if (face == -1) { texcolor = tex.DefaultTexture.RGBA; - texcolor.R = (float)Math.Abs(color.x - 1); - texcolor.G = (float)Math.Abs(color.y - 1); - texcolor.B = (float)Math.Abs(color.z - 1); + texcolor.R = (float)Math.Min(Math.Max(color.x, 0.0), 1.0); + texcolor.G = (float)Math.Min(Math.Max(color.y, 0.0), 1.0); + texcolor.B = (float)Math.Min(Math.Max(color.z, 0.0), 1.0); tex.DefaultTexture.RGBA = texcolor; for (uint i = 0; i < 32; i++) { if (tex.FaceTextures[i] != null) { texcolor = tex.FaceTextures[i].RGBA; - texcolor.R = (float)Math.Abs(color.x - 1); - texcolor.G = (float)Math.Abs(color.y - 1); - texcolor.B = (float)Math.Abs(color.z - 1); + texcolor.R = (float)Math.Min(Math.Max(color.x, 0.0), 1.0); + texcolor.G = (float)Math.Min(Math.Max(color.y, 0.0), 1.0); + texcolor.B = (float)Math.Min(Math.Max(color.z, 0.0), 1.0); tex.FaceTextures[i].RGBA = texcolor; } } texcolor = tex.DefaultTexture.RGBA; - texcolor.R = (float)Math.Abs(color.x - 1); - texcolor.G = (float)Math.Abs(color.y - 1); - texcolor.B = (float)Math.Abs(color.z - 1); + texcolor.R = (float)Math.Min(Math.Max(color.x, 0.0), 1.0); + texcolor.G = (float)Math.Min(Math.Max(color.y, 0.0), 1.0); + texcolor.B = (float)Math.Min(Math.Max(color.z, 0.0), 1.0); tex.DefaultTexture.RGBA = texcolor; part.UpdateTexture(tex); return; @@ -2757,34 +2757,34 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (face > -1) { texcolor = tex.CreateFace((uint)face).RGBA; - texcolor.R = (float)Math.Abs(color.x - 1); - texcolor.G = (float)Math.Abs(color.y - 1); - texcolor.B = (float)Math.Abs(color.z - 1); + texcolor.R = (float)Math.Min(Math.Max(color.x, 0.0), 1.0); + texcolor.G = (float)Math.Min(Math.Max(color.y, 0.0), 1.0); + texcolor.B = (float)Math.Min(Math.Max(color.z, 0.0), 1.0); tex.FaceTextures[face].RGBA = texcolor; part.UpdateTexture(tex); } else if (face == -1) { texcolor = tex.DefaultTexture.RGBA; - texcolor.R = (float)Math.Abs(color.x - 1); - texcolor.G = (float)Math.Abs(color.y - 1); - texcolor.B = (float)Math.Abs(color.z - 1); + texcolor.R = (float)Math.Min(Math.Max(color.x, 0.0), 1.0); + texcolor.G = (float)Math.Min(Math.Max(color.y, 0.0), 1.0); + texcolor.B = (float)Math.Min(Math.Max(color.z, 0.0), 1.0); tex.DefaultTexture.RGBA = texcolor; for (uint i = 0; i < 32; i++) { if (tex.FaceTextures[i] != null) { texcolor = tex.FaceTextures[i].RGBA; - texcolor.R = (float)Math.Abs(color.x - 1); - texcolor.G = (float)Math.Abs(color.y - 1); - texcolor.B = (float)Math.Abs(color.z - 1); + texcolor.R = (float)Math.Min(Math.Max(color.x, 0.0), 1.0); + texcolor.G = (float)Math.Min(Math.Max(color.y, 0.0), 1.0); + texcolor.B = (float)Math.Min(Math.Max(color.z, 0.0), 1.0); tex.FaceTextures[i].RGBA = texcolor; } } texcolor = tex.DefaultTexture.RGBA; - texcolor.R = (float)Math.Abs(color.x - 1); - texcolor.G = (float)Math.Abs(color.y - 1); - texcolor.B = (float)Math.Abs(color.z - 1); + texcolor.R = (float)Math.Min(Math.Max(color.x, 0.0), 1.0); + texcolor.G = (float)Math.Min(Math.Max(color.y, 0.0), 1.0); + texcolor.B = (float)Math.Min(Math.Max(color.z, 0.0), 1.0); tex.DefaultTexture.RGBA = texcolor; part.UpdateTexture(tex); } @@ -5959,7 +5959,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (face > -1) { texcolor = tex.CreateFace((uint)face).RGBA; - texcolor.A = (float)Math.Abs(alpha - 1); + texcolor.A = (float)Math.Min(Math.Max(alpha, 0.0), 1.0); tex.FaceTextures[face].RGBA = texcolor; part.UpdateTexture(tex); return; @@ -5967,19 +5967,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api else if (face == -1) { texcolor = tex.DefaultTexture.RGBA; - texcolor.A = (float)Math.Abs(alpha - 1); + texcolor.A = (float)Math.Min(Math.Max(alpha, 0.0), 1.0); tex.DefaultTexture.RGBA = texcolor; for (uint i = 0; i < 32; i++) { if (tex.FaceTextures[i] != null) { texcolor = tex.FaceTextures[i].RGBA; - texcolor.A = (float)Math.Abs(alpha - 1); + texcolor.A = (float)Math.Min(Math.Max(alpha, 0.0), 1.0); tex.FaceTextures[i].RGBA = texcolor; } } texcolor = tex.DefaultTexture.RGBA; - texcolor.A = (float)Math.Abs(alpha - 1); + texcolor.A = (float)Math.Min(Math.Max(alpha, 0.0), 1.0); tex.DefaultTexture.RGBA = texcolor; part.UpdateTexture(tex); return; @@ -5998,26 +5998,26 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (face > -1) { texcolor = tex.CreateFace((uint)face).RGBA; - texcolor.A = (float)Math.Abs(alpha - 1); + texcolor.A = (float)Math.Min(Math.Max(alpha, 0.0), 1.0); tex.FaceTextures[face].RGBA = texcolor; part.UpdateTexture(tex); } else if (face == -1) { texcolor = tex.DefaultTexture.RGBA; - texcolor.A = (float)Math.Abs(alpha - 1); + texcolor.A = (float)Math.Min(Math.Max(alpha, 0.0), 1.0); tex.DefaultTexture.RGBA = texcolor; for (uint i = 0; i < 32; i++) { if (tex.FaceTextures[i] != null) { texcolor = tex.FaceTextures[i].RGBA; - texcolor.A = (float)Math.Abs(alpha - 1); + texcolor.A = (float)Math.Min(Math.Max(alpha, 0.0), 1.0); tex.FaceTextures[i].RGBA = texcolor; } } texcolor = tex.DefaultTexture.RGBA; - texcolor.A = (float)Math.Abs(alpha - 1); + texcolor.A = (float)Math.Min(Math.Max(alpha, 0.0), 1.0); tex.DefaultTexture.RGBA = texcolor; part.UpdateTexture(tex); } -- cgit v1.1