Don't interpolate if all block corners are negative

This commit is contained in:
Jarrod Doyle 2023-05-12 11:10:23 +01:00
parent 2f3c214c98
commit 2f99b0ea4e
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
1 changed files with 8 additions and 3 deletions

View File

@ -25,19 +25,24 @@ impl Chunk {
if block.len() == 0 { if block.len() == 0 {
// Extract relevant noise values from the chunk // Extract relevant noise values from the chunk
let mut noise_vals = Vec::new(); let mut noise_vals = Vec::new();
let mut block_sign = 0.0;
for z in 0..2 { for z in 0..2 {
for y in 0..2 { for y in 0..2 {
for x in 0..2 { for x in 0..2 {
let noise_pos = glam::uvec3(x, y, z) + pos; let noise_pos = glam::uvec3(x, y, z) + pos;
let noise_idx = math::to_1d_index(noise_pos, noise_dims); let noise_idx = math::to_1d_index(noise_pos, noise_dims);
noise_vals.push(self.noise[noise_idx]); let val = self.noise[noise_idx];
noise_vals.push(val);
block_sign += val.signum();
} }
} }
} }
// Interpolate to get block voxels
let mut vals = [0.0f32; 512]; let mut vals = [0.0f32; 512];
math::tri_lerp_block(&noise_vals, &[8, 8, 8], &mut vals); if block_sign != -8.0 {
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 {