mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-12-22 11:58:21 -06:00
enable frustum culling!
This commit is contained in:
parent
fe5bafdd35
commit
4c2a29e0a3
|
@ -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.);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue