From 432f820ba8685233c620e2398b3786b16ff4a1e8 Mon Sep 17 00:00:00 2001 From: Felix Weilbach Date: Fri, 16 Aug 2024 00:35:46 +0200 Subject: [PATCH] Fix point light assignment The min and max light id calculation needs to include lights that have their projected z coordinates smaller and greater than then bin z bounds. The address calculation of tiles need the x value multiplied by the words count. Otherwise the address is not correct because one tile covers words count unsigned integers. --- source/chapter7/graphics/render_scene.cpp | 4 ++-- source/chapter7/shaders/lighting.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/source/chapter7/graphics/render_scene.cpp b/source/chapter7/graphics/render_scene.cpp index d2cd72e..29cd8d1 100644 --- a/source/chapter7/graphics/render_scene.cpp +++ b/source/chapter7/graphics/render_scene.cpp @@ -2143,7 +2143,7 @@ void RenderScene::upload_gpu_data( UploadGpuDataContext& context ) { for ( u32 i = 0; i < k_num_lights; ++i ) { const SortedLight& light = sorted_lights[ i ]; - if ( ( light.projected_z >= bin_min && light.projected_z <= bin_max ) || + if ( ( light.projected_z_min <= bin_min && light.projected_z_max >= bin_max ) || ( light.projected_z_min >= bin_min && light.projected_z_min <= bin_max ) || ( light.projected_z_max >= bin_min && light.projected_z_max <= bin_max ) ) { if ( i < min_light_id ) { @@ -2352,7 +2352,7 @@ void RenderScene::upload_gpu_data( UploadGpuDataContext& context ) { for ( u32 y = first_tile_y; y <= last_tile_y; ++y ) { for ( u32 x = first_tile_x; x <= last_tile_x; ++x ) { - u32 array_index = y * tile_stride + x; + u32 array_index = y * tile_stride + x * k_num_words; u32 word_index = i / 32; u32 bit_index = i % 32; diff --git a/source/chapter7/shaders/lighting.h b/source/chapter7/shaders/lighting.h index f5168e0..2121b75 100644 --- a/source/chapter7/shaders/lighting.h +++ b/source/chapter7/shaders/lighting.h @@ -188,7 +188,7 @@ vec4 calculate_lighting(vec4 base_colour, vec3 orm, vec3 normal, vec3 emissive, uvec2 tile = position / uint( TILE_SIZE ); uint stride = uint( NUM_WORDS ) * ( uint( resolution.x ) / uint( TILE_SIZE ) ); - uint address = tile.y * stride + tile.x; + uint address = tile.y * stride + tile.x * uint( NUM_WORDS ); #if ENABLE_OPTIMIZATION // NOTE(marco): this version has been implemented following: