mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-11-29 02:08:48 -06:00
wip culling
This commit is contained in:
parent
1f1b337988
commit
5b4f54a19e
|
@ -5,6 +5,7 @@ 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
|
||||||
|
@ -12,4 +13,8 @@ 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.);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,7 +79,7 @@ impl Frustum {
|
||||||
}
|
}
|
||||||
|
|
||||||
//this may be broken
|
//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
|
// check box outside/inside of frustum
|
||||||
for i in 0..PLANE_COUNT {
|
for i in 0..PLANE_COUNT {
|
||||||
if self.planes[i].dot(vec4(minp.x, minp.y, minp.z, 1.)) < 0. &&
|
if self.planes[i].dot(vec4(minp.x, minp.y, minp.z, 1.)) < 0. &&
|
||||||
|
|
|
@ -69,22 +69,15 @@ pub fn draw_world(
|
||||||
});
|
});
|
||||||
let view = camera.view_matrix.to_cols_array_2d();
|
let view = camera.view_matrix.to_cols_array_2d();
|
||||||
let perspective = camera.perspective_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 {
|
for (&position, chunk) in &chunks.chunks {
|
||||||
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_vec3a() * CHUNK_SIZE as f32;
|
let world_position = position.as_vec3() * CHUNK_SIZE as f32;
|
||||||
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));
|
||||||
//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
|
|
||||||
// }
|
|
||||||
|
|
||||||
target.0.draw(
|
target.0.draw(
|
||||||
&mesh.vertex_buffer,
|
&mesh.vertex_buffer,
|
||||||
|
@ -94,7 +87,8 @@ pub fn draw_world(
|
||||||
position_offset: world_position.to_array(),
|
position_offset: world_position.to_array(),
|
||||||
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