1#define_import_path bevy_pbr::irradiance_volume 3#import bevy_pbr::light_probe::{light_probe_iterator_new, light_probe_iterator_next} 4#import bevy_pbr::mesh_view_bindings::{ 7 irradiance_volume_sampler, 10#import bevy_pbr::clustered_forward::ClusterableObjectIndexRanges 13#import bevy_pbr::mesh_view_types::LIGHT_PROBE_FLAG_AFFECTS_LIGHTMAPPED_MESH_DIFFUSE; 16#ifdef IRRADIANCE_VOLUMES_ARE_USABLE 21fn irradiance_volume_light( 22 world_position: vec3<f32>, 24 clusterable_object_index_ranges: ptr<function, ClusterableObjectIndexRanges>, 28 var iterator = light_probe_iterator_new( 31 clusterable_object_index_ranges, 34 var total_weight = 0.0; 35 var total_irradiance = vec3(0.0); 38 var query_result = light_probe_iterator_next(&iterator); 41 if (query_result.texture_index < 0) { 48 if ((query_result.flags & LIGHT_PROBE_FLAG_AFFECTS_LIGHTMAPPED_MESH_DIFFUSE) == 0u) { 53 #ifdef MULTIPLE_LIGHT_PROBES_IN_ARRAY 54 let irradiance_volume_texture = irradiance_volumes[query_result.texture_index]; 56 let irradiance_volume_texture = irradiance_volume; 59 let atlas_resolution = vec3<f32>(textureDimensions(irradiance_volume_texture)); 60 let resolution = vec3<f32>(textureDimensions(irradiance_volume_texture) / vec3(1u, 2u, 3u)); 63 var unit_pos = (query_result.light_from_world * vec4(world_position, 1.0f)).xyz; 64 let stp = clamp((unit_pos + 0.5) * resolution, vec3(0.5f), resolution - vec3(0.5f)); 65 let uvw = stp / atlas_resolution; 69 let neg_offset = select(vec3(0.0f), vec3(0.5f), N < vec3(0.0f)); 71 let uvw_x = uvw + vec3(0.0f, neg_offset.x, 0.0f); 72 let uvw_y = uvw + vec3(0.0f, neg_offset.y, 1.0f / 3.0f); 73 let uvw_z = uvw + vec3(0.0f, neg_offset.z, 2.0f / 3.0f); 75 let rgb_x = textureSampleLevel(irradiance_volume_texture, irradiance_volume_sampler, uvw_x, 0.0).rgb; 76 let rgb_y = textureSampleLevel(irradiance_volume_texture, irradiance_volume_sampler, uvw_y, 0.0).rgb; 77 let rgb_z = textureSampleLevel(irradiance_volume_texture, irradiance_volume_sampler, uvw_z, 0.0).rgb; 81 total_irradiance += (rgb_x * NN.x + rgb_y * NN.y + rgb_z * NN.z) * query_result.intensity * 84 total_weight += query_result.weight; 87 if (total_weight != 0.0) { 88 total_irradiance /= total_weight; 91 return total_irradiance; 94#endif // IRRADIANCE_VOLUMES_ARE_USABLE