add chunk borders

This commit is contained in:
griffi-gh 2023-01-30 01:24:53 +01:00
parent 852fee3607
commit 1d55a80404
5 changed files with 86 additions and 40 deletions

View file

@ -1,8 +1,8 @@
#version 150 core #version 150 core
out vec4 color; out vec4 out_color;
uniform vec4 u_color; uniform vec4 color;
void main() { void main() {
color = u_color; out_color = color;
} }

View file

@ -32,12 +32,6 @@ pub(crate) mod delta_time;
pub(crate) mod cursor_lock; pub(crate) mod cursor_lock;
pub(crate) mod control_flow; pub(crate) mod control_flow;
use rendering::{
Renderer,
RenderTarget,
BackgroundColor,
clear_background
};
use world::{ use world::{
init_game_world, init_game_world,
loading::update_loaded_world_around_player, loading::update_loaded_world_around_player,
@ -54,9 +48,14 @@ use events::{
use input::{init_input, process_inputs}; use input::{init_input, process_inputs};
use fly_controller::update_controllers; use fly_controller::update_controllers;
use rendering::{ use rendering::{
Renderer,
RenderTarget,
BackgroundColor,
clear_background,
primitives::init_simple_box_buffers, primitives::init_simple_box_buffers,
selection_box::render_selection_box, selection_box::render_selection_box,
world::draw_world, world::draw_world,
world::draw_current_chunk_border,
}; };
use block_placement::block_placement_system; use block_placement::block_placement_system;
use delta_time::{DeltaTime, init_delta_time}; use delta_time::{DeltaTime, init_delta_time};
@ -94,6 +93,7 @@ fn render() -> Workload {
( (
clear_background, clear_background,
draw_world, draw_world,
draw_current_chunk_border,
render_selection_box, render_selection_box,
).into_sequential_workload() ).into_sequential_workload()
} }

View file

@ -1,4 +1,3 @@
use glam::Mat4;
use shipyard::{View, IntoIter, NonSendSync, UniqueViewMut, UniqueView}; use shipyard::{View, IntoIter, NonSendSync, UniqueViewMut, UniqueView};
use glium::{ use glium::{
Surface, Surface,

View file

@ -1,4 +1,4 @@
use glam::Vec3; use glam::{Vec3, Mat4, Quat, ivec3};
use shipyard::{NonSendSync, UniqueView, UniqueViewMut, View, IntoIter}; use shipyard::{NonSendSync, UniqueView, UniqueViewMut, View, IntoIter};
use glium::{ use glium::{
implement_vertex, uniform, implement_vertex, uniform,
@ -15,10 +15,12 @@ use glium::{
DepthTest, DepthTest,
PolygonMode, PolygonMode,
BackfaceCullingMode, BackfaceCullingMode,
} }, Blend
}; };
use crate::{ use crate::{
camera::Camera, camera::Camera,
player::MainPlayer,
transform::Transform,
prefabs::{ prefabs::{
ChunkShaderPrefab, ChunkShaderPrefab,
BlockTexturesPrefab, BlockTexturesPrefab,
@ -28,7 +30,7 @@ use crate::{
ChunkStorage, ChunkStorage,
ChunkMeshStorage, ChunkMeshStorage,
chunk::CHUNK_SIZE, chunk::CHUNK_SIZE,
}, }, settings::GameSettings,
}; };
use super::{RenderTarget, primitives::SimpleBoxBuffers}; use super::{RenderTarget, primitives::SimpleBoxBuffers};
@ -108,26 +110,71 @@ pub fn draw_world(
} }
//this doesn't use culling! //this doesn't use culling!
// pub fn draw_chunk_borders( pub fn draw_current_chunk_border(
// mut target: NonSendSync<UniqueViewMut<RenderTarget>>, mut target: NonSendSync<UniqueViewMut<RenderTarget>>,
// chunks: UniqueView<ChunkStorage>, player: View<MainPlayer>,
// buffers: NonSendSync<UniqueView<SimpleBoxBuffers>>, transforms: View<Transform>,
// program: NonSendSync<UniqueView<BasicShaderPrefab>>, buffers: NonSendSync<UniqueView<SimpleBoxBuffers>>,
// camera: View<Camera>, program: NonSendSync<UniqueView<BasicColoredShaderPrefab>>,
// ) { camera: View<Camera>,
// for (&position, chunk) in &chunks.chunks { settings: UniqueView<GameSettings>,
// let world_position = position.as_vec3() * CHUNK_SIZE as f32; ) {
// target.0.draw( if !settings.debug_draw_current_chunk_border {
// &buffers.0, return
// &buffers.1, }
// &program.0, let camera = camera.iter().next().expect("No cameras in the scene");
// &uniform! { let view = camera.view_matrix.to_cols_array_2d();
// position_offset: world_position.to_array(), let perspective = camera.perspective_matrix.to_cols_array_2d();
// view: view, let (_, &player_transform) = (&player, &transforms).iter().next().expect("No player");
// perspective: perspective, let (_, _, player_position) = player_transform.0.to_scale_rotation_translation();
// tex: texture_sampler, let player_in_chunk = ivec3(
// }, (player_position.x as i32).div_euclid(CHUNK_SIZE as i32),
// &draw_parameters (player_position.y as i32).div_euclid(CHUNK_SIZE as i32),
// ).unwrap(); (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();
}

View file

@ -5,14 +5,14 @@ pub struct GameSettings {
/// there's a 1 chunk border of loaded but invisible around this /// there's a 1 chunk border of loaded but invisible around this
pub render_distance: u8, pub render_distance: u8,
pub mouse_sensitivity: f32, pub mouse_sensitivity: f32,
pub debug_draw_chunk_border: bool, pub debug_draw_current_chunk_border: bool,
} }
impl Default for GameSettings { impl Default for GameSettings {
fn default() -> Self { fn default() -> Self {
Self { Self {
render_distance: 5, render_distance: 5,
mouse_sensitivity: 1., mouse_sensitivity: 1.,
debug_draw_chunk_border: cfg!(debug_assertions), debug_draw_current_chunk_border: cfg!(debug_assertions),
} }
} }
} }