From 9532161ed742a6e02cfe575bf46367553abd5d06 Mon Sep 17 00:00:00 2001 From: griffi-gh Date: Mon, 17 Jul 2023 00:52:07 +0200 Subject: [PATCH] wip --- kubi/shaders/world.wgsl | 6 ++---- kubi/src/assets.rs | 4 ++-- kubi/src/lib.rs | 4 ++-- kubi/src/rendering/world.rs | 43 +++++++++++++++++++++++++++++++------ kubi/src/world.rs | 2 +- 5 files changed, 44 insertions(+), 15 deletions(-) diff --git a/kubi/shaders/world.wgsl b/kubi/shaders/world.wgsl index 0e1e335..d00f395 100644 --- a/kubi/shaders/world.wgsl +++ b/kubi/shaders/world.wgsl @@ -1,7 +1,7 @@ //TODO migrate, this is just some filler code to make the game compile struct VertexOutput { - @builtin(position) clip_position: vec4, + @builtin(position) position: vec4, }; @vertex @@ -9,9 +9,7 @@ fn vs_main( @builtin(vertex_index) in_vertex_index: u32, ) -> VertexOutput { var out: VertexOutput; - let x = f32(1 - i32(in_vertex_index)) * 0.5; - let y = f32(i32(in_vertex_index & 1u) * 2 - 1) * 0.5; - out.clip_position = vec4(x, y, 0.0, 1.0); + out.position = vec4(0.0, 0.0, 0.0, 1.0); return out; } diff --git a/kubi/src/assets.rs b/kubi/src/assets.rs index 8e623c1..2fd6132 100644 --- a/kubi/src/assets.rs +++ b/kubi/src/assets.rs @@ -37,14 +37,14 @@ impl AssetPaths for BlockTexture { #[derive(Unique)] #[repr(transparent)] -pub struct BlockTexturesPrefab(pub wgpu::Texture); +pub struct BlockTexturesAsset(pub wgpu::Texture); pub fn load_prefabs( storages: AllStoragesView, renderer: NonSendSync> ) { log::info!("Loading textures..."); - storages.add_unique_non_send_sync(BlockTexturesPrefab( + storages.add_unique_non_send_sync(BlockTexturesAsset( load_asset_texture_array::("blocks".into(), &renderer) )); } diff --git a/kubi/src/lib.rs b/kubi/src/lib.rs index 34415bb..8fc36a7 100644 --- a/kubi/src/lib.rs +++ b/kubi/src/lib.rs @@ -240,7 +240,7 @@ pub fn kubi_main() { let renderer = world.borrow::>>().unwrap(); renderer.begin() }; - world.add_unique_non_send_sync(target); + world.add_unique(target); //Run render workflow world.run_workload(render).unwrap(); @@ -248,7 +248,7 @@ pub fn kubi_main() { //Finish rendering { let target = world.remove_unique::().unwrap(); - let renderer = world.borrow::>>().unwrap(); + let renderer = world.borrow::>().unwrap(); renderer.end(target); } diff --git a/kubi/src/rendering/world.rs b/kubi/src/rendering/world.rs index 93ae1c0..5fb14e9 100644 --- a/kubi/src/rendering/world.rs +++ b/kubi/src/rendering/world.rs @@ -1,17 +1,18 @@ use glam::{Vec3, Mat4, Quat, ivec3}; -use shipyard::{NonSendSync, UniqueView, UniqueViewMut, View, IntoIter, track}; +use shipyard::{NonSendSync, UniqueView, UniqueViewMut, View, IntoIter, track, Unique}; +use wgpu::util::DeviceExt; use crate::{ camera::Camera, player::MainPlayer, transform::Transform, - assets::BlockTexturesPrefab, + assets::BlockTexturesAsset, world::{ ChunkStorage, ChunkMeshStorage, chunk::CHUNK_SIZE, }, settings::GameSettings, }; -use super::{RenderTarget, primitives::cube::CubePrimitive}; +use super::{RenderTarget, shaders::Shaders, Renderer}; #[repr(C, packed)] #[derive(Clone, Copy, bytemuck::Pod, bytemuck::Zeroable)] @@ -22,15 +23,45 @@ pub struct ChunkVertex { pub tex_index: u8, } -pub fn draw_world() {} +#[repr(C, packed)] +#[derive(Clone, Copy, bytemuck::Pod, bytemuck::Zeroable)] +struct WorldUniform { + position_offset: [f32; 3], + view: [[f32; 4]; 4], + perspective: [[f32; 4]; 4], +} + +pub fn draw_world( + renderer: UniqueView, + mut target: UniqueViewMut, + chunks: UniqueView, + meshes: UniqueView, + shaders: UniqueView, + texture: UniqueView, + camera: View, + settings: UniqueView +) { + let camera = camera.iter().next().expect("No cameras in the scene"); + for (&position, chunk) in &chunks.chunks { + if let Some(key) = chunk.mesh_index { + let mesh = meshes.get(key).expect("Mesh index pointing to nothing"); + let world_position = position.as_vec3() * CHUNK_SIZE as f32; + + //TODO culling + + //Draw chunk mesh + + } + } +} #[cfg(fuck)] pub fn draw_world( - mut target: NonSendSync>, + mut target: NonSendSync>, chunks: UniqueView, meshes: NonSendSync>, program: NonSendSync>, - texture: NonSendSync>, + texture: NonSendSync>, camera: View, settings: UniqueView ) { diff --git a/kubi/src/world.rs b/kubi/src/world.rs index 50664d2..f813b43 100644 --- a/kubi/src/world.rs +++ b/kubi/src/world.rs @@ -102,7 +102,7 @@ impl ChunkMeshStorage { pub fn init_game_world( storages: AllStoragesView, ) { - storages.add_unique_non_send_sync(ChunkMeshStorage::new()); + storages.add_unique(ChunkMeshStorage::new()); storages.add_unique(ChunkStorage::new()); storages.add_unique(ChunkTaskManager::new()); storages.add_unique(BlockUpdateQueue::new());