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// A postprocessing shader that implements volumetric fog via raymarching and
2// sampling directional light shadow maps.
3//
4// The overall approach is a combination of the volumetric rendering in [1] and
5// the shadow map raymarching in [2]. First, we raytrace the AABB of the fog
6// volume in order to determine how long our ray is. Then we do a raymarch, with
7// physically-based calculations at each step to determine how much light was
8// absorbed, scattered out, and scattered in. To determine in-scattering, we
9// sample the shadow map for the light to determine whether the point was in
10// shadow or not.
11//
12// [1]: https://www.scratchapixel.com/lessons/3d-basic-rendering/volume-rendering-for-developers/intro-volume-rendering.html
13//
14// [2]: http://www.alexandre-pestana.com/volumetric-lights/
16#import bevy_core_pipeline::fullscreen_vertex_shader::FullscreenVertexOutput
17#import bevy_pbr::atmosphere::{
18 functions::{calculate_visible_sun_ratio, clamp_to_surface},
19 bruneton_functions::transmittance_lut_r_mu_to_uv,
21#import bevy_pbr::mesh_functions::{get_world_from_local, mesh_position_local_to_clip}
22#import bevy_pbr::mesh_view_bindings::{
23 globals, lights, view, clustered_lights,
24 atmosphere, atmosphere_transmittance_texture, atmosphere_transmittance_sampler
26#import bevy_pbr::mesh_view_types::{
27 DIRECTIONAL_LIGHT_FLAGS_VOLUMETRIC_BIT,
28 POINT_LIGHT_FLAGS_SHADOWS_ENABLED_BIT,
29 POINT_LIGHT_FLAGS_VOLUMETRIC_BIT,
30 POINT_LIGHT_FLAGS_SPOT_LIGHT_Y_NEGATIVE,
32#import bevy_pbr::shadow_sampling::{
33 sample_shadow_map_hardware,
34 sample_shadow_cubemap,
35 sample_shadow_map,
36 SPOT_SHADOW_TEXEL_SIZE
38#import bevy_pbr::shadows::{get_cascade_index, world_to_directional_light_local}
39#import bevy_pbr::utils::interleaved_gradient_noise
40#import bevy_pbr::view_transformations::{
41 depth_ndc_to_view_z,
42 frag_coord_to_ndc,
43 position_ndc_to_view,
44 position_ndc_to_world,
45 position_view_to_world
47#import bevy_render::maths::orthonormalize
48#import bevy_pbr::clustered_forward as clustering
49#import bevy_pbr::lighting::getDistanceAttenuation;
51// The GPU version of [`VolumetricFog`]. See the comments in
52// `volumetric_fog/mod.rs` for descriptions of the fields here.
53struct VolumetricFog {
54 clip_from_local: mat4x4<f32>,
55 uvw_from_world: mat4x4<f32>,
56 far_planes: array<vec4<f32>, 6>,
57 fog_color: vec3<f32>,
58 light_tint: vec3<f32>,
59 ambient_color: vec3<f32>,
60 ambient_intensity: f32,
61 step_count: u32,
62 bounding_radius: f32,
63 absorption: f32,
64 scattering: f32,
65 density_factor: f32,
66 density_texture_offset: vec3<f32>,
67 scattering_asymmetry: f32,
68 light_intensity: f32,
69 jitter_strength: f32,
72@group(1) @binding(0) var<uniform> volumetric_fog: VolumetricFog;
74#ifdef MULTISAMPLED
75@group(1) @binding(1) var depth_texture: texture_depth_multisampled_2d;
76#else
77@group(1) @binding(1) var depth_texture: texture_depth_2d;
78#endif
80#ifdef DENSITY_TEXTURE
81@group(1) @binding(2) var density_texture: texture_3d<f32>;
82@group(1) @binding(3) var density_sampler: sampler;
83#endif // DENSITY_TEXTURE
85// 1 / (4π)
86const FRAC_4_PI: f32 = 0.07957747154594767;
88struct Vertex {
89 @builtin(instance_index) instance_index: u32,
90 @location(0) position: vec3<f32>,
93@vertex
94fn vertex(vertex: Vertex) -> @builtin(position) vec4<f32> {
95 return volumetric_fog.clip_from_local * vec4<f32>(vertex.position, 1.0);
98// The common Henyey-Greenstein asymmetric phase function [1] [2].
99//
100// This determines how much light goes toward the viewer as opposed to away from
101// the viewer. From a visual point of view, it controls how the light shafts
102// appear and disappear as the camera looks at the light source.
103//
104// [1]: https://www.scratchapixel.com/lessons/3d-basic-rendering/volume-rendering-for-developers/ray-marching-get-it-right.html
105//
106// [2]: https://www.pbr-book.org/4ed/Volume_Scattering/Phase_Functions#TheHenyeyndashGreensteinPhaseFunction
107fn henyey_greenstein(neg_LdotV: f32) -> f32 {
108 let g = volumetric_fog.scattering_asymmetry;
109 let denom = 1.0 + g * g - 2.0 * g * neg_LdotV;
110 return FRAC_4_PI * (1.0 - g * g) / (denom * sqrt(denom));
113@fragment
114fn fragment(@builtin(position) position: vec4<f32>) -> @location(0) vec4<f32> {
115 // Unpack the `volumetric_fog` settings.
116 let uvw_from_world = volumetric_fog.uvw_from_world;
117 let fog_color = volumetric_fog.fog_color;
118 let ambient_color = volumetric_fog.ambient_color;
119 let ambient_intensity = volumetric_fog.ambient_intensity;
120 let step_count = volumetric_fog.step_count;
121 let bounding_radius = volumetric_fog.bounding_radius;
122 let absorption = volumetric_fog.absorption;
123 let scattering = volumetric_fog.scattering;
124 let density_factor = volumetric_fog.density_factor;
125 let density_texture_offset = volumetric_fog.density_texture_offset;
126 let light_tint = volumetric_fog.light_tint;
127 let light_intensity = volumetric_fog.light_intensity;
128 let jitter_strength = volumetric_fog.jitter_strength;
130 // Unpack the view.
131 let exposure = view.exposure;
133 // Sample the depth to put an upper bound on the length of the ray (as we
134 // shouldn't trace through solid objects). If this is multisample, just use
135 // sample 0; this is approximate but good enough.
136 let frag_coord = position;
137 let ndc_end_depth_from_buffer = textureLoad(depth_texture, vec2<i32>(frag_coord.xy), 0);
138 let view_end_depth_from_buffer = -position_ndc_to_view(
139 frag_coord_to_ndc(vec4(position.xy, ndc_end_depth_from_buffer, 1.0))).z;
141 // Calculate the start position of the ray. Since we're only rendering front
142 // faces of the AABB, this is the current fragment's depth.
143 let view_start_pos = position_ndc_to_view(frag_coord_to_ndc(frag_coord));
145 // Calculate the end position of the ray. This requires us to raytrace the
146 // back faces of the AABB to find the one that our ray intersects.
147 var end_depth_view = 0.0;
148 for (var plane_index = 0; plane_index < 6; plane_index += 1) {
149 let plane = volumetric_fog.far_planes[plane_index];
150 let other_plane_a = volumetric_fog.far_planes[(plane_index + 1) % 6];
151 let other_plane_b = volumetric_fog.far_planes[(plane_index + 2) % 6];
152 let other_plane_c = volumetric_fog.far_planes[(plane_index + 3) % 6];
153 let other_plane_d = volumetric_fog.far_planes[(plane_index + 4) % 6];
154 let other_plane_e = volumetric_fog.far_planes[(plane_index + 5) % 6];
156 // Calculate the intersection of the ray and the plane. The ray must
157 // intersect in front of us (t > 0).
158 let t = -plane.w / dot(plane.xyz, view_start_pos.xyz);
159 if (t < 0.0) {
160 continue;
161 }
162 let hit_pos = view_start_pos.xyz * t;
164 // The intersection point must be in front of the other backfaces.
165 // If those tests pass, we found our backface.
166 if (dot(vec4(hit_pos, 1.0), other_plane_a) >= 0.0 &&
167 dot(vec4(hit_pos, 1.0), other_plane_b) >= 0.0 &&
168 dot(vec4(hit_pos, 1.0), other_plane_c) >= 0.0 &&
169 dot(vec4(hit_pos, 1.0), other_plane_d) >= 0.0 &&
170 dot(vec4(hit_pos, 1.0), other_plane_e) >= 0.0)
171 {
172 end_depth_view = -hit_pos.z;
173 break;
174 }
175 }
177 // Starting at the end depth, which we got above, figure out how long the
178 // ray we want to trace is and the length of each increment.
179 end_depth_view = min(end_depth_view, view_end_depth_from_buffer);
181 // We assume world and view have the same scale here.
182 let start_depth_view = -depth_ndc_to_view_z(frag_coord.z);
184 let ray_length_view = max(0.0, end_depth_view - start_depth_view);
185 // If the end is behind the start of the first opaque pixel, then we know it
186 // is occluded, and we don't need to render it
187 if (ray_length_view == 0.0) {
188 return vec4(0.0, 0.0, 0.0, 0.0);
189 }
190 let inv_step_count = 1.0 / f32(step_count);
191 let step_size_world = ray_length_view * inv_step_count;
193 let directional_light_count = lights.n_directional_lights;
195 // Calculate the ray origin (`Ro`) and the ray direction (`Rd`) in NDC,
196 // view, and world coordinates.
197 let Rd_ndc = vec3(frag_coord_to_ndc(position).xy, 1.0);
198 let Rd_view = normalize(position_ndc_to_view(Rd_ndc));
199 var Ro_world = position_view_to_world(view_start_pos.xyz);
200 let Rd_world = normalize(position_ndc_to_world(Rd_ndc) - view.world_position);
202 // Offset by jitter.
203 let jitter = interleaved_gradient_noise(position.xy, globals.frame_count) * jitter_strength;
204 Ro_world += Rd_world * jitter;
206 // Use Beer's law [1] [2] to calculate the maximum amount of light that each
207 // directional light could contribute, and modulate that value by the light
208 // tint and fog color. (The actual value will in turn be modulated by the
209 // phase according to the Henyey-Greenstein formula.)
210 //
211 // [1]: https://www.scratchapixel.com/lessons/3d-basic-rendering/volume-rendering-for-developers/intro-volume-rendering.html
212 //
213 // [2]: https://en.wikipedia.org/wiki/Beer%E2%80%93Lambert_law
215 // Use Beer's law again to accumulate the ambient light all along the path.
216 var accumulated_color = exp(-ray_length_view * (absorption + scattering)) * ambient_color *
217 ambient_intensity;
219 // This is the amount of the background that shows through. We're actually
220 // going to recompute this over and over again for each directional light,
221 // coming up with the same values each time.
222 var background_alpha = 1.0;
224 // If we have a density texture, transform to its local space.
225#ifdef DENSITY_TEXTURE
226 let Ro_uvw = (uvw_from_world * vec4(Ro_world, 1.0)).xyz;
227 let Rd_step_uvw = mat3x3(uvw_from_world[0].xyz, uvw_from_world[1].xyz, uvw_from_world[2].xyz) *
228 (Rd_world * step_size_world);
229#endif // DENSITY_TEXTURE
231 for (var light_index = 0u; light_index < directional_light_count; light_index += 1u) {
232 // Volumetric lights are all sorted first, so the first time we come to
233 // a non-volumetric light, we know we've seen them all.
234 let light = &lights.directional_lights[light_index];
235 if (((*light).flags & DIRECTIONAL_LIGHT_FLAGS_VOLUMETRIC_BIT) == 0) {
236 break;
237 }
239 let L = (*light).direction_to_light.xyz;
241 // Offset the depth value by the bias.
242 let depth_offset = (*light).shadow_depth_bias * L;
244 // Compute phase, which determines the fraction of light that's
245 // scattered toward the camera instead of away from it.
246 let neg_LdotV = dot(normalize(L), Rd_world);
247 let phase = henyey_greenstein(neg_LdotV);
249 // Reset `background_alpha` for a new raymarch.
250 background_alpha = 1.0;
252 // Start raymarching.
253 for (var step = 0u; step < step_count; step += 1u) {
254 // As an optimization, break if we've gotten too dark.
255 if (background_alpha < 0.001) {
256 break;
257 }
259 // Calculate where we are in the ray.
260 let P_world = Ro_world + Rd_world * f32(step) * step_size_world;
261 let P_view = view_start_pos + Rd_view * f32(step) * step_size_world;
263 var density = density_factor;
264#ifdef DENSITY_TEXTURE
265 // Take the density texture into account, if there is one.
266 //
267 // The uvs should never go outside the (0, 0, 0) to (1, 1, 1) box,
268 // but sometimes due to floating point error they can. Handle this
269 // case.
270 let P_uvw = Ro_uvw + Rd_step_uvw * f32(step);
271 if (all(P_uvw >= vec3(0.0)) && all(P_uvw <= vec3(1.0))) {
272 density *= textureSampleLevel(density_texture, density_sampler, P_uvw + density_texture_offset, 0.0).r;
273 } else {
274 density = 0.0;
275 }
276#endif // DENSITY_TEXTURE
278 // Calculate absorption (amount of light absorbed by the fog) and
279 // out-scattering (amount of light the fog scattered away).
280 let sample_attenuation = exp(-step_size_world * density * (absorption + scattering));
282 // Process absorption and out-scattering.
283 background_alpha *= sample_attenuation;
285 // Compute in-scattering (amount of light other fog particles
286 // scattered into this ray). This is where any directional light is
287 // scattered in.
289 // Prepare to sample the shadow map.
290 let cascade_index = get_cascade_index(light_index, P_view.z);
291 let light_local = world_to_directional_light_local(
292 light_index,
293 cascade_index,
294 vec4(P_world + depth_offset, 1.0)
295 );
297 // If we're outside the shadow map entirely, local light attenuation
298 // is zero.
299 var local_light_attenuation = f32(light_local.w != 0.0);
301 // Otherwise, sample the shadow map to determine whether, and by how
302 // much, this sample is in the light.
303 if (local_light_attenuation != 0.0) {
304 let cascade = &(*light).cascades[cascade_index];
305 let array_index = i32((*light).depth_texture_base_index + cascade_index);
306 local_light_attenuation =
307 sample_shadow_map_hardware(light_local.xy, light_local.z, array_index);
308 }
310 if (local_light_attenuation != 0.0) {
311 let light_attenuation = exp(-density * bounding_radius * (absorption + scattering));
312 var light_factors_per_step = fog_color * light_tint * light_attenuation *
313 scattering * density * step_size_world * light_intensity * exposure;
315#ifdef ATMOSPHERE
316 // attenuate by atmospheric scattering
317 let P = P_world + depth_offset;
318 let P_as = (atmosphere.world_to_atmosphere * vec4(P, 1.0)).xyz;
319 let P_clamped = clamp_to_surface(atmosphere, P_as);
320 let r = length(P_clamped);
321 let local_up = normalize(P_clamped);
322 let mu_light = dot(L, local_up);
324 let transmittance = sample_transmittance_lut(r, mu_light);
325 let sun_visibility = calculate_visible_sun_ratio(atmosphere, r, mu_light, (*light).sun_disk_angular_size);
326 light_factors_per_step *= transmittance * sun_visibility;
327#endif
329 // Modulate the factor we calculated above by the phase, fog color,
330 // light color, light tint.
331 let light_color_per_step = (*light).color.rgb * phase * light_factors_per_step;
333 // Accumulate the light.
334 accumulated_color += light_color_per_step * local_light_attenuation *
335 background_alpha;
336 }
337 }
338 }
340 // Point lights and Spot lights
341 let is_orthographic = view.clip_from_view[3].w == 1.0;
343 // Reset `background_alpha` for a new raymarch.
344 background_alpha = 1.0;
346 // Start raymarching.
347 for (var step = 0u; step < step_count; step += 1u) {
348 // As an optimization, break if we've gotten too dark.
349 if (background_alpha < 0.001) {
350 break;
351 }
353 // Calculate where we are in the ray.
354 let P_world = Ro_world + Rd_world * f32(step) * step_size_world;
355 let P_view = view_start_pos + Rd_view * f32(step) * step_size_world;
357 var density = density_factor;
358#ifdef DENSITY_TEXTURE
359 // Take the density texture into account, if there is one.
360 //
361 // The uvs should never go outside the (0, 0, 0) to (1, 1, 1) box,
362 // but sometimes due to floating point error they can. Handle this
363 // case.
364 let P_uvw = Ro_uvw + Rd_step_uvw * f32(step);
365 if (all(P_uvw >= vec3(0.0)) && all(P_uvw <= vec3(1.0))) {
366 density *= textureSampleLevel(density_texture, density_sampler, P_uvw + density_texture_offset, 0.0).r;
367 } else {
368 density = 0.0;
369 }
370#endif // DENSITY_TEXTURE
372 var sample_color = vec3(0.0);
374 let cluster_index = clustering::view_fragment_cluster_index(frag_coord.xy, P_view.z, is_orthographic);
375 var clusterable_object_index_ranges = clustering::unpack_clusterable_object_index_ranges(cluster_index);
376 for (var i: u32 = clusterable_object_index_ranges.first_point_light_index_offset;
377 i < clusterable_object_index_ranges.first_reflection_probe_index_offset;
378 i = i + 1u)
379 {
380 let light_id = clustering::get_clusterable_object_id(i);
381 let light = &clustered_lights.data[light_id];
382 if (((*light).flags & POINT_LIGHT_FLAGS_VOLUMETRIC_BIT) == 0) {
383 continue;
384 }
386 let light_to_frag = (*light).position_radius.xyz - P_world;
387 let V = Rd_world;
388 let L = normalize(light_to_frag);
389 let distance_square = dot(light_to_frag, light_to_frag);
390 let distance_atten = getDistanceAttenuation(distance_square, (*light).color_inverse_square_range.w);
391 var local_light_attenuation = distance_atten;
392 if (i < clusterable_object_index_ranges.first_spot_light_index_offset) {
393 var shadow: f32 = 1.0;
394 if (((*light).flags & POINT_LIGHT_FLAGS_SHADOWS_ENABLED_BIT) != 0u) {
395 shadow = fetch_point_shadow_without_normal(light_id, vec4(P_world, 1.0), position.xy);
396 }
397 local_light_attenuation *= shadow;
398 } else {
399 // spot light attenuation
400 // reconstruct spot dir from x/z and y-direction flag
401 var spot_dir = vec3<f32>((*light).light_custom_data.x, 0.0, (*light).light_custom_data.y);
402 spot_dir.y = sqrt(max(0.0, 1.0 - spot_dir.x * spot_dir.x - spot_dir.z * spot_dir.z));
403 if ((*light).flags & POINT_LIGHT_FLAGS_SPOT_LIGHT_Y_NEGATIVE) != 0u {
404 spot_dir.y = -spot_dir.y;
405 }
407 // calculate attenuation based on filament formula https://google.github.io/filament/Filament.md.html#listing_glslpunctuallight
408 // spot_scale and spot_offset have been precomputed
409 // note we normalize here to get "l" from the filament listing. spot_dir is already normalized
410 let cd = dot(-spot_dir, normalize(light_to_frag));
411 let attenuation = saturate(cd * (*light).light_custom_data.z + (*light).light_custom_data.w);
412 let spot_attenuation = attenuation * attenuation;
414 var shadow: f32 = 1.0;
415 if (((*light).flags & POINT_LIGHT_FLAGS_SHADOWS_ENABLED_BIT) != 0u) {
416 shadow = fetch_spot_shadow_without_normal(light_id, vec4(P_world, 1.0), position.xy);
417 }
418 local_light_attenuation *= spot_attenuation * shadow;
419 }
421 let light_attenuation = exp(-density * bounding_radius * (absorption + scattering));
422 let light_factors_per_step = fog_color * light_tint * light_attenuation *
423 scattering * density * step_size_world * light_intensity * exposure;
425 // Modulate the factor we calculated above by the phase, fog color,
426 // light color, light tint.
427 let light_color_per_step = (*light).color_inverse_square_range.rgb * light_factors_per_step;
429 // Accumulate the light.
430 sample_color += light_color_per_step * local_light_attenuation;
431 }
433 // Calculate absorption (amount of light absorbed by the fog) and
434 // out-scattering (amount of light the fog scattered away).
435 let sample_attenuation = exp(-step_size_world * density * (absorption + scattering));
437 // Process absorption and out-scattering.
438 background_alpha *= sample_attenuation;
439 accumulated_color += sample_color * background_alpha;
440 }
442 // We're done! Return the color with alpha so it can be blended onto the
443 // render target.
444 return vec4(accumulated_color, 1.0 - background_alpha);
447fn fetch_point_shadow_without_normal(light_id: u32, frag_position: vec4<f32>, frag_coord_xy: vec2<f32>) -> f32 {
448 let light = &clustered_lights.data[light_id];
450 // because the shadow maps align with the axes and the frustum planes are at 45 degrees
451 // we can get the worldspace depth by taking the largest absolute axis
452 let surface_to_light = (*light).position_radius.xyz - frag_position.xyz;
453 let surface_to_light_abs = abs(surface_to_light);
454 let distance_to_light = max(surface_to_light_abs.x, max(surface_to_light_abs.y, surface_to_light_abs.z));
456 // The normal bias here is already scaled by the texel size at 1 world unit from the light.
457 // The texel size increases proportionally with distance from the light so multiplying by
458 // distance to light scales the normal bias to the texel size at the fragment distance.
459 let depth_offset = (*light).shadow_depth_bias * normalize(surface_to_light.xyz);
460 let offset_position = frag_position.xyz + depth_offset;
462 // similar largest-absolute-axis trick as above, but now with the offset fragment position
463 let frag_ls = offset_position.xyz - (*light).position_radius.xyz;
464 let abs_position_ls = abs(frag_ls);
465 let major_axis_magnitude = max(abs_position_ls.x, max(abs_position_ls.y, abs_position_ls.z));
467 // NOTE: These simplifications come from multiplying:
468 // projection * vec4(0, 0, -major_axis_magnitude, 1.0)
469 // and keeping only the terms that have any impact on the depth.
470 // Projection-agnostic approach:
471 let zw = -major_axis_magnitude * (*light).light_custom_data.xy + (*light).light_custom_data.zw;
472 let depth = zw.x / zw.y;
474 // Do the lookup, using HW PCF and comparison. Cubemaps assume a left-handed coordinate space,
475 // so we have to flip the z-axis when sampling.
476 let flip_z = vec3(1.0, 1.0, -1.0);
477 return sample_shadow_cubemap(frag_ls * flip_z, distance_to_light, depth, light_id, frag_coord_xy);
480fn fetch_spot_shadow_without_normal(light_id: u32, frag_position: vec4<f32>, frag_coord_xy: vec2<f32>) -> f32 {
481 let light = &clustered_lights.data[light_id];
483 let surface_to_light = (*light).position_radius.xyz - frag_position.xyz;
485 // construct the light view matrix
486 var spot_dir = vec3<f32>((*light).light_custom_data.x, 0.0, (*light).light_custom_data.y);
487 // reconstruct spot dir from x/z and y-direction flag
488 spot_dir.y = sqrt(max(0.0, 1.0 - spot_dir.x * spot_dir.x - spot_dir.z * spot_dir.z));
489 if (((*light).flags & POINT_LIGHT_FLAGS_SPOT_LIGHT_Y_NEGATIVE) != 0u) {
490 spot_dir.y = -spot_dir.y;
491 }
493 // view matrix z_axis is the reverse of transform.forward()
494 let fwd = -spot_dir;
495 let offset_position =
496 -surface_to_light
497 + ((*light).shadow_depth_bias * normalize(surface_to_light));
499 let light_inv_rot = orthonormalize(fwd);
501 // because the matrix is a pure rotation matrix, the inverse is just the transpose, and to calculate
502 // the product of the transpose with a vector we can just post-multiply instead of pre-multiplying.
503 // this allows us to keep the matrix construction code identical between CPU and GPU.
504 let projected_position = offset_position * light_inv_rot;
506 // divide xy by perspective matrix "f" and by -projected.z (projected.z is -projection matrix's w)
507 // to get ndc coordinates
508 let f_div_minus_z = 1.0 / ((*light).spot_light_tan_angle * -projected_position.z);
509 let shadow_xy_ndc = projected_position.xy * f_div_minus_z;
510 // convert to uv coordinates
511 let shadow_uv = shadow_xy_ndc * vec2<f32>(0.5, -0.5) + vec2<f32>(0.5, 0.5);
513 // 0.1 must match POINT_LIGHT_NEAR_Z
514 let depth = 0.1 / -projected_position.z;
516 return sample_shadow_map(
517 shadow_uv,
518 depth,
519 i32(light_id) + lights.spot_light_shadowmap_offset,
520 frag_coord_xy,
521 SPOT_SHADOW_TEXEL_SIZE
522 );
525#ifdef ATMOSPHERE
526fn sample_transmittance_lut(r: f32, mu: f32) -> vec3<f32> {
527 let uv = transmittance_lut_r_mu_to_uv(atmosphere, r, mu);
528 return textureSampleLevel(
529 atmosphere_transmittance_texture,
530 atmosphere_transmittance_sampler, uv, 0.0).rgb;
532#endif // ATMOSPHERE
Contents