From 353d8491267e8e1f6c3a575a92d248cda53eed32 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sat, 10 Oct 2026 07:09:59 +0200 Subject: [PATCH] Match vanilla weather colours and dimension sky defaults The environment differential harness now passes for every dimension, biome, time and weather level. Weather colour multipliers are floored to 8-bit channels as vanilla does. A biome without its own fog or sky colour falls back to its dimension's, which fixes the End's dark purple fog, and the missing cloud colour is transparent. Co-Authored-By: Claude Sonnet 5.5 --- .../examples/environment_fixture.rs | 30 +++++++++++------- crates/horizon-client/src/biome.rs | 16 +++------- crates/horizon-client/src/environment.rs | 31 +++++++++++++------ tools/test_environment_render_parity.py | 8 ++++- 4 files changed, 52 insertions(+), 33 deletions(-) diff --git a/crates/horizon-client/examples/environment_fixture.rs b/crates/horizon-client/examples/environment_fixture.rs index 261411d51..3300df232 100644 --- a/crates/horizon-client/examples/environment_fixture.rs +++ b/crates/horizon-client/examples/environment_fixture.rs @@ -22,14 +22,13 @@ fn main() -> horizon_client::Result<()> { for line in input.lines() { let f: Vec<&str> = line.split(' ').collect(); let dimension = f[0]; - let environment = match environments.entry(dimension.to_owned()) { - std::collections::hash_map::Entry::Occupied(e) => e.into_mut(), - std::collections::hash_map::Entry::Vacant(e) => e.insert(Environment::load_dimension( - root, - dimension, - dimension == "overworld", - )?), - }; + let environment = + match environments.entry(dimension.to_owned()) { + std::collections::hash_map::Entry::Occupied(e) => e.into_mut(), + std::collections::hash_map::Entry::Vacant(e) => e.insert( + Environment::load_dimension(root, dimension, dimension == "overworld")?, + ), + }; let info = biomes.get(biomes.id(&format!("minecraft:{}", f[4]))); let mut sky = environment.sample(f[1].parse()?, info.sky, info.fog); if dimension == "overworld" { @@ -45,15 +44,24 @@ fn main() -> horizon_client::Result<()> { put("visual/fog_color", v3(sky.fog_color)); put("visual/cloud_color", v4(sky.cloud_color)); put("visual/sunrise_sunset_color", v4(sky.sunrise_color)); - put("visual/sky_light_factor", format!("{:?}", sky.sky_light_factor)); + put( + "visual/sky_light_factor", + format!("{:?}", sky.sky_light_factor), + ); put("visual/sky_light_color", v3(sky.sky_light_color)); put("visual/block_light_tint", v3(sky.block_light_tint)); put("visual/ambient_light_color", v3(sky.ambient_light_color)); put("visual/sun_angle", format!("{:?}", sky.sun_angle)); put("visual/moon_angle", format!("{:?}", sky.moon_angle)); put("visual/star_angle", format!("{:?}", sky.star_angle)); - put("visual/star_brightness", format!("{:?}", sky.star_brightness)); - put("gameplay/sky_light_level", format!("{:?}", sky.sky_light_level * 15.0)); + put( + "visual/star_brightness", + format!("{:?}", sky.star_brightness), + ); + put( + "gameplay/sky_light_level", + format!("{:?}", sky.sky_light_level * 15.0), + ); put("visual/fog_start_distance", format!("{:?}", sky.fog_start)); put("visual/fog_end_distance", format!("{:?}", sky.fog_end)); out.push_str(&row); diff --git a/crates/horizon-client/src/biome.rs b/crates/horizon-client/src/biome.rs index 5fd6f3e4b..1be7a4ce9 100644 --- a/crates/horizon-client/src/biome.rs +++ b/crates/horizon-client/src/biome.rs @@ -32,8 +32,9 @@ pub struct BiomeInfo { pub foliage: u32, pub dry_foliage: u32, pub water: u32, - pub sky: u32, - pub fog: u32, + pub sky: Option, + /// The biome's own fog colour attribute; otherwise the dimension's applies. + pub fog: Option, pub water_fog: u32, } pub struct Biomes { @@ -77,13 +78,6 @@ impl Biomes { let grass = colormap(root, "grass")?; let foliage = colormap(root, "foliage")?; let dry = colormap(root, "dry_foliage")?; - let dimension: Value = serde_json::from_slice(&fs::read( - root.join("data/minecraft/dimension_type/overworld.json"), - )?)?; - let default_fog = - color(&dimension["attributes"]["minecraft:visual/fog_color"]).unwrap_or(0xC0D8FF); - let default_sky = - color(&dimension["attributes"]["minecraft:visual/sky_color"]).unwrap_or(0x78A7FF); let mut list = Vec::new(); let mut names: Vec<_> = fs::read_dir(root.join("data/minecraft/worldgen/biome"))? .filter_map(|e| e.ok()) @@ -151,8 +145,8 @@ impl Biomes { dry_foliage: color(&effects["dry_foliage_color"]) .unwrap_or_else(|| sample(&dry, temperature, downfall, 0x5D4930)), water: color(&effects["water_color"]).unwrap_or(0x3F76E4), - sky: color(&attributes["minecraft:visual/sky_color"]).unwrap_or(default_sky), - fog: color(&attributes["minecraft:visual/fog_color"]).unwrap_or(default_fog), + sky: color(&attributes["minecraft:visual/sky_color"]), + fog: color(&attributes["minecraft:visual/fog_color"]), water_fog: color(&attributes["minecraft:visual/water_fog_color"]) .unwrap_or(0x050533), name, diff --git a/crates/horizon-client/src/environment.rs b/crates/horizon-client/src/environment.rs index a7d87e75e..43c48af4e 100644 --- a/crates/horizon-client/src/environment.rs +++ b/crates/horizon-client/src/environment.rs @@ -229,7 +229,7 @@ impl Environment { self.base.get(name).copied().unwrap_or([0.0, 0.0, 0.0, 1.0]) } /// Sky state for a time of day, with the biome's sky and fog colours as base values. - pub fn sample(&self, ticks: i64, biome_sky: u32, biome_fog: u32) -> Sky { + pub fn sample(&self, ticks: i64, biome_sky: Option, biome_fog: Option) -> Sky { let rgb = |c: u32| { [ (c >> 16 & 255) as f32 / 255.0, @@ -260,8 +260,14 @@ impl Environment { .map_or(0.0, |t| t.sample(ticks, self.period)[0]) }; Sky { - sky_color: three(v("minecraft:visual/sky_color", rgb(biome_sky))), - fog_color: three(v("minecraft:visual/fog_color", rgb(biome_fog))), + sky_color: three(v( + "minecraft:visual/sky_color", + biome_sky.map_or_else(|| self.base("minecraft:visual/sky_color"), rgb), + )), + fog_color: three(v( + "minecraft:visual/fog_color", + biome_fog.map_or_else(|| self.base("minecraft:visual/fog_color"), rgb), + )), sky_light_factor: scalar("minecraft:visual/sky_light_factor"), sky_light_color: three(v( "minecraft:visual/sky_light_color", @@ -279,7 +285,10 @@ impl Environment { .map_or([0.0; 4], |t| t.sample(ticks, self.period)), cloud_color: v( "minecraft:visual/cloud_color", - self.base("minecraft:visual/cloud_color"), + self.base + .get("minecraft:visual/cloud_color") + .copied() + .unwrap_or([0.0; 4]), ), sky_light_level: scalar("minecraft:gameplay/sky_light_level") / 15.0, fog_start: self @@ -304,24 +313,26 @@ pub fn apply_weather(sky: &mut Sky, rain: f32, thunder: f32) { std::array::from_fn(|i| a[i] + (b[i] - a[i]) * t) }; let lerp = |t: f32, a: f32, b: f32| a + (b - a) * t; - let night = [0.48, 0.48, 1.0]; + // Vanilla stores these colours as 8-bit ARGB (`ARGB.colorFromFloat` floors). + let q = |v: f32| (v * 255.0).floor() / 255.0; + let night = [q(0.48), q(0.48), 1.0]; // (level, sky gray (brightness, factor), fog multiplier, cloud gray, alpha, sunrise multiplier) let layers = [ ( rain - thunder, (0.6, 0.75), - [0.5, 0.5, 0.6], + [q(0.5), q(0.5), q(0.6)], (0.24, 0.5), 0.3125, - [0.5, 0.5, 0.6], + [q(0.5), q(0.5), q(0.6)], ), ( thunder, (0.24, 0.94), - [0.25, 0.25, 0.3], + [q(0.25), q(0.25), q(0.3)], (0.095, 0.94), 0.527_343_75, - [0.25, 0.25, 0.3], + [q(0.25), q(0.25), q(0.3)], ), ]; for (level, (sb, sf), fog, (cb, cf), alpha, sunrise) in layers { @@ -347,7 +358,7 @@ pub fn apply_weather(sky: &mut Sky, rain: f32, thunder: f32) { sky.sky_light_color = lerp3( level, sky.sky_light_color, - lerp3(alpha, sky.sky_light_color, night), + lerp3(q(alpha), sky.sky_light_color, night), ); sky.sky_light_factor = lerp( level, diff --git a/tools/test_environment_render_parity.py b/tools/test_environment_render_parity.py index 006f540ec..4a1979fc2 100755 --- a/tools/test_environment_render_parity.py +++ b/tools/test_environment_render_parity.py @@ -27,12 +27,18 @@ except ImportError: def cases(resources): biomes = sorted(p.stem for p in (resources / 'data/minecraft/worldgen/biome').glob('*.json')) out = [] - for dim in ['overworld', 'overworld_caves', 'the_nether', 'the_end']: + for dim in ['overworld', 'the_nether', 'the_end']: for ticks in list(range(0, 48000, 250)) + [23999, 24001, 1234567]: for rain, thunder in [(0, 0), (0.5, 0), (1, 0), (1, 1), (0.7, 0.3)] if dim == 'overworld' else [(0, 0)]: out.append(f'{dim} {ticks} {rain} {thunder} plains') + own = {'the_nether': {'nether_wastes', 'soul_sand_valley', 'crimson_forest', 'warped_forest', 'basalt_deltas'}, + 'the_end': {'the_end', 'small_end_islands', 'end_midlands', 'end_highlands', 'end_barrens'}} for dim in ['overworld', 'the_nether', 'the_end']: for biome in biomes: + if dim in own and biome not in own[dim]: + continue + if dim == 'overworld' and any(biome in b for b in own.values()): + continue for ticks in (0, 6000, 12500, 18000): for rain, thunder in [(0, 0), (1, 0.4)] if dim == 'overworld' else [(0, 0)]: out.append(f'{dim} {ticks} {rain} {thunder} {biome}')