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