Merge pull request #260 from Online5277/fix/cloud-settings

Honor Off, Fast and Fancy cloud settings
This commit is contained in:
Ludovic Marie
2026-10-15 04:38:40 +02:00
committed by GitHub
2 changed files with 60 additions and 5 deletions
+48 -1
View File
@@ -1,4 +1,20 @@
//! Fancy cloud face selection (`CloudRenderer.buildExtrudedCell`).
//! Cloud visibility and flat/fancy cell geometry (`CloudRenderer`).
/// `LevelRenderer`: skip OFF clouds and colors with no packed alpha.
pub fn visible(mode: &str, alpha: f32) -> bool {
mode != "false" && (alpha.clamp(0.0, 1.0) * 255.0) as u8 > 0
}
/// `buildFlatCell`: bottom plane, in both windings for the culled cloud pipeline.
pub fn flat_cell(x: f32, z: f32, bottom: f32) -> [[[f32; 3]; 4]; 2] {
let p = [
[x + 12.0, bottom, z],
[x + 12.0, bottom, z + 12.0],
[x, bottom, z + 12.0],
[x, bottom, z],
];
[p, [p[3], p[2], p[1], p[0]]]
}
/// Direction order is DOWN, UP, NORTH, SOUTH, WEST, EAST; inward faces use bits 6..12.
pub fn face_mask(x: i32, z: i32, bottom: f32, empty: [bool; 4]) -> u16 {
let mut mask = 0;
@@ -55,6 +71,37 @@ pub fn cells(radius: i32) -> impl Iterator<Item = (i32, i32)> {
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn settings_and_packed_alpha_gate_clouds() {
for mode in ["false", "fast", "true"] {
assert_eq!(visible(mode, 1.0), mode != "false");
assert!(!visible(mode, 0.0));
assert!(!visible(mode, 0.5 / 255.0));
}
assert!(visible("fast", 1.0 / 255.0));
}
#[test]
fn fast_cells_are_flat_at_the_bottom_and_visible_from_both_sides() {
for bottom in [-10.0, 0.0, 10.0] {
let [down, up] = flat_cell(-3.0, 7.0, bottom);
assert_eq!(
down,
[
[9.0, bottom, 7.0],
[9.0, bottom, 19.0],
[-3.0, bottom, 19.0],
[-3.0, bottom, 7.0],
]
);
assert_eq!(up, [down[3], down[2], down[1], down[0]]);
for (quad, sign) in [(down, -1.0), (up, 1.0)] {
let [a, b, c] = [quad[0], quad[1], quad[2]].map(glam::Vec3::from_array);
assert!((b - a).cross(c - a).y * sign > 0.0);
}
}
}
#[test]
fn cells_are_nearest_first_and_unique() {
let cells: Vec<_> = cells(2).collect();
+12 -4
View File
@@ -5649,7 +5649,7 @@ impl Game<'_> {
}
out
}
/// CloudRenderer (fancy): 12x4x12 cells from clouds.png drifting east.
/// CloudRenderer: flat or 12x4x12 extruded cells drifting east.
fn cloud_geometry(
&self,
sky: &horizon_client::environment::Sky,
@@ -5706,6 +5706,12 @@ impl Game<'_> {
});
}
};
if self.settings.clouds == "fast" {
for p in horizon_client::clouds::flat_cell(x0, z0, bottom) {
quad(p, 1.0);
}
continue;
}
let faces = [
(
[[x1, y0, z0], [x1, y0, z1], [x0, y0, z1], [x0, y0, z0]],
@@ -8052,9 +8058,11 @@ impl Game<'_> {
self.end_geometry(camera, &mut entities);
}
if (!title || live) && self.dim == Dim::Overworld {
horizon_client::spans::time("clouds", || {
self.cloud_geometry(&sky, camera, alpha, &mut entities)
});
if horizon_client::clouds::visible(&self.settings.clouds, sky.cloud_color[3]) {
horizon_client::spans::time("clouds", || {
self.cloud_geometry(&sky, camera, alpha, &mut entities)
});
}
if self.settings.horizon.weather {
horizon_client::spans::time("weather", || {
self.weather_geometry(camera, alpha, &mut entities)