From f191f38a3e4d45efd0ec1d7714b4331171cc8c6b Mon Sep 17 00:00:00 2001 From: Teravus Ovares Date: Sat, 16 Aug 2008 19:03:29 +0000 Subject: [PATCH] * Fix a rare maptile shading error, terrain difference mod 1 = 0 + abs = oops. --- OpenSim/Region/Environment/Scenes/Scene.cs | 49 ++++++---------------- 1 file changed, 13 insertions(+), 36 deletions(-) diff --git a/OpenSim/Region/Environment/Scenes/Scene.cs b/OpenSim/Region/Environment/Scenes/Scene.cs index ae7e3aa3b6..2e89e4b231 100644 --- a/OpenSim/Region/Environment/Scenes/Scene.cs +++ b/OpenSim/Region/Environment/Scenes/Scene.cs @@ -1085,8 +1085,10 @@ namespace OpenSim.Region.Environment.Scenes //float tmpval = (float)hm[x, y]; float heightvalue = (float)hm[x, y]; + if (heightvalue > (float)m_regInfo.RegionSettings.WaterHeight) { + // scale height value heightvalue = low + mid * (heightvalue - low) / mid; @@ -1108,13 +1110,14 @@ namespace OpenSim.Region.Environment.Scenes //X // . // - + // Shade the terrain for shadows if ((x - 1 > 0) && (y - 1 > 0)) { hfvalue = (float)hm[x, y]; hfvaluecompare = (float)hm[x - 1, y - 1]; hfdiff = hfvaluecompare - hfvalue; + if (Single.IsInfinity(hfvalue) || Single.IsNaN(hfvalue)) hfvalue = 0; @@ -1127,7 +1130,14 @@ namespace OpenSim.Region.Environment.Scenes } else if (hfdiff < -0.3f) { - hfdiffi = Math.Abs((int)((hfdiff * 4) + (hfdiff * 0.5))) + Math.Abs((int)(((hfdiff % 1) * 0.5f) * 10f)); + // We have to desaturate and blacken the land at the same time + // we use floats, colors use bytes, so shrink are space down to + // 0-255 + hfdiffi = Math.Abs((int)((hfdiff * 4) + (hfdiff * 0.5))) + 1; + if (hfdiff % 1 != 0) + { + hfdiffi = hfdiffi + Math.Abs((int)(((hfdiff % 1) * 0.5f) * 10f) + 1); + } //hfdiffi2 = (int)(hfdiff * 0.5f) + 1; if ((256 - y) - 1 > 0) { @@ -1146,40 +1156,7 @@ namespace OpenSim.Region.Environment.Scenes } - /* - // - // . - // X - if ((x + 1 < 255) && (y + 1 < 255)) - { - hfvalue = (float)hm[x, y]; - hfvaluecompare = (float)hm[x + 1, y + 1]; - hfdiff = hfvaluecompare - hfvalue; - - if (hfdiff > 0.3f) - { - - } - else if (hfdiff < -0.3f) - { - hfdiffi = Math.Abs((int)hfdiff) + 1; - if ((256 - y) + 1 < 256) - { - Color Shade = mapbmp.GetPixel(x + 1, (256 - y) + 1); - - int r = Shade.R; - int g = Shade.G; - int b = Shade.B; - Shade = Color.FromArgb((r - hfdiffi > 0) ? r - hfdiffi : 0, (g - hfdiffi > 0) ? g - hfdiffi : 0, (b - hfdiffi > 0) ? g - hfdiffi : 0); - mapbmp.SetPixel(x + 1, (256 - y) + 1, Shade); - } - - } - - - } - */ - //if ((x + }