Improve biome color handling
This commit is contained in:
parent
d5acb0588d
commit
f8be801eac
|
@ -926,13 +926,15 @@ fn calculate_biome(snapshot: &world::Snapshot, x: i32, z: i32, img: &image::Dyna
|
||||||
for xx in -1 .. 2 {
|
for xx in -1 .. 2 {
|
||||||
for zz in -1 .. 2 {
|
for zz in -1 .. 2 {
|
||||||
let bi = snapshot.get_biome(x+xx, z+zz);
|
let bi = snapshot.get_biome(x+xx, z+zz);
|
||||||
let ix = bi.color_index & 0xFF;
|
let color_index = bi.get_color_index();
|
||||||
let iy = bi.color_index >> 8;
|
let ix = color_index & 0xFF;
|
||||||
|
let iy = color_index >> 8;
|
||||||
|
|
||||||
let ix = min(max(ix, 0), 255);
|
let ix = min(max(ix, 0), 255);
|
||||||
let iy = min(max(iy, 0), 255);
|
let iy = min(max(iy, 0), 255);
|
||||||
|
|
||||||
let col = img.get_pixel(ix as u32, iy as u32);
|
let col = img.get_pixel(ix as u32, iy as u32);
|
||||||
|
let col = bi.process_color(col);
|
||||||
r += col.data[0] as u32;
|
r += col.data[0] as u32;
|
||||||
g += col.data[1] as u32;
|
g += col.data[1] as u32;
|
||||||
b += col.data[2] as u32;
|
b += col.data[2] as u32;
|
||||||
|
|
|
@ -1,25 +1,46 @@
|
||||||
|
|
||||||
|
use image::Rgba;
|
||||||
|
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
pub struct Biome {
|
pub struct Biome {
|
||||||
pub id: usize,
|
pub id: usize,
|
||||||
pub temperature: f64,
|
pub temperature: f64,
|
||||||
pub moisture: f64,
|
pub moisture: f64,
|
||||||
pub color_index: usize,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Biome {
|
impl Biome {
|
||||||
const fn new(id: usize, t: f64, m: f64) -> Biome{
|
const fn new(id: usize, t: f64, m: f64) -> Biome {
|
||||||
Biome {
|
Biome {
|
||||||
id: id,
|
id: id,
|
||||||
temperature: t,
|
temperature: t,
|
||||||
moisture: m*t,
|
moisture: m*t,
|
||||||
color_index: (((1.0 - t) * 255.0) as usize) | ((((1.0 - (m*t)) * 255.0) as usize) << 8),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn by_id(id: usize) -> Biome {
|
pub fn by_id(id: usize) -> Biome {
|
||||||
*BY_ID.get(id).unwrap_or(&INVALID)
|
*BY_ID.get(id).unwrap_or(&INVALID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_color_index(self) -> usize {
|
||||||
|
let t = self.temperature.min(1.0).max(0.0);
|
||||||
|
let m = self.moisture.min(1.0).max(0.0);
|
||||||
|
(((1.0 - t) * 255.0) as usize) | ((((1.0 - (m*t)) * 255.0) as usize) << 8)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn process_color(self, col: Rgba<u8>) -> Rgba<u8> {
|
||||||
|
if self.id == ROOFED_FOREST.id || self.id == ROOFED_FOREST_MOUNTAINS.id {
|
||||||
|
Rgba {
|
||||||
|
data: [
|
||||||
|
((col.data[0] as u32 + 0x28) / 2) as u8,
|
||||||
|
((col.data[1] as u32 + 0x34) / 2) as u8,
|
||||||
|
((col.data[2] as u32 + 0x0A) / 2) as u8,
|
||||||
|
255
|
||||||
|
]
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
col
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! define_biomes {
|
macro_rules! define_biomes {
|
||||||
|
|
Loading…
Reference in New Issue