Search across packages, versions, files, declarations, and comments. Use multiple terms to narrow results (AND), and add @vertex, @fragment, or @compute to filter by shader stage.
1#import bevy_pbr::forward_io::VertexOutput
2#import bevy_pbr::irradiance_volume
3#import bevy_pbr::mesh_view_bindings
4#import bevy_pbr::clustered_forward
6struct VoxelVisualizationIrradianceVolumeInfo {
7 world_from_voxel: mat4x4<f32>,
8 voxel_from_world: mat4x4<f32>,
9 resolution: vec3<u32>,
10 // A scale factor that's applied to the diffuse and specular light from the
11 // light probe. This is in units of cd/m² (candela per square meter).
12 intensity: f32,
15@group(#{MATERIAL_BIND_GROUP}) @binding(100)
16var<uniform> irradiance_volume_info: VoxelVisualizationIrradianceVolumeInfo;
18@fragment
19fn fragment(mesh: VertexOutput) -> @location(0) vec4<f32> {
20 // Snap the world position we provide to `irradiance_volume_light()` to the
21 // middle of the nearest texel.
22 var unit_pos = (irradiance_volume_info.voxel_from_world *
23 vec4(mesh.world_position.xyz, 1.0f)).xyz;
24 let resolution = vec3<f32>(irradiance_volume_info.resolution);
25 let stp = clamp((unit_pos + 0.5) * resolution, vec3(0.5f), resolution - vec3(0.5f));
26 let stp_rounded = round(stp - 0.5f) + 0.5f;
27 let rounded_world_pos = (irradiance_volume_info.world_from_voxel * vec4(stp_rounded, 1.0f)).xyz;
29 // Look up the irradiance volume range in the cluster list.
30 let view_z = dot(vec4<f32>(
31 mesh_view_bindings::view.view_from_world[0].z,
32 mesh_view_bindings::view.view_from_world[1].z,
33 mesh_view_bindings::view.view_from_world[2].z,
34 mesh_view_bindings::view.view_from_world[3].z
35 ), mesh.world_position);
36 let cluster_index = clustered_forward::view_fragment_cluster_index(mesh.position.xy, view_z, false);
37 var clusterable_object_index_ranges =
38 clustered_forward::unpack_clusterable_object_index_ranges(cluster_index);
40 // `irradiance_volume_light()` multiplies by intensity, so cancel it out.
41 // If we take intensity into account, the cubes will be way too bright.
42 let rgb = irradiance_volume::irradiance_volume_light(
43 mesh.world_position.xyz,
44 mesh.world_normal,
45 &clusterable_object_index_ranges,
46 ) / irradiance_volume_info.intensity;
48 return vec4<f32>(rgb, 1.0f);
Contents