diff --git a/shaders/colored.frag b/shaders/colored.frag new file mode 100644 index 0000000..9b2ac94 --- /dev/null +++ b/shaders/colored.frag @@ -0,0 +1,8 @@ +#version 150 core + +out vec4 color; +uniform vec4 u_color; + +void main() { + color = u_color; +} diff --git a/shaders/colored.vert b/shaders/colored.vert new file mode 100644 index 0000000..083513e --- /dev/null +++ b/shaders/colored.vert @@ -0,0 +1,11 @@ +#version 150 core + +in vec3 position; +uniform mat4 model; +uniform mat4 perspective; +uniform mat4 view; + +void main() { + mat4 modelview = view * model; + gl_Position = perspective * modelview * vec4(position, 1.); +} diff --git a/shaders/selection_box.vert b/shaders/selection_box.vert index 7243a1f..f825013 100644 --- a/shaders/selection_box.vert +++ b/shaders/selection_box.vert @@ -1,10 +1,10 @@ #version 150 core in vec3 position; -uniform vec3 u_position; +uniform ivec3 u_position; uniform mat4 perspective; uniform mat4 view; void main() { - gl_Position = perspective * view * vec4(position + u_position, 1.); + gl_Position = perspective * view * vec4(position + vec3(u_position), 1.); } diff --git a/src/prefabs.rs b/src/prefabs.rs index 793966e..8b90291 100644 --- a/src/prefabs.rs +++ b/src/prefabs.rs @@ -59,10 +59,14 @@ pub struct ChunkShaderPrefab(pub Program); #[derive(Unique)] pub struct SelBoxShaderPrefab(pub Program); +#[derive(Unique)] +pub struct BasicColoredShaderPrefab(pub Program); + pub fn load_prefabs( storages: AllStoragesView, renderer: NonSendSync> ) { + log::info!("Loading textures..."); storages.add_unique_non_send_sync(BlockTexturesPrefab( load_texture2darray_prefab::( "./assets/blocks/".into(), @@ -70,8 +74,11 @@ pub fn load_prefabs( MipmapsOption::AutoGeneratedMipmaps ) )); + + log::info!("Compiling shaders..."); storages.add_unique_non_send_sync(ChunkShaderPrefab( include_shader_prefab!( + "world", "../shaders/world.vert", "../shaders/world.frag", &renderer.display @@ -79,9 +86,18 @@ pub fn load_prefabs( )); storages.add_unique_non_send_sync(SelBoxShaderPrefab( include_shader_prefab!( + "selection_box", "../shaders/selection_box.vert", "../shaders/selection_box.frag", &renderer.display ) )); + storages.add_unique_non_send_sync(BasicColoredShaderPrefab( + include_shader_prefab!( + "colored", + "../shaders/colored.vert", + "../shaders/colored.frag", + &renderer.display + ) + )); } diff --git a/src/prefabs/shaders.rs b/src/prefabs/shaders.rs index 97bffa6..553fbdf 100644 --- a/src/prefabs/shaders.rs +++ b/src/prefabs/shaders.rs @@ -1,11 +1,10 @@ macro_rules! include_shader_prefab { - ($vert: literal, $frag: literal, $geom: literal, $facade: expr) => { + ($name: literal, $vert: literal, $frag: literal, $geom: literal, $facade: expr) => { { use ::glium::Program; - log::info!("↓↓↓ compiling shader prefab ↓↓↓"); - log::info!("{} {} {}", $vert, $frag, $geom); + log::info!("compiling shader {}", $name); Program::from_source( &*$facade, include_str!($vert), @@ -14,11 +13,10 @@ macro_rules! include_shader_prefab { ).expect("Failed to compile gpu program") } }; - ($vert: literal, $frag: literal, $facade: expr) => { + ($name: literal, $vert: literal, $frag: literal, $facade: expr) => { { use ::glium::Program; - log::info!("↓↓↓ compiling shader prefab ↓↓↓"); - log::info!("{} {}", $vert, $frag); + log::info!("compiling shader {}", $name); Program::from_source( &*$facade, include_str!($vert), diff --git a/src/prefabs/texture.rs b/src/prefabs/texture.rs index cf2ae4c..10a16ee 100644 --- a/src/prefabs/texture.rs +++ b/src/prefabs/texture.rs @@ -12,7 +12,7 @@ pub fn load_texture2darray_prefab< facade: &E, mipmaps: MipmapsOption, ) -> SrgbTexture2dArray { - log::info!("↓↓↓ loading textures {} ↓↓↓", directory.as_os_str().to_str().unwrap()); + log::info!("started loading {}", directory.as_os_str().to_str().unwrap()); //Load raw images let tex_files: Vec<&'static str> = T::iter().map(|x| x.file_name()).collect(); let raw_images: Vec> = tex_files.par_iter().map(|&file_name| { diff --git a/src/rendering/selection_box.rs b/src/rendering/selection_box.rs index 1cbe8cf..1a895db 100644 --- a/src/rendering/selection_box.rs +++ b/src/rendering/selection_box.rs @@ -1,3 +1,4 @@ +use glam::Mat4; use shipyard::{View, IntoIter, NonSendSync, UniqueViewMut, UniqueView}; use glium::{ Surface, @@ -33,7 +34,7 @@ pub fn render_selection_box( &program.0, &uniform! { u_color: [0., 0., 0., 0.5_f32], - u_position: lookat.block_position.as_vec3().to_array(), + u_position: lookat.block_position.to_array(), perspective: camera.perspective_matrix.to_cols_array_2d(), view: camera.view_matrix.to_cols_array_2d(), }, diff --git a/src/rendering/world.rs b/src/rendering/world.rs index 2cd543c..d0de7b3 100644 --- a/src/rendering/world.rs +++ b/src/rendering/world.rs @@ -21,7 +21,8 @@ use crate::{ camera::Camera, prefabs::{ ChunkShaderPrefab, - BlockTexturesPrefab, + BlockTexturesPrefab, + BasicColoredShaderPrefab, }, world::{ ChunkStorage, @@ -29,7 +30,7 @@ use crate::{ chunk::CHUNK_SIZE, }, }; -use super::RenderTarget; +use super::{RenderTarget, primitives::SimpleBoxBuffers}; #[derive(Clone, Copy)] pub struct ChunkVertex { @@ -105,3 +106,28 @@ pub fn draw_world( } } } + +// this doesn't use culling! +// pub fn draw_chunk_borders( +// mut target: NonSendSync>, +// chunks: UniqueView, +// buffers: NonSendSync>, +// program: NonSendSync>, +// camera: View, +// ) { +// 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(); +// } +// }