Automap (client) [VS plugin mod]
Révision | 508336c58ad6f456d1ea4f2c93834f0a96a93d1d (tree) |
---|---|
l'heure | 2021-05-19 10:19:30 |
Auteur | melchior <melchior@user...> |
Commiter | melchior |
Fixed shading EDGE Defects on Chunk boundary / Missing data
@@ -1,5 +1,8 @@ | ||
1 | 1 | using System; |
2 | 2 | using System.Collections.Generic; |
3 | +//using System.Drawing; | |
4 | +//using System.Drawing.Imaging; | |
5 | +//using System.IO; | |
3 | 6 | using System.Linq; |
4 | 7 | |
5 | 8 | using Hjg.Pngcs; |
@@ -52,8 +55,8 @@ namespace Automap | ||
52 | 55 | |
53 | 56 | // Prefetch map chunks, in pattern |
54 | 57 | var corner_pos = new Vec2i(chunkPos.X - 1, chunkPos.Y - 1); |
55 | - var west_pos = new Vec2i(chunkPos.X - 1, chunkPos.Y); | |
56 | - var north_pos = new Vec2i(chunkPos.X, chunkPos.Y - 1); | |
58 | + var west_pos = new Vec2i(chunkPos.X, chunkPos.Y - 1); | |
59 | + var north_pos = new Vec2i(chunkPos.X - 1 , chunkPos.Y); | |
57 | 60 | |
58 | 61 | uint missingRainmap = 0, missingHeightmap = 0; |
59 | 62 |
@@ -132,6 +135,8 @@ namespace Automap | ||
132 | 135 | |
133 | 136 | if (badHeightData > 0) |
134 | 137 | Logger.VerboseDebug("H.M Zeros# {0} , Missing Rainmaps {1} Heightmaps {2}",badHeightData ,missingRainmap, missingHeightmap); |
138 | + | |
139 | + //RenderDebugBitmap(overlapHeightmap, chunkPos); | |
135 | 140 | #endif |
136 | 141 | |
137 | 142 |
@@ -162,16 +167,18 @@ namespace Automap | ||
162 | 167 | int west_Z = localZ + 1; |
163 | 168 | int northWest_X = localX; |
164 | 169 | int northWest_Z = localZ; |
165 | - | |
170 | + bool edge = localX == 0 || localZ == 0; | |
166 | 171 | |
167 | - northH = Math.Sign(localY - (overlapHeightmap[north_X, north_Z] == 0 ? avgOverlap_Y : overlapHeightmap[north_X, north_Z])); | |
168 | - northWestH = Math.Sign(localY - (overlapHeightmap[northWest_X, northWest_Z] == 0 ? avgOverlap_Y : overlapHeightmap[northWest_X, northWest_Z])); | |
169 | - westH = Math.Sign(localY - (overlapHeightmap[west_X, west_Z] == 0 ? avgOverlap_Y : overlapHeightmap[west_X, west_Z])); | |
172 | + northH = Math.Sign(localY - (overlapHeightmap[north_X, north_Z] == 0 ? localY : overlapHeightmap[north_X, north_Z])); | |
173 | + northWestH = Math.Sign(localY - (overlapHeightmap[northWest_X, northWest_Z] == 0 ? localY : overlapHeightmap[northWest_X, northWest_Z])); | |
174 | + westH = Math.Sign(localY - (overlapHeightmap[west_X, west_Z] == 0 ? localY : overlapHeightmap[west_X, west_Z])); | |
170 | 175 | |
171 | 176 | float slopeness = (northH + northWestH + westH); |
177 | + float tolerance = edge ? 2.0f : 0f; | |
178 | + | |
172 | 179 | |
173 | - if (slopeness > 0) slopeBoost = 1.2f; | |
174 | - if (slopeness < 0) slopeBoost = 0.8f; | |
180 | + if (slopeness > tolerance) slopeBoost = 1.2f; | |
181 | + if (slopeness < tolerance) slopeBoost = 0.8f; | |
175 | 182 | if (Math.Abs(slopeness) <= float.Epsilon) slopeBoost = 1.0f;//Same height |
176 | 183 | //slopeBoost -= 0.15f; //Slope boost value |
177 | 184 |
@@ -207,5 +214,29 @@ namespace Automap | ||
207 | 214 | |
208 | 215 | this.PngWriter.End( ); |
209 | 216 | } |
217 | + | |
218 | + /* | |
219 | + private void RenderDebugBitmap( ushort[ , ] heightmap, Vec2i chunkOrigin ) | |
220 | + { | |
221 | + Bitmap mapBitmap = null; | |
222 | + Graphics gContext = null; | |
223 | + mapBitmap = new Bitmap(33, 33, PixelFormat.Format24bppRgb); | |
224 | + gContext = Graphics.FromImage(mapBitmap); | |
225 | + | |
226 | + for (int x = 0; x <= chunkSize; x++) { | |
227 | + for (int y = 0; y <= chunkSize; y++) { | |
228 | + ushort heightCol = heightmap[x, y]; | |
229 | + Color color= Color.FromArgb((byte)heightCol,( byte )heightCol,( byte )heightCol); | |
230 | + mapBitmap.SetPixel(x, y, color); | |
231 | + } | |
232 | + } | |
233 | + | |
234 | + gContext.Flush(System.Drawing.Drawing2D.FlushIntention.Sync); | |
235 | + | |
236 | + var fileName = Path.Combine( ClientAPI.GetOrCreateDataPath("Heightmaps"),$"offhm_{chunkOrigin.X}-{chunkOrigin.Y}.png"); | |
237 | + mapBitmap.Save(fileName, ImageFormat.Png); | |
238 | + | |
239 | + } | |
240 | + */ | |
210 | 241 | } |
211 | 242 | } |
\ No newline at end of file |