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.
1import package::atmosphere::{
2 bindings::{view, settings},
3 bruneton_functions::sample_transmittance_lut_segment,
4 functions::{
5 sample_transmittance_lut,
6 sample_sky_view_lut, direction_world_to_atmosphere,
7 uv_to_ray_direction, uv_to_ndc, sample_aerial_view_lut,
8 sample_sun_radiance, ndc_to_camera_dist, raymarch_atmosphere,
9 get_view_position, max_atmosphere_distance
10 },
11};
13import bevy_core_pipeline::fullscreen_vertex_shader::FullscreenVertexOutput;
15@if(DUAL_SOURCE_BLENDING)
16enable dual_source_blending;
18@if(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;
23struct RenderSkyOutput {
24 @if(DUAL_SOURCE_BLENDING)
25 @location(0) @blend_src(0) inscattering: vec4<f32>,
26 @if(DUAL_SOURCE_BLENDING)
27 @location(0) @blend_src(1) transmittance: vec4<f32>,
28 @else
29 @location(0) inscattering: vec4<f32>,
32@fragment
33fn main(in: FullscreenVertexOutput) -> RenderSkyOutput {
34 let depth = textureLoad(depth_texture, vec2<i32>(in.position.xy), 0);
36 let ray_dir_ws = uv_to_ray_direction(in.uv);
37 let world_pos = get_view_position();
38 let r = length(world_pos);
39 let up = normalize(world_pos);
40 let mu = dot(ray_dir_ws, up);
41 let max_samples = settings.sky_max_samples;
42 let should_raymarch = settings.rendering_method == 1u;
44 var transmittance: vec3<f32>;
45 var inscattering: vec3<f32>;
47 let sun_radiance = sample_sun_radiance(ray_dir_ws);
49 if depth == 0.0 {
50 let ray_dir_as = direction_world_to_atmosphere(ray_dir_ws);
51 transmittance = sample_transmittance_lut(r, mu);
52 inscattering = sample_sky_view_lut(r, ray_dir_as);
53 if should_raymarch {
54 let t_max = max_atmosphere_distance(r, mu);
55 let result = raymarch_atmosphere(world_pos, ray_dir_ws, t_max, max_samples, in.uv, true);
56 inscattering = result.inscattering;
57 transmittance = result.transmittance;
58 }
59 inscattering += sun_radiance * transmittance;
60 } else {
61 let t = ndc_to_camera_dist(vec3(uv_to_ndc(in.uv), depth));
62 inscattering = sample_aerial_view_lut(in.uv, t);
63 transmittance = sample_transmittance_lut_segment(r, mu, t);
64 if should_raymarch {
65 let result = raymarch_atmosphere(world_pos, ray_dir_ws, t, max_samples, in.uv, false);
66 inscattering = result.inscattering;
67 transmittance = result.transmittance;
68 }
69 }
71 // exposure compensation
72 inscattering *= view.exposure;
74 @if(DUAL_SOURCE_BLENDING)
75 return RenderSkyOutput(vec4(inscattering, 0.0), vec4(transmittance, 1.0));
76 @if(!DUAL_SOURCE_BLENDING)
77 let mean_transmittance = (transmittance.r + transmittance.g + transmittance.b) / 3.0;
78 @if(!DUAL_SOURCE_BLENDING)
79 return RenderSkyOutput(vec4(inscattering, mean_transmittance));
Contents