Simplify block gen code path when all corners are empty

This commit is contained in:
Jarrod Doyle 2023-05-13 11:51:14 +01:00
parent 2f99b0ea4e
commit a29b4979ef
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
1 changed files with 20 additions and 16 deletions

View File

@ -39,25 +39,29 @@ impl Chunk {
} }
} }
let mut vals = [0.0f32; 512]; // If all the corners are negative, then all the interpolated values
if block_sign != -8.0 { // will be negative too. In that case we can just fill with empty.
if block_sign == -8.0 {
block.resize(512, Voxel::Empty);
} else {
let mut vals = [0.0f32; 512];
math::tri_lerp_block(&noise_vals, &[8, 8, 8], &mut vals); math::tri_lerp_block(&noise_vals, &[8, 8, 8], &mut vals);
}
let mut idx = 0; let mut idx = 0;
for z in 0..8 { for z in 0..8 {
for y in 0..8 { for y in 0..8 {
for x in 0..8 { for x in 0..8 {
let val = vals[idx]; let val = vals[idx];
idx += 1; idx += 1;
if val > 0.0 { if val > 0.0 {
let r = ((x + 1) * 32 - 1) as u8; let r = ((x + 1) * 32 - 1) as u8;
let g = ((y + 1) * 32 - 1) as u8; let g = ((y + 1) * 32 - 1) as u8;
let b = ((z + 1) * 32 - 1) as u8; let b = ((z + 1) * 32 - 1) as u8;
block.push(Voxel::Color(r, g, b)); block.push(Voxel::Color(r, g, b));
} else { } else {
block.push(Voxel::Empty); block.push(Voxel::Empty);
}
} }
} }
} }