Random terrain sprite orientations

This commit is contained in:
Joshua Barretto 2019-08-21 16:22:49 +01:00
parent 75e1ee3cd7
commit 0fcb3a174d
2 changed files with 15 additions and 8 deletions

View File

@ -36,7 +36,7 @@ void main() {
0.0
) * sin(v_pos.z * 0.03) * 0.5;
f_norm = v_norm;
f_norm = (inst_mat * vec4(v_norm, 0)).xyz;
f_col = v_col * inst_col;

View File

@ -17,7 +17,7 @@ use crossbeam::channel;
use dot_vox::DotVoxData;
use frustum_query::frustum::Frustum;
use hashbrown::HashMap;
use std::{i32, ops::Mul, time::Duration};
use std::{f32, i32, ops::Mul, time::Duration};
use vek::*;
struct TerrainChunk {
@ -88,15 +88,22 @@ fn mesh_worker(
let kind = volume.get(wpos).unwrap_or(&Block::empty()).kind();
if let Some(cfg) = sprite_config_for(kind) {
instances.entry(kind).or_insert_with(|| Vec::new()).push(
SpriteInstance::new(
Mat4::identity().translated_3d(
let seed = x * 3 + y * 7 + z * 13 + x * y;
let instance = SpriteInstance::new(
Mat4::identity()
.rotated_z(f32::consts::PI * 0.5 * (seed % 4) as f32)
.translated_3d(
wpos.map(|e| e as f32) + Vec3::new(0.5, 0.5, 0.0),
),
Rgb::broadcast(1.0),
cfg.wind_sway,
),
Rgb::broadcast(1.0),
cfg.wind_sway,
);
instances
.entry(kind)
.or_insert_with(|| Vec::new())
.push(instance);
}
}
}