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.
1enable dual_source_blending;
3#import bevy_pbr::atmosphere::{
4 types::{Atmosphere, AtmosphereSettings},
5 bindings::{atmosphere, view, atmosphere_transforms, settings},
6 functions::{
7 sample_transmittance_lut, sample_transmittance_lut_segment,
8 sample_sky_view_lut, direction_world_to_atmosphere,
9 uv_to_ray_direction, uv_to_ndc, sample_aerial_view_lut,
10 sample_sun_radiance, ndc_to_camera_dist, raymarch_atmosphere,
11 get_view_position, max_atmosphere_distance
12 },
13};
14#import bevy_render::view::View;
16#import bevy_core_pipeline::fullscreen_vertex_shader::FullscreenVertexOutput
18#ifdef MULTISAMPLED
19@group(0) @binding(13) var depth_texture: texture_depth_multisampled_2d;
20#else
21@group(0) @binding(13) var depth_texture: texture_depth_2d;
22#endif
24struct RenderSkyOutput {
25#ifdef DUAL_SOURCE_BLENDING
26 @location(0) @blend_src(0) inscattering: vec4<f32>,
27 @location(0) @blend_src(1) transmittance: vec4<f32>,
28#else
29 @location(0) inscattering: vec4<f32>,
30#endif
33@fragment
34fn main(in: FullscreenVertexOutput) -> RenderSkyOutput {
35 let depth = textureLoad(depth_texture, vec2<i32>(in.position.xy), 0);
37 let ray_dir_ws = uv_to_ray_direction(in.uv);
38 let world_pos = get_view_position();
39 let r = length(world_pos);
40 let up = normalize(world_pos);
41 let mu = dot(ray_dir_ws, up);
42 let max_samples = settings.sky_max_samples;
43 let should_raymarch = settings.rendering_method == 1u;
45 var transmittance: vec3<f32>;
46 var inscattering: vec3<f32>;
48 let sun_radiance = sample_sun_radiance(ray_dir_ws);
50 if depth == 0.0 {
51 let ray_dir_as = direction_world_to_atmosphere(ray_dir_ws, up);
52 transmittance = sample_transmittance_lut(r, mu);
53 inscattering = sample_sky_view_lut(r, ray_dir_as);
54 if should_raymarch {
55 let t_max = max_atmosphere_distance(r, mu);
56 let result = raymarch_atmosphere(world_pos, ray_dir_ws, t_max, max_samples, in.uv, true);
57 inscattering = result.inscattering;
58 transmittance = result.transmittance;
59 }
60 inscattering += sun_radiance * transmittance;
61 } else {
62 let t = ndc_to_camera_dist(vec3(uv_to_ndc(in.uv), depth));
63 inscattering = sample_aerial_view_lut(in.uv, t);
64 transmittance = sample_transmittance_lut_segment(r, mu, t);
65 if should_raymarch {
66 let result = raymarch_atmosphere(world_pos, ray_dir_ws, t, max_samples, in.uv, false);
67 inscattering = result.inscattering;
68 transmittance = result.transmittance;
69 }
70 }
72 // exposure compensation
73 inscattering *= view.exposure;
75#ifdef DUAL_SOURCE_BLENDING
76 return RenderSkyOutput(vec4(inscattering, 0.0), vec4(transmittance, 1.0));
77#else
78 let mean_transmittance = (transmittance.r + transmittance.g + transmittance.b) / 3.0;
79 return RenderSkyOutput(vec4(inscattering, mean_transmittance));
80#endif
Contents