From b650b096ef13563d017d41151ad14323dda3fc8e Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Thu, 3 Aug 2023 18:31:45 +0200 Subject: [PATCH] resource: return block color as float vector Deferring conversion to integers is convenient for biome smoothing. --- src/bin/minedmap/tile_renderer.rs | 9 +++++++-- src/resource/block_color.rs | 6 ++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/bin/minedmap/tile_renderer.rs b/src/bin/minedmap/tile_renderer.rs index fed99bb..c931c72 100644 --- a/src/bin/minedmap/tile_renderer.rs +++ b/src/bin/minedmap/tile_renderer.rs @@ -4,6 +4,7 @@ use std::{ }; use anyhow::{Context, Result}; +use glam::Vec3; use num_integer::div_mod_floor; use minedmap::{ @@ -82,7 +83,7 @@ impl<'a> TileRenderer<'a> { chunk: &ProcessedChunk, _chunk_coords: ChunkCoords, block_coords: LayerBlockCoords, - ) -> Option<[u8; 4]> { + ) -> Option { let block = chunk.blocks[block_coords]?; let depth = chunk.depths[block_coords]?; @@ -109,7 +110,11 @@ impl<'a> TileRenderer<'a> { z: BlockZ::new(z), }; let color = Self::block_color_at(region_group, chunk, chunk_coords, block_coords); - image::Rgba(color.unwrap_or_default()) + image::Rgba( + color + .map(|c| [c[0] as u8, c[1] as u8, c[2] as u8, 255]) + .unwrap_or_default(), + ) }); overlay_chunk(image, &chunk_image, chunk_coords); } diff --git a/src/resource/block_color.rs b/src/resource/block_color.rs index 0b6e935..b98aec9 100644 --- a/src/resource/block_color.rs +++ b/src/resource/block_color.rs @@ -78,7 +78,7 @@ pub fn needs_biome(block: BlockType) -> bool { block.is(Grass) || block.is(Foliage) || block.is(Water) } -pub fn block_color(block: BlockType, biome: Option<&Biome>, depth: f32) -> [u8; 4] { +pub fn block_color(block: BlockType, biome: Option<&Biome>, depth: f32) -> Vec3 { use super::BlockFlag::*; let get_biome = || biome.expect("needs biome to determine block color"); @@ -101,7 +101,5 @@ pub fn block_color(block: BlockType, biome: Option<&Biome>, depth: f32) -> [u8; color *= get_biome().water_color(); } - color *= 0.5 + 0.005 * depth; - - [color[0] as u8, color[1] as u8, color[2] as u8, 255] + color * (0.5 + 0.005 * depth) }