feat: wire vertical exaggeration through the shell #13

Merged
moldybits merged 25 commits from feat/terrain-gen-abstraction into main 2026-05-20 23:00:29 -04:00
Showing only changes of commit aed8df3bbe - Show all commits
+45 -1
View File
@@ -63,7 +63,8 @@ pub fn render_top_down(grid: &HeightGrid, scene: &Scene) -> RgbImage {
for y in 0..h { for y in 0..h {
for x in 0..w { for x in 0..w {
let elevation = grid.sample(x, y).unwrap_or(0.0) * vertical_exaggeration; let elevation = grid.sample(x, y).unwrap_or(0.0) * vertical_exaggeration;
let color = scene_color(scene, elevation); let (nx, nz) = normalized_coords(x, y, w, h);
let color = surface_color(scene, elevation, nx, nz);
img.put_pixel(x, y, Rgb(color)); img.put_pixel(x, y, Rgb(color));
} }
} }
@@ -154,6 +155,49 @@ fn mix_color(color: [u8; 3], target: [u8; 3], factor: f32) -> [u8; 3] {
] ]
} }
fn normalized_coords(x: u32, y: u32, width: u32, height: u32) -> (f32, f32) {
let nx = if width > 1 {
x as f32 / (width as f32 - 1.0)
} else {
0.5
};
let nz = if height > 1 {
y as f32 / (height as f32 - 1.0)
} else {
0.5
};
(nx.clamp(0.0, 1.0), nz.clamp(0.0, 1.0))
}
fn hydrology_overlay_color(scene: &Scene, nx: f32, nz: f32) -> Option<[u8; 3]> {
let lake = scene.hydrology.lake_coverage(nx, nz);
let river = scene.hydrology.river_coverage(nx, nz);
let coverage = lake.max(river);
if coverage <= 0.0 {
return None;
}
let tint = if lake >= river {
mix_color(scene.palette.water, [40, 125, 225], 0.68)
} else {
mix_color(scene.palette.water, [100, 210, 255], 0.75)
};
let colored = mix_color(scene.palette.water, tint, coverage);
Some(if coverage > 0.72 {
mix_color(colored, [245, 250, 255], (coverage - 0.72).clamp(0.0, 0.28) * 3.0)
} else {
colored
})
}
fn surface_color(scene: &Scene, elevation: f32, nx: f32, nz: f32) -> [u8; 3] {
let base = scene_color(scene, elevation);
match hydrology_overlay_color(scene, nx, nz) {
Some(overlay) => mix_color(base, overlay, 0.9),
None => base,
}
}
fn v_add(a: Vec3, b: Vec3) -> Vec3 { fn v_add(a: Vec3, b: Vec3) -> Vec3 {
Vec3::new(a.x + b.x, a.y + b.y, a.z + b.z) Vec3::new(a.x + b.x, a.y + b.y, a.z + b.z)
} }