mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-12-22 20:08:20 -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;
|
flat in uint v_tex_index;
|
||||||
out vec4 color;
|
out vec4 color;
|
||||||
uniform sampler2DArray tex;
|
uniform sampler2DArray tex;
|
||||||
uniform bool debug;
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
// base color from texture
|
// base color from texture
|
||||||
|
@ -13,8 +12,4 @@ void main() {
|
||||||
//basic "lighting"
|
//basic "lighting"
|
||||||
float light = abs(v_normal.x) + .8 * abs(v_normal.y) + .6 * abs(v_normal.z);
|
float light = abs(v_normal.x) + .8 * abs(v_normal.y) + .6 * abs(v_normal.z);
|
||||||
color *= vec4(vec3(light), 1.);
|
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 {
|
if let Some(key) = chunk.mesh_index {
|
||||||
let mesh = meshes.get(key).expect("Mesh index pointing to nothing");
|
let mesh = meshes.get(key).expect("Mesh index pointing to nothing");
|
||||||
let world_position = position.as_vec3() * CHUNK_SIZE as f32;
|
let world_position = position.as_vec3() * CHUNK_SIZE as f32;
|
||||||
|
|
||||||
|
//Skip mesh if its empty
|
||||||
if mesh.index_buffer.len() == 0 {
|
if mesh.index_buffer.len() == 0 {
|
||||||
continue
|
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(
|
target.0.draw(
|
||||||
&mesh.vertex_buffer,
|
&mesh.vertex_buffer,
|
||||||
&mesh.index_buffer,
|
&mesh.index_buffer,
|
||||||
|
@ -88,7 +99,6 @@ pub fn draw_world(
|
||||||
view: view,
|
view: view,
|
||||||
perspective: perspective,
|
perspective: perspective,
|
||||||
tex: texture_sampler,
|
tex: texture_sampler,
|
||||||
debug: debug
|
|
||||||
},
|
},
|
||||||
&draw_parameters
|
&draw_parameters
|
||||||
).unwrap();
|
).unwrap();
|
||||||
|
|
Loading…
Reference in a new issue