mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-11-22 06:48:43 -06:00
add chunk borders
This commit is contained in:
parent
852fee3607
commit
1d55a80404
|
@ -1,8 +1,8 @@
|
|||
#version 150 core
|
||||
|
||||
out vec4 color;
|
||||
uniform vec4 u_color;
|
||||
out vec4 out_color;
|
||||
uniform vec4 color;
|
||||
|
||||
void main() {
|
||||
color = u_color;
|
||||
out_color = color;
|
||||
}
|
||||
|
|
12
src/main.rs
12
src/main.rs
|
@ -32,12 +32,6 @@ pub(crate) mod delta_time;
|
|||
pub(crate) mod cursor_lock;
|
||||
pub(crate) mod control_flow;
|
||||
|
||||
use rendering::{
|
||||
Renderer,
|
||||
RenderTarget,
|
||||
BackgroundColor,
|
||||
clear_background
|
||||
};
|
||||
use world::{
|
||||
init_game_world,
|
||||
loading::update_loaded_world_around_player,
|
||||
|
@ -54,9 +48,14 @@ use events::{
|
|||
use input::{init_input, process_inputs};
|
||||
use fly_controller::update_controllers;
|
||||
use rendering::{
|
||||
Renderer,
|
||||
RenderTarget,
|
||||
BackgroundColor,
|
||||
clear_background,
|
||||
primitives::init_simple_box_buffers,
|
||||
selection_box::render_selection_box,
|
||||
world::draw_world,
|
||||
world::draw_current_chunk_border,
|
||||
};
|
||||
use block_placement::block_placement_system;
|
||||
use delta_time::{DeltaTime, init_delta_time};
|
||||
|
@ -94,6 +93,7 @@ fn render() -> Workload {
|
|||
(
|
||||
clear_background,
|
||||
draw_world,
|
||||
draw_current_chunk_border,
|
||||
render_selection_box,
|
||||
).into_sequential_workload()
|
||||
}
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
use glam::Mat4;
|
||||
use shipyard::{View, IntoIter, NonSendSync, UniqueViewMut, UniqueView};
|
||||
use glium::{
|
||||
Surface,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use glam::Vec3;
|
||||
use glam::{Vec3, Mat4, Quat, ivec3};
|
||||
use shipyard::{NonSendSync, UniqueView, UniqueViewMut, View, IntoIter};
|
||||
use glium::{
|
||||
implement_vertex, uniform,
|
||||
|
@ -15,10 +15,12 @@ use glium::{
|
|||
DepthTest,
|
||||
PolygonMode,
|
||||
BackfaceCullingMode,
|
||||
}
|
||||
}, Blend
|
||||
};
|
||||
use crate::{
|
||||
camera::Camera,
|
||||
player::MainPlayer,
|
||||
transform::Transform,
|
||||
prefabs::{
|
||||
ChunkShaderPrefab,
|
||||
BlockTexturesPrefab,
|
||||
|
@ -28,7 +30,7 @@ use crate::{
|
|||
ChunkStorage,
|
||||
ChunkMeshStorage,
|
||||
chunk::CHUNK_SIZE,
|
||||
},
|
||||
}, settings::GameSettings,
|
||||
};
|
||||
use super::{RenderTarget, primitives::SimpleBoxBuffers};
|
||||
|
||||
|
@ -107,27 +109,72 @@ pub fn draw_world(
|
|||
}
|
||||
}
|
||||
|
||||
// this doesn't use culling!
|
||||
// pub fn draw_chunk_borders(
|
||||
// mut target: NonSendSync<UniqueViewMut<RenderTarget>>,
|
||||
// chunks: UniqueView<ChunkStorage>,
|
||||
// buffers: NonSendSync<UniqueView<SimpleBoxBuffers>>,
|
||||
// program: NonSendSync<UniqueView<BasicShaderPrefab>>,
|
||||
// camera: View<Camera>,
|
||||
// ) {
|
||||
// for (&position, chunk) in &chunks.chunks {
|
||||
// let world_position = position.as_vec3() * CHUNK_SIZE as f32;
|
||||
// target.0.draw(
|
||||
// &buffers.0,
|
||||
// &buffers.1,
|
||||
// &program.0,
|
||||
// &uniform! {
|
||||
// position_offset: world_position.to_array(),
|
||||
// view: view,
|
||||
// perspective: perspective,
|
||||
// tex: texture_sampler,
|
||||
// },
|
||||
// &draw_parameters
|
||||
// ).unwrap();
|
||||
// }
|
||||
// }
|
||||
//this doesn't use culling!
|
||||
pub fn draw_current_chunk_border(
|
||||
mut target: NonSendSync<UniqueViewMut<RenderTarget>>,
|
||||
player: View<MainPlayer>,
|
||||
transforms: View<Transform>,
|
||||
buffers: NonSendSync<UniqueView<SimpleBoxBuffers>>,
|
||||
program: NonSendSync<UniqueView<BasicColoredShaderPrefab>>,
|
||||
camera: View<Camera>,
|
||||
settings: UniqueView<GameSettings>,
|
||||
) {
|
||||
if !settings.debug_draw_current_chunk_border {
|
||||
return
|
||||
}
|
||||
let camera = camera.iter().next().expect("No cameras in the scene");
|
||||
let view = camera.view_matrix.to_cols_array_2d();
|
||||
let perspective = camera.perspective_matrix.to_cols_array_2d();
|
||||
let (_, &player_transform) = (&player, &transforms).iter().next().expect("No player");
|
||||
let (_, _, player_position) = player_transform.0.to_scale_rotation_translation();
|
||||
let player_in_chunk = ivec3(
|
||||
(player_position.x as i32).div_euclid(CHUNK_SIZE as i32),
|
||||
(player_position.y as i32).div_euclid(CHUNK_SIZE as i32),
|
||||
(player_position.z as i32).div_euclid(CHUNK_SIZE as i32),
|
||||
);
|
||||
let world_position = player_in_chunk.as_vec3() * CHUNK_SIZE as f32;
|
||||
target.0.draw(
|
||||
&buffers.0,
|
||||
&buffers.1,
|
||||
&program.0,
|
||||
&uniform! {
|
||||
model: Mat4::from_scale_rotation_translation(
|
||||
Vec3::splat(CHUNK_SIZE as f32),
|
||||
Quat::default(),
|
||||
world_position
|
||||
).to_cols_array_2d(),
|
||||
color: [0.25f32; 4],
|
||||
view: view,
|
||||
perspective: perspective,
|
||||
},
|
||||
&DrawParameters {
|
||||
depth: Depth {
|
||||
test: DepthTest::IfLess,
|
||||
..Default::default()
|
||||
},
|
||||
blend: Blend::alpha_blending(),
|
||||
..Default::default()
|
||||
}
|
||||
).unwrap();
|
||||
target.0.draw(
|
||||
&buffers.0,
|
||||
&buffers.1,
|
||||
&program.0,
|
||||
&uniform! {
|
||||
model: Mat4::from_scale_rotation_translation(
|
||||
Vec3::splat(CHUNK_SIZE as f32),
|
||||
Quat::default(),
|
||||
world_position
|
||||
).to_cols_array_2d(),
|
||||
color: [0.0f32; 4],
|
||||
view: view,
|
||||
perspective: perspective,
|
||||
},
|
||||
&DrawParameters {
|
||||
polygon_mode: PolygonMode::Point,
|
||||
line_width: Some(2.),
|
||||
point_size: Some(5.),
|
||||
..Default::default()
|
||||
}
|
||||
).unwrap();
|
||||
}
|
||||
|
|
|
@ -5,14 +5,14 @@ pub struct GameSettings {
|
|||
/// there's a 1 chunk border of loaded but invisible around this
|
||||
pub render_distance: u8,
|
||||
pub mouse_sensitivity: f32,
|
||||
pub debug_draw_chunk_border: bool,
|
||||
pub debug_draw_current_chunk_border: bool,
|
||||
}
|
||||
impl Default for GameSettings {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
render_distance: 5,
|
||||
mouse_sensitivity: 1.,
|
||||
debug_draw_chunk_border: cfg!(debug_assertions),
|
||||
debug_draw_current_chunk_border: cfg!(debug_assertions),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue