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#define_import_path bevy_pbr::lightmap
3#import bevy_pbr::mesh_bindings::mesh
5@group(1) @binding(4) var lightmaps_texture: texture_2d<f32>;
6@group(1) @binding(5) var lightmaps_sampler: sampler;
8// Samples the lightmap, if any, and returns indirect illumination from it.
9fn lightmap(uv: vec2<f32>, exposure: f32, instance_index: u32) -> vec3<f32> {
10 let packed_uv_rect = mesh[instance_index].lightmap_uv_rect;
11 let uv_rect = vec4<f32>(vec4<u32>(
12 packed_uv_rect.x & 0xffffu,
13 packed_uv_rect.x >> 16u,
14 packed_uv_rect.y & 0xffffu,
15 packed_uv_rect.y >> 16u)) / 65535.0;
17 let lightmap_uv = mix(uv_rect.xy, uv_rect.zw, uv);
19 // Mipmapping lightmaps is usually a bad idea due to leaking across UV
20 // islands, so there's no harm in using mip level 0 and it lets us avoid
21 // control flow uniformity problems.
22 //
23 // TODO(pcwalton): Consider bicubic filtering.
24 return textureSampleLevel(
25 lightmaps_texture,
26 lightmaps_sampler,
27 lightmap_uv,
28 0.0).rgb * exposure;
Contents