Skip to content
Merged
Prev Previous commit
Next Next commit
fix(render): composite fog and shafts over the Bruneton sky
Bruneton copies onto HDR before volumetric fog and god rays, so a
cleared pixel keeps both. The sky pixel test enables those passes.
A failed fog or shaft build prints the degraded mode and exits before
a median instead of claiming atmosphere_with_aravath_fog.

Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com>
  • Loading branch information
cursoragent and lazyxeon committed Oct 21, 2026
commit bee6f15fe4f750578fa57afcb67ae0a19f93f77a
65 changes: 54 additions & 11 deletions astraweave-render/src/bin/gpu_frame_budget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ fn main() -> anyhow::Result<()> {
add_heavy_terrain(&mut renderer)?;
renderer.set_particle_emitter(Some(emitter()))?;
// Cloud shadows stay at the renderer default (on). That is
// `CloudShadowPass`, not `VolumetricCloudsPass`. `--atmosphere` also
// turns on Aravath's fog and god rays so the median is that frame.
// Aerial then keeps those pixels instead of scattering them again.
// `CloudShadowPass`, not `VolumetricCloudsPass`. `--atmosphere` writes
// the Bruneton sky first, then Aravath's fog and god rays composite
// over it. A failed fog or shaft build is not that frame.
// GPU indirect culling is not the draw path on any adapter: each model
// still binds its own group 3, so one indirect buffer cannot select
// those groups. The CPU frustum remains the filter.
Expand All @@ -173,15 +173,14 @@ fn main() -> anyhow::Result<()> {
});
renderer.set_atmosphere_enabled(true);
}
let fog = renderer.volumetric_fog_enabled();
let shafts = renderer.god_rays_enabled();
let measure = gated_measure_label(atmosphere, fog, shafts);
println!("gated_atmosphere={}", if atmosphere { "on" } else { "off" });
println!(
"gated_measure={}",
if atmosphere {
"atmosphere_with_aravath_fog"
} else {
"baseline"
}
);
println!("gated_measure={measure}");
if atmosphere && (!fog || !shafts) {
anyhow::bail!("degraded atmosphere measurement: {measure}");
}
let gpu_cull = "cpu_fallback";

let device = renderer.device().clone();
Expand Down Expand Up @@ -804,6 +803,18 @@ fn renderer_limits(limits: &wgpu::Limits) -> [(&'static str, u64); 15] {
]
}

fn gated_measure_label(atmosphere: bool, fog: bool, shafts: bool) -> &'static str {
if !atmosphere {
return "baseline";
}
match (fog, shafts) {
(true, true) => "atmosphere_with_aravath_fog",
(true, false) => "atmosphere_without_shafts",
(false, true) => "atmosphere_without_fog",
(false, false) => "atmosphere_without_volumetrics",
}
}

/// `--atmosphere` alone draws the Aravath fog frame with Bruneton sky.
/// Every other enabled gated flag is rejected, including a second flag beside it.
/// `false` is off and does not bail.
Expand Down Expand Up @@ -984,3 +995,35 @@ fn median(values: &mut [f64]) -> f64 {
values[mid]
}
}

#[cfg(test)]
mod measure_label_tests {
use super::gated_measure_label;

#[test]
fn degraded_volumetrics_are_not_the_aravath_fog_frame() {
assert_eq!(gated_measure_label(false, false, false), "baseline");
assert_eq!(
gated_measure_label(true, true, true),
"atmosphere_with_aravath_fog"
);
assert_eq!(
gated_measure_label(true, false, true),
"atmosphere_without_fog"
);
assert_eq!(
gated_measure_label(true, true, false),
"atmosphere_without_shafts"
);
assert_eq!(
gated_measure_label(true, false, false),
"atmosphere_without_volumetrics"
);
for (fog, shafts) in [(false, true), (true, false), (false, false)] {
assert_ne!(
gated_measure_label(true, fog, shafts),
"atmosphere_with_aravath_fog"
);
}
}
}
124 changes: 72 additions & 52 deletions astraweave-render/src/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5642,13 +5642,15 @@ fn vs(input: VSIn) -> VSOut {
self.gated_velocity = Some((velocity, velocity_view));
}

/// Presentation passes that stay off unless a setter turned them on.
/// History and GI stay out of the simulation.
fn record_gated_presentation(
&mut self,
enc: &mut wgpu::CommandEncoder,
depth: &wgpu::TextureView,
) {
/// Bruneton sky and aerial, copied onto HDR before fog and god rays.
///
/// Cleared pixels become the Bruneton sky. Fog and shafts then composite
/// over that color, so a sky pixel keeps both. When fog or shafts are
/// already on, geometry is not scattered a second time.
fn record_bruneton(&mut self, enc: &mut wgpu::CommandEncoder, depth: &wgpu::TextureView) {
if !self.atmosphere_on {
return;
}
let gen = self.resource_generation;
let hdr = self.hdr_view.clone();
let device = self.device.clone();
Expand All @@ -5674,43 +5676,63 @@ fn vs(input: VSIn) -> VSOut {
};
let (near, far) = clip_planes(self.cached_proj);
let scatter_geometry = !self.volumetric_fog_enabled() && !self.god_rays_enabled();

if self.atmosphere_on {
if self.atmosphere.is_none() {
self.atmosphere = Some(crate::atmosphere::AtmospherePass::new(
&self.device,
width,
height,
crate::atmosphere::AtmosphereConfig::default(),
));
}
if let Some(pass) = self.atmosphere.as_mut() {
let (pass_w, pass_h) = pass.dimensions();
if pass_w != width || pass_h != height {
pass.resize(&device, width, height);
}
pass.prepare_frame(
&queue,
inv,
eye,
toward_sun,
-toward_sun,
near,
far,
scatter_geometry,
);
pass.execute(&device, enc, &hdr, depth, gen);
enc.copy_texture_to_texture(
pass.aerial_texture().as_image_copy(),
self.hdr_tex.as_image_copy(),
wgpu::Extent3d {
width,
height,
depth_or_array_layers: 1,
},
);
}
if self.atmosphere.is_none() {
self.atmosphere = Some(crate::atmosphere::AtmospherePass::new(
&self.device,
width,
height,
crate::atmosphere::AtmosphereConfig::default(),
));
}
let Some(pass) = self.atmosphere.as_mut() else {
return;
};
let (pass_w, pass_h) = pass.dimensions();
if pass_w != width || pass_h != height {
pass.resize(&device, width, height);
}
pass.prepare_frame(
&queue,
inv,
eye,
toward_sun,
-toward_sun,
near,
far,
scatter_geometry,
);
pass.execute(&device, enc, &hdr, depth, gen);
enc.copy_texture_to_texture(
pass.aerial_texture().as_image_copy(),
self.hdr_tex.as_image_copy(),
wgpu::Extent3d {
width,
height,
depth_or_array_layers: 1,
},
);
}

/// Presentation passes that stay off unless a setter turned them on.
/// History and GI stay out of the simulation.
fn record_gated_presentation(
&mut self,
enc: &mut wgpu::CommandEncoder,
depth: &wgpu::TextureView,
) {
let gen = self.resource_generation;
let hdr = self.hdr_view.clone();
let device = self.device.clone();
let queue = self.queue.clone();
let width = self.config.width.max(1);
let height = self.config.height.max(1);
let view_proj = self.cached_proj * self.cached_view;
let inv = view_proj.inverse();
let eye = glam::Vec3::new(
self.camera_ubo.camera_pos_pad[0],
self.camera_ubo.camera_pos_pad[1],
self.camera_ubo.camera_pos_pad[2],
);
if self.cloud_raymarch_on {
if self.cloud_raymarch.is_none() {
self.cloud_raymarch = Some(crate::volumetric_clouds::VolumetricCloudsPass::new(
Expand Down Expand Up @@ -6184,8 +6206,10 @@ fn vs(input: VSIn) -> VSOut {

/// Composite engine volumetric fog, then screen-space light shafts, into HDR.
///
/// Both passes no-op while their configs are disabled. Fog samples the
/// cascaded shadow map. Shafts are added before the tonemap blit.
/// Runs after Bruneton has copied its sky into HDR, so fog and shafts
/// apply over cleared pixels. Both passes no-op while their configs are
/// disabled. Fog samples the cascaded shadow map. Shafts are added before
/// the tonemap blit.
fn composite_atmosphere(&mut self, enc: &mut wgpu::CommandEncoder, depth: &wgpu::TextureView) {
let light = glam::Vec3::new(
self.camera_ubo.light_dir_pad[0],
Expand Down Expand Up @@ -8046,9 +8070,11 @@ fn vs(input: VSIn) -> VSOut {
self.close_timing_gap(enc);
let atmosphere_stamp = self.begin_named_stamp(enc, "atmosphere");
if let Some(external_depth) = depth_view {
self.record_bruneton(enc, external_depth);
self.composite_atmosphere(enc, external_depth);
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
} else {
let depth = self.depth.view.clone();
self.record_bruneton(enc, &depth);
self.composite_atmosphere(enc, &depth);
}
self.end_named_stamp(enc, atmosphere_stamp);
Expand Down Expand Up @@ -8109,13 +8135,7 @@ fn vs(input: VSIn) -> VSOut {
} else {
0.0
};
if self.atmosphere_on
|| self.cloud_raymarch_on
|| self.ssgi_on
|| self.taa_on
|| self.upscale_on
|| self.dof_on
{
if self.cloud_raymarch_on || self.ssgi_on || self.taa_on || self.upscale_on || self.dof_on {
let depth = depth_view
.cloned()
.unwrap_or_else(|| self.depth.view.clone());
Expand Down
39 changes: 39 additions & 0 deletions astraweave-render/tests/gated_passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,5 +275,44 @@ fn atmosphere_sky_differs_from_geometry_and_aerial_tints_distance() {
channel_distance(far, far_off) > 20,
"aerial perspective did not change the far quad: on {far:?} off {far_off:?} sky {sky:?}"
);
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved

// Aim the sun at the empty sky pixel so shafts have a source there.
renderer.set_light_direction_override(glam::Vec3::new(-0.9, 0.0, 0.4), 1.0);
renderer.update_view(&astraweave_camera::RenderView::new(
view,
&projection,
eye,
(target - eye).normalize(),
));
let sky_only = sample(&draw_and_read(&mut renderer, true), WIDTH, 60, 32);
renderer.set_volumetric_fog_config(
astraweave_render::volumetric_fog::VolumetricFogPass::gameplay_config(),
);
assert!(
renderer.volumetric_fog_enabled(),
"fog pipeline did not build"
);
let sky_fog = sample(&draw_and_read(&mut renderer, true), WIDTH, 60, 32);
renderer.set_god_ray_config(astraweave_render::GodRayConfig {
enabled: true,
half_res: true,
num_samples: 32,
exposure: 0.22,
..astraweave_render::GodRayConfig::default()
});
assert!(renderer.god_rays_enabled(), "shaft pipeline did not build");
let sky_both = sample(&draw_and_read(&mut renderer, true), WIDTH, 60, 32);
assert!(
channel_distance(sky_fog, sky_only) > 8,
"fog did not survive on the sky pixel: fog {sky_fog:?} sky {sky_only:?}"
);
assert!(
channel_distance(sky_both, sky_fog) > 5,
"shafts did not survive on the sky pixel: both {sky_both:?} fog {sky_fog:?}"
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
);
assert!(
channel_distance(sky_both, magenta) > 40,
"fogged sky {sky_both:?} is the debug magenta clear {magenta:?}"
);
});
}