diff --git a/shaders/world.frag b/shaders/world.frag index e07b5e1..017c5e1 100644 --- a/shaders/world.frag +++ b/shaders/world.frag @@ -5,6 +5,7 @@ in vec2 v_uv; flat in uint v_tex_index; out vec4 color; uniform sampler2DArray tex; +uniform bool debug; void main() { // base color from texture @@ -12,4 +13,8 @@ void main() { //basic "lighting" float light = abs(v_normal.x) + .8 * abs(v_normal.y) + .6 * abs(v_normal.z); color *= vec4(vec3(light), 1.); + //highlight + if (debug) { + color *= vec4(1., 0., 0., 1.); + } } diff --git a/src/camera/frustum.rs b/src/camera/frustum.rs index 259b211..78f97c6 100644 --- a/src/camera/frustum.rs +++ b/src/camera/frustum.rs @@ -79,7 +79,7 @@ impl Frustum { } //this may be broken - pub fn intersect_box(&self, minp: Vec3, maxp: Vec3) -> bool { + pub fn is_box_visible(&self, minp: Vec3, maxp: Vec3) -> bool { // check box outside/inside of frustum for i in 0..PLANE_COUNT { if self.planes[i].dot(vec4(minp.x, minp.y, minp.z, 1.)) < 0. && diff --git a/src/world/render.rs b/src/world/render.rs index ec1460b..99ad9ad 100644 --- a/src/world/render.rs +++ b/src/world/render.rs @@ -69,22 +69,15 @@ pub fn draw_world( }); let view = camera.view_matrix.to_cols_array_2d(); let perspective = camera.perspective_matrix.to_cols_array_2d(); - let camera_mat = camera.perspective_matrix * camera.view_matrix; for (&position, chunk) in &chunks.chunks { if let Some(key) = chunk.mesh_index { let mesh = meshes.get(key).expect("Mesh index pointing to nothing"); - let world_position = position.as_vec3a() * CHUNK_SIZE as f32; + let world_position = position.as_vec3() * CHUNK_SIZE as f32; if mesh.index_buffer.len() == 0 { continue } - - //basic culling - // let chunk_center = world_position + Vec3A::splat(CHUNK_SIZE as f32) * 0.5; - // let cull_point = camera_mat * chunk_center.extend(1.); - // if (cull_point.xyz() / cull_point.w).abs().cmpgt(Vec3::splat(1.)).any() { - // continue - // } + let debug = !camera.frustum.is_box_visible(world_position, world_position + Vec3::splat(CHUNK_SIZE as f32)); target.0.draw( &mesh.vertex_buffer, @@ -94,7 +87,8 @@ pub fn draw_world( position_offset: world_position.to_array(), view: view, perspective: perspective, - tex: texture_sampler + tex: texture_sampler, + debug: debug }, &draw_parameters ).unwrap();