From 5f0ea3fa03b0c1459bc0e142696bafdb32ddb27c Mon Sep 17 00:00:00 2001 From: Jarrod Doyle Date: Thu, 4 May 2023 10:50:00 +0100 Subject: [PATCH] Correctly index shading table in shader --- assets/shaders/voxel_volume.wgsl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/assets/shaders/voxel_volume.wgsl b/assets/shaders/voxel_volume.wgsl index 0159ce0..bd8e915 100644 --- a/assets/shaders/voxel_volume.wgsl +++ b/assets/shaders/voxel_volume.wgsl @@ -66,9 +66,11 @@ fn to_1d_index(p: vec3, dims: vec3) -> u32 { fn get_shading_offset(p: vec3) -> u32 { // What brickmap are we in? - let brickmap_index = to_1d_index(p / 8, vec3(world_state.brickmap_cache_dims)); + let brickgrid_index = to_1d_index(p / 8, vec3(world_state.brickmap_cache_dims)); + let brick_ptr = brickgrid[brickgrid_index]; + let brickmap = &brickmap_cache[brick_ptr >> 8u]; + let local_index = to_1d_index(p % 8, vec3(8)); - let brickmap = &brickmap_cache[brickmap_index]; let bitmask_index = local_index / 32u; var map_voxel_idx = 0u; for (var i: i32 = 0; i < i32(bitmask_index); i++) {