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
5struct VoxelVisualizationIrradianceVolumeInfo {
6 world_from_voxel: mat4x4<f32>,
7 voxel_from_world: mat4x4<f32>,
8 resolution: vec3<u32>,
9 // A scale factor that's applied to the diffuse and specular light from the
10 // light probe. This is in units of cd/m² (candela per square meter).
11 intensity: f32,
14@group(2) @binding(100)
15var<uniform> irradiance_volume_info: VoxelVisualizationIrradianceVolumeInfo;
17@fragment
18fn fragment(mesh: VertexOutput) -> @location(0) vec4<f32> {
19 // Snap the world position we provide to `irradiance_volume_light()` to the
20 // middle of the nearest texel.
21 var unit_pos = (irradiance_volume_info.voxel_from_world *
22 vec4(mesh.world_position.xyz, 1.0f)).xyz;
23 let resolution = vec3<f32>(irradiance_volume_info.resolution);
24 let stp = clamp((unit_pos + 0.5) * resolution, vec3(0.5f), resolution - vec3(0.5f));
25 let stp_rounded = round(stp - 0.5f) + 0.5f;
26 let rounded_world_pos = (irradiance_volume_info.world_from_voxel * vec4(stp_rounded, 1.0f)).xyz;
28 // `irradiance_volume_light()` multiplies by intensity, so cancel it out.
29 // If we take intensity into account, the cubes will be way too bright.
30 let rgb = irradiance_volume::irradiance_volume_light(
31 mesh.world_position.xyz,
32 mesh.world_normal) / irradiance_volume_info.intensity;
34 return vec4<f32>(rgb, 1.0f);
Contents