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::atmosphere::{
2 types::{Atmosphere, AtmosphereSettings},
3 bindings::{atmosphere, view, atmosphere_transforms},
4 functions::{
5 sample_transmittance_lut, sample_transmittance_lut_segment,
6 sample_sky_view_lut, direction_world_to_atmosphere,
7 uv_to_ray_direction, uv_to_ndc, sample_aerial_view_lut,
8 view_radius, sample_sun_radiance, ndc_to_camera_dist
9 },
10};
11#import bevy_render::view::View;
13#import bevy_core_pipeline::fullscreen_vertex_shader::FullscreenVertexOutput
15#ifdef MULTISAMPLED
16@group(0) @binding(13) var depth_texture: texture_depth_multisampled_2d;
17#else
18@group(0) @binding(13) var depth_texture: texture_depth_2d;
19#endif
21struct RenderSkyOutput {
22 @location(0) inscattering: vec4<f32>,
23#ifdef DUAL_SOURCE_BLENDING
24 @location(0) @second_blend_source transmittance: vec4<f32>,
25#endif
28@fragment
29fn main(in: FullscreenVertexOutput) -> RenderSkyOutput {
30 let depth = textureLoad(depth_texture, vec2<i32>(in.position.xy), 0);
32 let ray_dir_ws = uv_to_ray_direction(in.uv);
33 let r = view_radius();
34 let mu = ray_dir_ws.y;
36 var transmittance: vec3<f32>;
37 var inscattering: vec3<f32>;
39 let sun_radiance = sample_sun_radiance(ray_dir_ws.xyz);
41 if depth == 0.0 {
42 let ray_dir_as = direction_world_to_atmosphere(ray_dir_ws.xyz);
43 transmittance = sample_transmittance_lut(r, mu);
44 inscattering += sample_sky_view_lut(r, ray_dir_as);
45 inscattering += sun_radiance * transmittance * view.exposure;
46 } else {
47 let t = ndc_to_camera_dist(vec3(uv_to_ndc(in.uv), depth));
48 inscattering = sample_aerial_view_lut(in.uv, t);
49 transmittance = sample_transmittance_lut_segment(r, mu, t);
50 }
51#ifdef DUAL_SOURCE_BLENDING
52 return RenderSkyOutput(vec4(inscattering, 0.0), vec4(transmittance, 1.0));
53#else
54 let mean_transmittance = (transmittance.r + transmittance.g + transmittance.b) / 3.0;
55 return RenderSkyOutput(vec4(inscattering, mean_transmittance));
56#endif
Contents