1#define_import_path bevy_pbr::light_probe 3#import bevy_pbr::clustered_forward 4#import bevy_pbr::clustered_forward::ClusterableObjectIndexRanges 5#import bevy_pbr::mesh_view_bindings::light_probes 6#import bevy_pbr::mesh_view_types::LightProbe 9struct LightProbeQueryResult { 18 light_from_world: mat4x4<f32>, 20 affects_lightmapped_mesh_diffuse: bool, 23fn transpose_affine_matrix(matrix: mat3x4<f32>) -> mat4x4<f32> { 24 let matrix4x4 = mat4x4<f32>( 28 vec4<f32>(0.0, 0.0, 0.0, 1.0)); 29 return transpose(matrix4x4); 32#if AVAILABLE_STORAGE_BUFFER_BINDINGS >= 3 41 world_position: vec3<f32>, 42 is_irradiance_volume: bool, 43 clusterable_object_index_ranges: ptr<function, ClusterableObjectIndexRanges>, 44) -> LightProbeQueryResult { 45 var result: LightProbeQueryResult; 46 result.texture_index = -1; 51 var start_offset: u32; 53 if is_irradiance_volume { 54 start_offset = (*clusterable_object_index_ranges).first_irradiance_volume_index_offset; 55 end_offset = (*clusterable_object_index_ranges).first_decal_offset; 57 start_offset = (*clusterable_object_index_ranges).first_reflection_probe_index_offset; 58 end_offset = (*clusterable_object_index_ranges).first_irradiance_volume_index_offset; 61 for (var light_probe_index_offset: u32 = start_offset; 62 light_probe_index_offset < end_offset && result.texture_index < 0; 63 light_probe_index_offset += 1u) { 64 let light_probe_index = i32(clustered_forward::get_clusterable_object_id( 65 light_probe_index_offset)); 67 var light_probe: LightProbe; 68 if is_irradiance_volume { 69 light_probe = light_probes.irradiance_volumes[light_probe_index]; 71 light_probe = light_probes.reflection_probes[light_probe_index]; 75 let light_from_world = 76 transpose_affine_matrix(light_probe.light_from_world_transposed); 80 let probe_space_pos = (light_from_world * vec4<f32>(world_position, 1.0f)).xyz; 81 if (all(abs(probe_space_pos) <= vec3(0.5f))) { 82 result.texture_index = light_probe.cubemap_index; 83 result.intensity = light_probe.intensity; 84 result.light_from_world = light_from_world; 85 result.affects_lightmapped_mesh_diffuse = 86 light_probe.affects_lightmapped_mesh_diffuse != 0u; 94#else // AVAILABLE_STORAGE_BUFFER_BINDINGS >= 3 104 world_position: vec3<f32>, 105 is_irradiance_volume: bool, 106 clusterable_object_index_ranges: ptr<function, ClusterableObjectIndexRanges>, 107) -> LightProbeQueryResult { 108 var result: LightProbeQueryResult; 109 result.texture_index = -1; 111 var light_probe_count: i32; 112 if is_irradiance_volume { 113 light_probe_count = light_probes.irradiance_volume_count; 115 light_probe_count = light_probes.reflection_probe_count; 118 for (var light_probe_index: i32 = 0; 119 light_probe_index < light_probe_count && result.texture_index < 0; 120 light_probe_index += 1) { 121 var light_probe: LightProbe; 122 if is_irradiance_volume { 123 light_probe = light_probes.irradiance_volumes[light_probe_index]; 125 light_probe = light_probes.reflection_probes[light_probe_index]; 129 let light_from_world = 130 transpose_affine_matrix(light_probe.light_from_world_transposed); 134 let probe_space_pos = (light_from_world * vec4<f32>(world_position, 1.0f)).xyz; 135 if (all(abs(probe_space_pos) <= vec3(0.5f))) { 136 result.texture_index = light_probe.cubemap_index; 137 result.intensity = light_probe.intensity; 138 result.light_from_world = light_from_world; 139 result.affects_lightmapped_mesh_diffuse = 140 light_probe.affects_lightmapped_mesh_diffuse != 0u; 154#endif // AVAILABLE_STORAGE_BUFFER_BINDINGS >= 3