Experimients with long range waves

This commit is contained in:
2024-10-21 21:16:33 -04:00
parent 9dd0191ca2
commit f6f20d8c1b

View File

@@ -118,6 +118,8 @@ pub fn generate_chunk_water_mesh(chunk: &MeshChunkData, sealevel: f32, map_width
create_tile_water_surface(
tile_pos,
height,
chunk.min_height,
&n,
neighbor_has_land,
&mut verts,
@@ -140,6 +142,8 @@ pub fn generate_chunk_water_mesh(chunk: &MeshChunkData, sealevel: f32, map_width
fn create_tile_water_surface(
pos: Vec3,
height: f32,
min_height: f32,
neighbors: &[f32; 6],
neighbor_has_land: bool,
verts: &mut Vec<Vec3>,
@@ -148,14 +152,16 @@ fn create_tile_water_surface(
normals: &mut Vec<Vec3>,
) {
if !neighbor_has_land {
crate_tile_water_inner_surface(pos, verts, uvs, indices, normals);
crate_tile_water_inner_surface(pos, height, min_height, verts, uvs, indices, normals);
return;
}
crate_tile_water_shore_surface(pos, neighbors, verts, uvs, indices, normals);
crate_tile_water_shore_surface(pos, height, min_height, neighbors, verts, uvs, indices, normals);
}
fn crate_tile_water_inner_surface(
pos: Vec3,
height: f32,
min_height: f32,
verts: &mut Vec<Vec3>,
uvs: &mut Vec<Vec2>,
indices: &mut Vec<u32>,
@@ -166,7 +172,7 @@ fn crate_tile_water_inner_surface(
for i in 0..6 {
let p = pos + HEX_CORNERS[i];
verts.push(p);
uvs.push(Vec2::ZERO);
uvs.push(Vec2::new(0.0, height.remap(min_height, pos.y, 0.0, 1.0)));
normals.push(Vec3::Y);
}
for i in 0..3 {
@@ -182,6 +188,8 @@ fn crate_tile_water_inner_surface(
fn crate_tile_water_shore_surface(
pos: Vec3,
height: f32,
min_height: f32,
neighbors: &[f32; 6],
verts: &mut Vec<Vec3>,
uvs: &mut Vec<Vec2>,
@@ -191,22 +199,22 @@ fn crate_tile_water_shore_surface(
let idx = verts.len() as u32;
//todo: only use triangle fan when on shoreline
verts.push(pos);
uvs.push(Vec2::ZERO);
uvs.push(Vec2::new(0.0, height.remap(min_height, pos.y, 0.0, 1.0)));
normals.push(Vec3::Y);
for i in 0..12 {
let p = pos + WATER_HEX_CORNERS[i];
verts.push(p);
let mut uv = Vec2::ZERO;
let mut uv = Vec2::new(0.0, height.remap(min_height, pos.y, 0.0, 1.0));
let ni = i / 2;
let n = neighbors[ni];
let nn = neighbors[(ni + 5) % 6];
if nn > pos.y || n > pos.y {
uv = Vec2::ONE;
uv.x = 1.0;
}
if ni * 2 != i {
if n <= pos.y {
uv = Vec2::ZERO;
uv.x = 0.0;
}
}