From 508336c58ad6f456d1ea4f2c93834f0a96a93d1d Mon Sep 17 00:00:00 2001 From: melchior Date: Tue, 18 May 2021 21:19:30 -0400 Subject: [PATCH] Fixed shading EDGE Defects on Chunk boundary / Missing data --- Automap/Renderers/StandardRenderer.cs | 47 +++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/Automap/Renderers/StandardRenderer.cs b/Automap/Renderers/StandardRenderer.cs index dab0414..415f488 100644 --- a/Automap/Renderers/StandardRenderer.cs +++ b/Automap/Renderers/StandardRenderer.cs @@ -1,5 +1,8 @@ using System; using System.Collections.Generic; +//using System.Drawing; +//using System.Drawing.Imaging; +//using System.IO; using System.Linq; using Hjg.Pngcs; @@ -52,8 +55,8 @@ namespace Automap // Prefetch map chunks, in pattern var corner_pos = new Vec2i(chunkPos.X - 1, chunkPos.Y - 1); - var west_pos = new Vec2i(chunkPos.X - 1, chunkPos.Y); - var north_pos = new Vec2i(chunkPos.X, chunkPos.Y - 1); + var west_pos = new Vec2i(chunkPos.X, chunkPos.Y - 1); + var north_pos = new Vec2i(chunkPos.X - 1 , chunkPos.Y); uint missingRainmap = 0, missingHeightmap = 0; @@ -132,6 +135,8 @@ namespace Automap if (badHeightData > 0) Logger.VerboseDebug("H.M Zeros# {0} , Missing Rainmaps {1} Heightmaps {2}",badHeightData ,missingRainmap, missingHeightmap); + + //RenderDebugBitmap(overlapHeightmap, chunkPos); #endif @@ -162,16 +167,18 @@ namespace Automap int west_Z = localZ + 1; int northWest_X = localX; int northWest_Z = localZ; - + bool edge = localX == 0 || localZ == 0; - northH = Math.Sign(localY - (overlapHeightmap[north_X, north_Z] == 0 ? avgOverlap_Y : overlapHeightmap[north_X, north_Z])); - northWestH = Math.Sign(localY - (overlapHeightmap[northWest_X, northWest_Z] == 0 ? avgOverlap_Y : overlapHeightmap[northWest_X, northWest_Z])); - westH = Math.Sign(localY - (overlapHeightmap[west_X, west_Z] == 0 ? avgOverlap_Y : overlapHeightmap[west_X, west_Z])); + northH = Math.Sign(localY - (overlapHeightmap[north_X, north_Z] == 0 ? localY : overlapHeightmap[north_X, north_Z])); + northWestH = Math.Sign(localY - (overlapHeightmap[northWest_X, northWest_Z] == 0 ? localY : overlapHeightmap[northWest_X, northWest_Z])); + westH = Math.Sign(localY - (overlapHeightmap[west_X, west_Z] == 0 ? localY : overlapHeightmap[west_X, west_Z])); float slopeness = (northH + northWestH + westH); + float tolerance = edge ? 2.0f : 0f; + - if (slopeness > 0) slopeBoost = 1.2f; - if (slopeness < 0) slopeBoost = 0.8f; + if (slopeness > tolerance) slopeBoost = 1.2f; + if (slopeness < tolerance) slopeBoost = 0.8f; if (Math.Abs(slopeness) <= float.Epsilon) slopeBoost = 1.0f;//Same height //slopeBoost -= 0.15f; //Slope boost value @@ -207,5 +214,29 @@ namespace Automap this.PngWriter.End( ); } + + /* + private void RenderDebugBitmap( ushort[ , ] heightmap, Vec2i chunkOrigin ) + { + Bitmap mapBitmap = null; + Graphics gContext = null; + mapBitmap = new Bitmap(33, 33, PixelFormat.Format24bppRgb); + gContext = Graphics.FromImage(mapBitmap); + + for (int x = 0; x <= chunkSize; x++) { + for (int y = 0; y <= chunkSize; y++) { + ushort heightCol = heightmap[x, y]; + Color color= Color.FromArgb((byte)heightCol,( byte )heightCol,( byte )heightCol); + mapBitmap.SetPixel(x, y, color); + } + } + + gContext.Flush(System.Drawing.Drawing2D.FlushIntention.Sync); + + var fileName = Path.Combine( ClientAPI.GetOrCreateDataPath("Heightmaps"),$"offhm_{chunkOrigin.X}-{chunkOrigin.Y}.png"); + mapBitmap.Save(fileName, ImageFormat.Png); + + } + */ } } \ No newline at end of file -- 2.11.0