mirror of
https://github.com/neocturne/MinedMap.git
synced 2025-03-04 17:23:33 +01:00
main: add height-based color modification
Modify terrain color depending on the height to give a sense of elevation.
This commit is contained in:
parent
46802116d9
commit
bcec704d27
2 changed files with 20 additions and 7 deletions
25
src/main.rs
25
src/main.rs
|
@ -10,7 +10,10 @@ use minedmap::{
|
|||
io::storage,
|
||||
resource,
|
||||
types::*,
|
||||
world::{self, layer::BlockLightArray},
|
||||
world::{
|
||||
self,
|
||||
layer::{BlockInfo, BlockLightArray},
|
||||
},
|
||||
};
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
|
@ -275,6 +278,19 @@ impl<'a> TileRenderer<'a> {
|
|||
storage::read(&processed_path).context("Failed to load processed region data")
|
||||
}
|
||||
|
||||
fn block_color(block: &BlockInfo) -> [u8; 4] {
|
||||
let h = block
|
||||
.depth
|
||||
.map(|depth| 0.5 + 0.005 * depth.0 as f32)
|
||||
.unwrap_or_default();
|
||||
let c = block
|
||||
.block_type
|
||||
.color
|
||||
.0
|
||||
.map(|v| (f32::from(v) * h).clamp(0.0, 255.0) as u8);
|
||||
[c[0], c[1], c[2], 255]
|
||||
}
|
||||
|
||||
fn render_chunk(
|
||||
image: &mut image::RgbaImage,
|
||||
coords: ChunkCoords,
|
||||
|
@ -284,14 +300,11 @@ impl<'a> TileRenderer<'a> {
|
|||
|
||||
let chunk_image = image::RgbaImage::from_fn(N, N, |x, z| {
|
||||
image::Rgba(
|
||||
match chunk[LayerBlockCoords {
|
||||
match &chunk[LayerBlockCoords {
|
||||
x: BlockX(x as u8),
|
||||
z: BlockZ(z as u8),
|
||||
}] {
|
||||
Some(block) => {
|
||||
let c = block.block_type.color.0;
|
||||
[c[0], c[1], c[2], 255]
|
||||
}
|
||||
Some(block) => Self::block_color(block),
|
||||
None => [0, 0, 0, 0],
|
||||
},
|
||||
)
|
||||
|
|
|
@ -8,7 +8,7 @@ use crate::{
|
|||
};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct BlockHeight(i32);
|
||||
pub struct BlockHeight(pub i32);
|
||||
|
||||
impl BlockHeight {
|
||||
/// Constructs a new [BlockHeight] from section and block Y indices
|
||||
|
|
Loading…
Add table
Reference in a new issue