diff --git a/world/Cargo.toml b/world/Cargo.toml index 8f2160c186..c96c114004 100644 --- a/world/Cargo.toml +++ b/world/Cargo.toml @@ -60,3 +60,7 @@ name = "tree" [[example]] name = "chunk_compression_benchmarks" required-features = ["bin_compression"] + +[[example]] +name = "heightmap_visualization" +required-features = ["bin_compression"] diff --git a/world/examples/heightmap_visualization.rs b/world/examples/heightmap_visualization.rs index e821fdb13b..96ec9e3fcf 100644 --- a/world/examples/heightmap_visualization.rs +++ b/world/examples/heightmap_visualization.rs @@ -128,6 +128,13 @@ fn main() { image_with_autorange("heightmap.png", 1024, 1024, rgb_from_scalar, |x, y| { land.get_alt_approx(Vec2::new(x as i32 * 32, y as i32 * 32)) }); + image_with_autorange( + "heightmap_big.png", + 1024 * 4, + 1024 * 4, + rgb_from_scalar, + |x, y| land.get_alt_approx(Vec2::new(x as i32 * 8, y as i32 * 8)), + ); image_with_autorange("heightmap_dx.png", 1024, 1024, grey_from_scalar, |x, y| { let mut v = 0.0; for i in -1i32..=1 { @@ -175,35 +182,58 @@ fn main() { (dx * dx + dy * dy).sqrt() }, ); - for i in 1..=100 { - #[rustfmt::skip] - // convert -delay 10 -loop 0 -dispose previous heightmap_delta_{001..100}.png heightmap_thresholds.gif - // convert -delay 20 -loop 0 -dispose previous $(seq 1 3 100 | xargs printf "heightmap_delta_%03d.png ") heightmap_thresholds.gif - image_with_autorange( - &format!("heightmap_delta_{:03}.png", i), - 1024, - 1024, - grey_from_scalar_thresh(i as f32 * 0.01), - |x, y| { - let mut v = 0.0; - for i in -1i32..=1 { - for j in -1i32..=1 { - let tmp = if i == 0 && j == 0 { - 1.0 - } else if (i + j).abs() == 1 { - -0.25 - } else { - 0.0 - }; - v += tmp as f32 - * land.get_alt_approx(Vec2::new( + if false { + for i in 1..=100 { + #[rustfmt::skip] + // convert -delay 10 -loop 0 -dispose previous heightmap_delta_{001..100}.png heightmap_thresholds.gif + // convert -delay 20 -loop 0 -dispose previous $(seq 1 3 100 | xargs printf "heightmap_delta_%03d.png ") heightmap_thresholds.gif + image_with_autorange( + &format!("heightmap_delta_{:03}.png", i), + 1024, + 1024, + grey_from_scalar_thresh(i as f32 * 0.01), + |x, y| { + let mut v = 0.0; + for i in -1i32..=1 { + for j in -1i32..=1 { + let tmp = if i == 0 && j == 0 { + 1.0 + } else if (i + j).abs() == 1 { + -0.25 + } else { + 0.0 + }; + v += tmp as f32 + * land.get_alt_approx(Vec2::new( + (x as i32 + i) * 32, + (y as i32 + j) * 32, + )); + } + } + v + }, + ); + } + } + image_with_autorange( + "heightmap_max5.png", + 1024, + 1024, + grey_from_scalar_thresh(0.95), + |x, y| { + let mut v = -f32::INFINITY; + for i in -2i32..=2 { + for j in -2i32..=2 { + if i != 0 || j != 0 { + v = + v.max(land.get_alt_approx(Vec2::new( (x as i32 + i) * 32, (y as i32 + j) * 32, - )); + ))); } } - v - }, - ); - } + } + land.get_alt_approx(Vec2::new(x as i32 * 32, y as i32 * 32)) / v + }, + ); }