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::{
2 mesh_view_types::Lights,
3 atmosphere::{
4 types::{Atmosphere, AtmosphereSettings},
5 bindings::{atmosphere, view, settings},
6 functions::{
7 sample_atmosphere, get_local_up, AtmosphereSample,
8 sample_local_inscattering, get_local_r, view_radius,
9 max_atmosphere_distance, direction_atmosphere_to_world,
10 sky_view_lut_uv_to_zenith_azimuth, zenith_azimuth_to_ray_dir,
11 MIDPOINT_RATIO
12 },
13 }
16#import bevy_render::{
17 view::View,
18 maths::HALF_PI,
20#import bevy_core_pipeline::fullscreen_vertex_shader::FullscreenVertexOutput
22@group(0) @binding(13) var sky_view_lut_out: texture_storage_2d<rgba16float, write>;
24@compute
25@workgroup_size(16, 16, 1)
26fn main(@builtin(global_invocation_id) idx: vec3<u32>) {
27 let uv = vec2<f32>(idx.xy) / vec2<f32>(settings.sky_view_lut_size);
29 let r = view_radius();
30 var zenith_azimuth = sky_view_lut_uv_to_zenith_azimuth(r, uv);
32 let ray_dir_as = zenith_azimuth_to_ray_dir(zenith_azimuth.x, zenith_azimuth.y);
33 let ray_dir_ws = direction_atmosphere_to_world(ray_dir_as);
35 let mu = ray_dir_ws.y;
36 let t_max = max_atmosphere_distance(r, mu);
38 let sample_count = mix(1.0, f32(settings.sky_view_lut_samples), clamp(t_max * 0.01, 0.0, 1.0));
39 var total_inscattering = vec3(0.0);
40 var throughput = vec3(1.0);
41 var prev_t = 0.0;
42 for (var s = 0.0; s < sample_count; s += 1.0) {
43 let t_i = t_max * (s + MIDPOINT_RATIO) / sample_count;
44 let dt_i = (t_i - prev_t);
45 prev_t = t_i;
47 let local_r = get_local_r(r, mu, t_i);
48 let local_up = get_local_up(r, t_i, ray_dir_ws);
49 let local_atmosphere = sample_atmosphere(local_r);
51 let sample_optical_depth = local_atmosphere.extinction * dt_i;
52 let sample_transmittance = exp(-sample_optical_depth);
54 let inscattering = sample_local_inscattering(
55 local_atmosphere,
56 ray_dir_ws,
57 local_r,
58 local_up
59 );
61 // Analytical integration of the single scattering term in the radiance transfer equation
62 let s_int = (inscattering - inscattering * sample_transmittance) / local_atmosphere.extinction;
63 total_inscattering += throughput * s_int;
65 throughput *= sample_transmittance;
66 if all(throughput < vec3(0.001)) {
67 break;
68 }
69 }
71 textureStore(sky_view_lut_out, idx.xy, vec4(total_inscattering, 1.0));
Contents