From 5b1f0b1ef597599b2b10b61dadab6dc16ae4cca4 Mon Sep 17 00:00:00 2001 From: Rob Parrett Date: Fri, 6 Dec 2024 00:49:18 -0800 Subject: [PATCH] Fix error in volumetric fog shader (#16677) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Objective Volumetric fog was broken by #13746. Looks like this particular shader just got missed. I don't see any other instances of `unpack_offset_and_counts` in the codebase. ``` 2024-12-06T03:18:42.297494Z ERROR bevy_render::render_resource::pipeline_cache: failed to process shader: error: no definition in scope for identifier: 'bevy_pbr::clustered_forward::unpack_offset_and_counts' ┌─ crates/bevy_pbr/src/volumetric_fog/volumetric_fog.wgsl:312:29 │ 312 │ let offset_and_counts = bevy_pbr::clustered_forward::unpack_offset_and_counts(cluster_index); │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unknown identifier │ = no definition in scope for identifier: 'bevy_pbr::clustered_forward::unpack_offset_and_counts' ``` ## Solution Use `unpack_clusterable_object_index_ranges` to get the indices for point/spot lights. ## Testing `cargo run --example volumetric_fog` `cargo run --example fog_volumes` `cargo run --example scrolling_fog` --- crates/bevy_pbr/src/volumetric_fog/volumetric_fog.wgsl | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/crates/bevy_pbr/src/volumetric_fog/volumetric_fog.wgsl b/crates/bevy_pbr/src/volumetric_fog/volumetric_fog.wgsl index bb72f82616d06..058f73fca959d 100644 --- a/crates/bevy_pbr/src/volumetric_fog/volumetric_fog.wgsl +++ b/crates/bevy_pbr/src/volumetric_fog/volumetric_fog.wgsl @@ -309,9 +309,11 @@ fn fragment(@builtin(position) position: vec4) -> @location(0) vec4 { let view_z = view_start_pos.z; let is_orthographic = view.clip_from_view[3].w == 1.0; let cluster_index = clustering::fragment_cluster_index(frag_coord.xy, view_z, is_orthographic); - let offset_and_counts = clustering::unpack_offset_and_counts(cluster_index); - let spot_light_start_index = offset_and_counts[0] + offset_and_counts[1]; - for (var i: u32 = offset_and_counts[0]; i < offset_and_counts[0] + offset_and_counts[1] + offset_and_counts[2]; i = i + 1u) { + var clusterable_object_index_ranges = + clustering::unpack_clusterable_object_index_ranges(cluster_index); + for (var i: u32 = clusterable_object_index_ranges.first_point_light_index_offset; + i < clusterable_object_index_ranges.first_reflection_probe_index_offset; + i = i + 1u) { let light_id = clustering::get_clusterable_object_id(i); let light = &clusterable_objects.data[light_id]; if (((*light).flags & POINT_LIGHT_FLAGS_VOLUMETRIC_BIT) == 0) { @@ -340,7 +342,7 @@ fn fragment(@builtin(position) position: vec4) -> @location(0) vec4 { let distance_square = dot(light_to_frag, light_to_frag); let distance_atten = getDistanceAttenuation(distance_square, (*light).color_inverse_square_range.w); var local_light_attenuation = distance_atten; - if (i < spot_light_start_index) { + if (i < clusterable_object_index_ranges.first_spot_light_index_offset) { var shadow: f32 = 1.0; if (((*light).flags & POINT_LIGHT_FLAGS_SHADOWS_ENABLED_BIT) != 0u) { shadow = fetch_point_shadow_without_normal(light_id, vec4(P_world, 1.0));