From c38f00e4114c071463429801b9bb5fcb314b3291 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Thu, 3 Aug 2023 19:06:20 +0200 Subject: [PATCH] minedmap/tile_renderer: implement biome smoothing Rather than the diamond-shaped kernel used by the old implemenation, we now use the approximation of a Gauss filter. In addition, the kernel size is decreased, reducing the strength of the blur effect. --- src/bin/minedmap/tile_renderer.rs | 32 +++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/src/bin/minedmap/tile_renderer.rs b/src/bin/minedmap/tile_renderer.rs index c931c72..c66431f 100644 --- a/src/bin/minedmap/tile_renderer.rs +++ b/src/bin/minedmap/tile_renderer.rs @@ -79,11 +79,15 @@ impl<'a> TileRenderer<'a> { } fn block_color_at( - _region_group: &RegionGroup, + region_group: &RegionGroup, chunk: &ProcessedChunk, - _chunk_coords: ChunkCoords, + chunk_coords: ChunkCoords, block_coords: LayerBlockCoords, ) -> Option { + const SMOOTH: [[f32; 3]; 3] = [[41.0, 26.0, 7.0], [26.0, 16.0, 4.0], [7.0, 4.0, 1.0]]; + const X: isize = SMOOTH[0].len() as isize - 1; + const Z: isize = SMOOTH.len() as isize - 1; + let block = chunk.blocks[block_coords]?; let depth = chunk.depths[block_coords]?; @@ -91,9 +95,29 @@ impl<'a> TileRenderer<'a> { return Some(block_color(block, None, depth.0 as f32)); } - let biome = chunk.biomes[block_coords].as_ref()?; + let mut total = 0.0; + let mut color = Vec3::ZERO; + for dz in -Z..=Z { + for dx in -X..=X { + let w = SMOOTH[dz.unsigned_abs()][dx.unsigned_abs()]; + if w == 0.0 { + continue; + } - Some(block_color(block, Some(biome), depth.0 as f32)) + let Some(biome) = biome_at(region_group, chunk_coords, block_coords, dx as i32, dz as i32) else { + continue; + }; + + total += w; + color += w * block_color(block, Some(biome), depth.0 as f32); + } + } + + if total == 0.0 { + return None; + } + + Some(color / total) } fn render_chunk(