From 84705073913c4ec6ddb7fd86f2dfb99ff130b912 Mon Sep 17 00:00:00 2001 From: Jarrod Doyle Date: Tue, 27 Jun 2023 20:35:22 +0100 Subject: [PATCH] Rename world_state.brickmap_cache_dims --- assets/shaders/voxel_volume.wgsl | 11 ++++++----- src/voxel/brickmap.rs | 6 +++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/assets/shaders/voxel_volume.wgsl b/assets/shaders/voxel_volume.wgsl index c566cff..b103b0e 100644 --- a/assets/shaders/voxel_volume.wgsl +++ b/assets/shaders/voxel_volume.wgsl @@ -23,8 +23,9 @@ struct Camera { _pad: f32, }; +// TODO: Should probably know how big the cache and shading table are etc. struct WorldState { - brickmap_cache_dims: vec3, + brickgrid_dims: vec3, _pad: u32, }; @@ -177,7 +178,7 @@ fn grid_cast_ray(orig_ray_pos: vec3, ray_dir: vec3) -> HitInfo { var hit_info = HitInfo(false, vec3(0), 0u, vec3(false)); let min = vec3(0.0); - let max = min + vec3(world_state.brickmap_cache_dims); + let max = min + vec3(world_state.brickgrid_dims); let aabbHit = ray_intersect_aabb(orig_ray_pos, ray_dir, min, max); var ray_pos = orig_ray_pos; var tmin = aabbHit.distance; @@ -194,16 +195,16 @@ fn grid_cast_ray(orig_ray_pos: vec3, ray_dir: vec3) -> HitInfo { var map_pos = vec3(floor(ray_pos)); var side_dist = (sign(ray_dir) * (vec3(map_pos) - ray_pos) + (sign(ray_dir) * 0.5) + 0.5) * delta_dist; - let dims = world_state.brickmap_cache_dims; + let dims = world_state.brickgrid_dims; let max_grid_depth = i32(dims.x + dims.y + dims.z); for (var i: i32 = 0; i < max_grid_depth; i++) { - if (!point_inside_aabb(map_pos, vec3(0), vec3(world_state.brickmap_cache_dims))) { + if (!point_inside_aabb(map_pos, vec3(0), vec3(world_state.brickgrid_dims))) { // If the ray has left the brickmap AABB there's no point in continuing // to trace against it break; } - let grid_idx = to_1d_index(map_pos, vec3(world_state.brickmap_cache_dims)); + let grid_idx = to_1d_index(map_pos, vec3(world_state.brickgrid_dims)); let brick_ptr = brickgrid[grid_idx]; // Ptr = 28 bits LOD colour / brickmap index + 4 bits load flags diff --git a/src/voxel/brickmap.rs b/src/voxel/brickmap.rs index 0efed78..124b408 100644 --- a/src/voxel/brickmap.rs +++ b/src/voxel/brickmap.rs @@ -13,7 +13,7 @@ struct Brickmap { #[repr(C)] #[derive(Debug, Default, Copy, Clone, bytemuck::Pod, bytemuck::Zeroable)] struct WorldState { - brickmap_cache_dims: [u32; 3], + brickgrid_dims: [u32; 3], _pad: u32, } @@ -39,7 +39,7 @@ pub struct BrickmapManager { impl BrickmapManager { pub fn new(context: &render::Context, brickgrid_dims: glam::UVec3) -> Self { let state_uniform = WorldState { - brickmap_cache_dims: [brickgrid_dims.x, brickgrid_dims.y, brickgrid_dims.z], + brickgrid_dims: [brickgrid_dims.x, brickgrid_dims.y, brickgrid_dims.z], ..Default::default() }; @@ -154,7 +154,7 @@ impl BrickmapManager { self.feedback_result_buffer.unmap(); // Generate a sphere of voxels - let world_dims = self.state_uniform.brickmap_cache_dims; + let world_dims = self.state_uniform.brickgrid_dims; for i in 0..request_count { let chunk_x = data[i * 4]; let chunk_y = data[i * 4 + 1];