diff --git a/shaders/world.frag b/shaders/world.frag index 017c5e1..e07b5e1 100644 --- a/shaders/world.frag +++ b/shaders/world.frag @@ -5,7 +5,6 @@ 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 @@ -13,8 +12,4 @@ 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/world/render.rs b/src/world/render.rs index 99ad9ad..3cda8fc 100644 --- a/src/world/render.rs +++ b/src/world/render.rs @@ -74,11 +74,22 @@ pub fn draw_world( if let Some(key) = chunk.mesh_index { let mesh = meshes.get(key).expect("Mesh index pointing to nothing"); let world_position = position.as_vec3() * CHUNK_SIZE as f32; + + //Skip mesh if its empty if mesh.index_buffer.len() == 0 { continue } - let debug = !camera.frustum.is_box_visible(world_position, world_position + Vec3::splat(CHUNK_SIZE as f32)); + //Frustum culling + { + let minp = world_position; + let maxp = world_position + Vec3::splat(CHUNK_SIZE as f32); + if !camera.frustum.is_box_visible(minp, maxp) { + continue + } + } + + //Draw chunk mesh target.0.draw( &mesh.vertex_buffer, &mesh.index_buffer, @@ -88,7 +99,6 @@ pub fn draw_world( view: view, perspective: perspective, tex: texture_sampler, - debug: debug }, &draw_parameters ).unwrap();