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