diff --git a/CHANGELOG.md b/CHANGELOG.md index 88e2c834..74bede08 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -66,11 +66,16 @@ git push origin v0.1.0 Changes that land in the main branch after phases C–E (`0.4.0`) go here. ### Added +- An anti-aliasing pass in the camera's picture (the manual's "The picture"): `picture.anti_aliasing: Some(Fxaa)` or + `Some(Smaa)` in the `camera` content puts Bevy's `Fxaa` (its defaults) or `Smaa` (`High`) on the world cameras, for a + camera SSAO took MSAA from; taking it out gives the camera back its own. `AntiAliasing`. Off by default. The view + model's camera over an HDR world camera keeps Bevy's 4x MSAA of its own (it has its own texture there). - Ambient occlusion in the camera's picture (the manual's "The picture"): `picture.ssao: Some((quality, radius, thickness))` in the `camera` content gives the world cameras Bevy's `ScreenSpaceAmbientOcclusion` (`SsaoTuning`, `SsaoQuality::{Low, Medium, High, Ultra}`), with the depth and normal prepasses it needs and `Msaa::Off` while it is on (Bevy draws no SSAO under MSAA); taking it out gives the camera back its own SSAO, MSAA and prepasses. The view model's camera follows the - world camera's MSAA and has no SSAO. Off by default. + world camera's MSAA (its own 4x over an HDR world camera, whose texture it does not share) and has no SSAO. Off by + default. - A shadow budget in views (the manual's "Lights and colour grading (F13)"): `graphics.shadow_views` (0 to 384, default 0) counts the shadow budget in shadow views, a point light 6 and a spot 1, the nearest first, and replaces `graphics.shadow_lights` while above 0. The `lights` query says the budget in views, how many are taken and, for a light @@ -403,6 +408,13 @@ Changes that land in the main branch after phases C–E (`0.4.0`) go here. and the timing `field_timing` (`#[ignore]`) in `physics/world.rs`. ### Fixed +- The first-person arms under an HDR world camera (a `picture.bloom`): the view model's camera drew in HDR into the world + camera's texture after its tone mapping and grade, with neither, so a grade's exposure brightened the world and left + the arms that many stops darker (1.7 in a game's tunnels). It now draws without HDR whatever the world camera does, tone + mapped and graded (the exposure) in its materials' shaders as over a camera without HDR; over an HDR one it draws into a + texture of its own, cleared to nothing, laid over the world's finished picture with premultiplied alpha (Bevy's + `CameraOutputMode`). The arms look the same with a bloom and without; the bloom and the rest of an HDR grade are the + world's alone. Tested on a GPU (`first_person::the_arms_are_drawn_alike_over_a_world_camera_with_hdr_and_without`). - Colour grading said every field of a grade is drawn; Bevy draws only a grade's `exposure` on a camera that does not draw in HDR (it grades in each material's shader there), and the rest (`temperature`, `tint`, `hue_deg`, `saturation`, `contrast`, `lift`, `gamma`, `gain`) only in HDR, in its tone mapping pass. A grade tuned without HDR therefore changed diff --git a/crates/sandbox/tests/sandbox/first_person.rs b/crates/sandbox/tests/sandbox/first_person.rs index e89c351c..e42a0b3d 100644 --- a/crates/sandbox/tests/sandbox/first_person.rs +++ b/crates/sandbox/tests/sandbox/first_person.rs @@ -356,7 +356,8 @@ fn ssao_from_the_camera_content_draws_through_the_first_person_cameras_and_goes_ let occluded = drawn(&mut app, &picture); let world = app.world(); assert!(world.get::(camera).is_some() && world.get::(camera).is_some()); - assert_eq!((msaa(&app, camera), msaa(&app, view_model)), (Some(Msaa::Off), Some(Msaa::Off)), "both cameras without MSAA"); + // The sandbox's camera draws in HDR (its bloom): the arms are drawn into a texture of their own, with MSAA of their own. + assert_eq!((msaa(&app, camera), msaa(&app, view_model)), (Some(Msaa::Off), Some(Msaa::Sample4)), "the world camera without MSAA, the arms with"); assert!(world.get::(view_model).is_none(), "the arms have no SSAO of their own"); let luma = |[r, g, b]: [f64; 3]| 0.2126 * r + 0.7152 * g + 0.0722 * b; let (w, h) = (plain.width(), plain.height()); @@ -379,7 +380,7 @@ fn ssao_from_the_camera_content_draws_through_the_first_person_cameras_and_goes_ settle(&mut app, 30); let back = drawn(&mut app, &picture); assert!(app.world().get::(camera).is_none()); - assert_eq!((msaa(&app, camera), msaa(&app, view_model)), (own, own), "the MSAA the camera had, on both"); + assert_eq!((msaa(&app, camera), msaa(&app, view_model)), (own, Some(Msaa::Sample4)), "the MSAA the camera had, and the arms' own"); assert!(mean_difference(&plain, &back) < 1.0, "the plain picture again: {:.3}", mean_difference(&plain, &back)); } @@ -439,3 +440,79 @@ fn a_grade_draws_its_exposure_alone_without_hdr_and_all_of_it_in_hdr() { assert_eq!(said_hdr.as_deref(), Some(" drawn: all of it (the camera draws in HDR)")); assert!(alike(brighter_ldr, brighter_hdr), "and an exposure is drawn alike in both: {brighter_ldr:.1?} and {brighter_hdr:.1?}"); } + +/// The arms are drawn alike over a world camera with HDR (a bloom) and without: the view model's camera draws without +/// HDR either way, tone mapped and graded (its exposure) in its shaders, into a texture of its own laid over the world's +/// picture. (Until it did, an HDR world camera drew the arms after its tone mapping and grade, with neither: a grade's +/// exposure of 1.7 stops brightened the world and left the arms 1.7 stops darker.) +#[test] +#[ignore = "needs a GPU, or a software one (WGPU_FORCE_FALLBACK_ADAPTER=1): cargo test -p sandbox --test sandbox -- --ignored first_person"] +fn the_arms_are_drawn_alike_over_a_world_camera_with_hdr_and_without() { + use shards::motion::camera::{BloomComposite, BloomTuning, Grading}; + + use crate::offscreen::block; + + let mut app = offscreen_app(); + let picture = app.world().resource::().image.clone(); + step(&mut app, 30); + look_down_through_the_eye(&mut app); + settle(&mut app, 200); + let brighter = Grading { exposure: 1.7, ..default() }; + let bloom = Some(BloomTuning { intensity: 0.1, threshold: 1.0, composite: BloomComposite::Additive, ..default() }); + // The picture with this bloom and this grade, and with the view model or without. + let take = |app: &mut App, name: &str, bloom: &Option, arms: bool| { + let mut tuning = app.world_mut().resource_mut::(); + (tuning.picture.bloom, tuning.picture.grading) = (bloom.clone(), Some(brighter.clone())); + tuning.first_person.view_model = arms.then(|| "arms".into()); + settle(app, 30); + shot_to(app, name); + capture_stable(app, &picture) + }; + let ldr = take(&mut app, "arms-ldr", &None, true); + let hdr = take(&mut app, "arms-hdr", &bloom, true); + let hdr_bare = take(&mut app, "arms-hdr-no-view-model", &bloom, false); + let (arms_ldr, arms_hdr) = (block(&ldr, 230, 440, 870, 280), block(&hdr, 230, 440, 870, 280)); + let (world_ldr, world_hdr) = (block(&ldr, 300, 200, 980, 200), block(&hdr, 300, 200, 980, 200)); + eprintln!("the arms' mean colour: {arms_ldr:.1?} without HDR, {arms_hdr:.1?} in HDR; the world above them {world_ldr:.1?} and {world_hdr:.1?}"); + let alike = |a: [f64; 3], b: [f64; 3], by: f64| (0..3).all(|c| (a[c] - b[c]).abs() < by); + assert!(alike(arms_ldr, arms_hdr, 3.0), "the arms are drawn alike: {arms_ldr:.1?} and {arms_hdr:.1?}"); + assert!(alike(world_ldr, world_hdr, 1.5), "and the world above them: {world_ldr:.1?} and {world_hdr:.1?}"); + let arms = changed(&hdr, &hdr_bare, (230, 440, 870, 280)); + let world = changed(&hdr, &hdr_bare, (300, 200, 980, 200)); + assert!(arms > 5000 && world < 50, "in HDR the arms are laid over the world, which shows round them: {arms} pixels differ below, {world} above"); +} + +/// The content's anti-aliasing pass draws over SSAO, which took the camera's MSAA: the edges change, the picture's +/// light does not, and taking it out gives the picture back. +#[test] +#[ignore = "needs a GPU, or a software one (WGPU_FORCE_FALLBACK_ADAPTER=1): cargo test -p sandbox --test sandbox -- --ignored first_person"] +fn the_contents_anti_aliasing_smooths_the_edges_of_a_picture_without_msaa() { + use shards::motion::camera::{AntiAliasing, SsaoQuality, SsaoTuning}; + + use crate::offscreen::block; + + let mut app = offscreen_app(); + let picture = app.world().resource::().image.clone(); + step(&mut app, 30); + look_down_through_the_eye(&mut app); + settle(&mut app, 200); + let take = |app: &mut App, name: &str, aa: Option| { + let mut tuning = app.world_mut().resource_mut::(); + tuning.picture.ssao = Some(SsaoTuning { quality: SsaoQuality::Medium, radius: 0.5, ..default() }); + tuning.picture.anti_aliasing = aa; + settle(app, 30); + shot_to(app, name); + capture_stable(app, &picture) + }; + let bare = take(&mut app, "ssao-no-aa", None); + let smaa = take(&mut app, "ssao-smaa", Some(AntiAliasing::Smaa)); + let fxaa = take(&mut app, "ssao-fxaa", Some(AntiAliasing::Fxaa)); + let again = take(&mut app, "ssao-no-aa-again", None); + let (w, h) = (bare.width(), bare.height()); + let (by_smaa, by_fxaa, back) = (changed(&bare, &smaa, (0, 0, w, h)), changed(&bare, &fxaa, (0, 0, w, h)), changed(&bare, &again, (0, 0, w, h))); + let (light, light_smaa) = (block(&bare, 0, 0, w, h), block(&smaa, 0, 0, w, h)); + eprintln!("anti-aliasing over SSAO: SMAA changed {by_smaa} pixels, FXAA {by_fxaa}, none again {back}; mean {light:.1?} and {light_smaa:.1?}"); + assert!(by_smaa > 100 && by_fxaa > 100, "each pass changes the edges: {by_smaa} and {by_fxaa} pixels"); + assert!((0..3).all(|c| (light[c] - light_smaa[c]).abs() < 1.0), "and not the light: {light:.1?} and {light_smaa:.1?}"); + assert!(back < 50, "taken out, the picture is as it was: {back} pixels differ"); +} diff --git a/crates/shards/tests/action_render/view_model.rs b/crates/shards/tests/action_render/view_model.rs index 6c5098cc..bc43652b 100644 --- a/crates/shards/tests/action_render/view_model.rs +++ b/crates/shards/tests/action_render/view_model.rs @@ -240,11 +240,33 @@ fn a_world_camera_that_grades_in_its_shaders_hands_its_grade_to_the_view_model_c app.update(); assert_eq!(grade_of(&app, vm), ColorGrading::default(), "and ungraded when the world is"); - // An HDR camera grades the finished picture, which the second camera draws over (with no tone mapping of its own, so no grade). - app.world_mut().entity_mut(camera).insert((Hdr, grade)); + // Over an HDR camera the second one still draws without HDR, graded and tone mapped in its shaders as before, into a + // texture of its own (cleared to nothing) that is laid over the world's finished picture. + use shards::bevy::camera::{CameraOutputMode, ClearColorConfig}; + use shards::bevy::render::view::Tonemapping; + app.world_mut().entity_mut(camera).insert((Hdr, grade.clone(), Tonemapping::TonyMcMapface)); app.update(); app.update(); - assert_eq!(grade_of(&app, vm), ColorGrading::default(), "under HDR the view model is drawn over the graded picture, ungraded"); + assert_eq!(grade_of(&app, vm), grade, "under HDR the view model is graded like the world still"); + let world = app.world(); + assert!(world.get::(vm).is_none(), "and draws without HDR"); + assert_eq!(world.get::(vm), Some(&Tonemapping::TonyMcMapface), "tone mapped as the world is, in its shaders"); + use shards::bevy::render::view::Msaa; + assert_eq!(world.get::(vm), Some(&Msaa::Sample4), "with MSAA of its own"); + let cam = world.get::(vm).unwrap(); + assert!(matches!(cam.clear_color, ClearColorConfig::Custom(c) if c == Color::NONE), "its own texture starts empty: {:?}", cam.clear_color); + assert!( + matches!(cam.output_mode, CameraOutputMode::Write { blend_state: Some(_), clear_color: ClearColorConfig::None }), + "and is laid over the world's picture: {:?}", + cam.output_mode + ); + + // Without HDR again: the shared texture, loaded as the world drew it. + app.world_mut().entity_mut(camera).remove::(); + app.update(); + app.update(); + let cam = app.world().get::(vm).unwrap(); + assert!(matches!(cam.clear_color, ClearColorConfig::None) && matches!(cam.output_mode, CameraOutputMode::Write { blend_state: None, .. })); } #[test] diff --git a/crates/shards_action/src/render/view_model.rs b/crates/shards_action/src/render/view_model.rs index be10b7d5..f902aa09 100644 --- a/crates/shards_action/src/render/view_model.rs +++ b/crates/shards_action/src/render/view_model.rs @@ -5,8 +5,15 @@ //! (the shake, the bob and the lean included), one `order` above it, with the `view_model` definition's //! own field of view and near plane. It draws [`VIEW_MODEL_LAYER`] alone and loads what the world camera //! drew, clearing only the depth (`Camera3d`'s default), so the model is drawn over the world and never -//! inside a wall. It mirrors the world camera's HDR, anti-aliasing and tone mapping, so that the two +//! inside a wall. It mirrors the world camera's anti-aliasing, tone mapping and grade, so that the two //! share one main texture. The UI goes to the camera that draws last, so the HUD is over the arms. +//! - **Over an HDR world camera** (a bloom) it still draws without HDR, as it does over one without: its +//! materials tone map in their shaders and take the world camera's grade (its exposure; [`ColorGrading`] +//! is drawn in full only in HDR), so the arms are drawn as they were before the world went HDR. The two +//! formats cannot share a texture: the view model draws into its own, cleared to nothing, and that is laid +//! over the world's finished picture (premultiplied alpha, [`CameraOutputMode`]), with Bevy's 4x MSAA of +//! its own whatever the world camera has (SSAO turns the world's off). An HDR view model drawn into the +//! world's texture would come after the world's tone mapping and grade, and be drawn with neither. //! - **The rig** ([`ViewModelRig`]) is a child of the camera: an [`Animated`] root that [`ShowsBody`] of //! the looked-through body, so the bridge animates it from that body's actions, with a [`GltfModel`] below. //! Which definition it is follows the body's moveset each frame, so a weapon switch swaps it; an edit of @@ -15,9 +22,10 @@ //! prop the bridge mounts), cast no shadow and are never culled by their (possibly stale) bounds. use bevy::camera::visibility::{NoFrustumCulling, RenderLayers, VisibilitySystems}; -use bevy::camera::{Camera, Camera3d, ClearColorConfig, Hdr, PerspectiveProjection, Projection}; +use bevy::camera::{Camera, Camera3d, CameraOutputMode, ClearColorConfig, Hdr, PerspectiveProjection, Projection}; use bevy::light::NotShadowCaster; use bevy::prelude::*; +use bevy::render::render_resource::BlendState; use bevy::render::view::{ColorGrading, Msaa, Tonemapping}; use shards_content::ContentDb; use shards_core::LocalPlayer; @@ -75,6 +83,15 @@ fn views_exist(first: Query<(), With>, views: Query<(), With< !first.is_empty() || !views.is_empty() } +/// Whether two clear colours are the same (Bevy's `ClearColorConfig` has no `PartialEq`). +fn same_clear(a: &ClearColorConfig, b: &ClearColorConfig) -> bool { + match (a, b) { + (ClearColorConfig::Default, ClearColorConfig::Default) | (ClearColorConfig::None, ClearColorConfig::None) => true, + (ClearColorConfig::Custom(x), ClearColorConfig::Custom(y)) => x == y, + _ => false, + } +} + /// The view model a body shows now: its moveset's, else the camera content's default. `None`: no /// view model (the body has none to show, or the definition is missing). pub fn view_model_of<'a>(db: &'a ContentDb, tuning: &'a CameraTuning, moveset: Option<&str>) -> Option<(&'a str, &'a ViewModelDef)> { @@ -126,11 +143,25 @@ fn sync_view_model( let (fov, near) = (def.fov_deg.to_radians(), def.near); let projection = Projection::Perspective(PerspectiveProjection { fov, near, ..default() }); let right_projection = |p: &Projection| matches!(p, Projection::Perspective(p) if (p.fov - fov).abs() < 1e-6 && (p.near - near).abs() < 1e-9); - // An HDR world camera has tone mapped what it drew; the view model is drawn over that as it is. - let tone = if hdr { Some(Tonemapping::None) } else { tonemapping.copied() }; - // A camera that does not draw in HDR tone maps (and grades, F13) in each material's shader, so the view model's own - // camera wants the world camera's grade to match; an HDR one grades the finished picture, which this camera draws over. - let grading = if hdr { None } else { world_grading.cloned() }; + // The view model never draws in HDR: it tone maps (and grades, F13) in its materials' shaders, with the world + // camera's tone mapping and grade, so the arms are drawn alike over a world camera with HDR and without. + let (tone, grading) = (tonemapping.copied(), world_grading.cloned()); + // Sharing a texture, the two must have the same MSAA. Over an HDR camera the view model has a texture of its own + // and keeps Bevy's 4x MSAA for the arms, though the world camera may have none (SSAO turns it off). + let msaa = if hdr { Some(&Msaa::Sample4) } else { msaa }; + // Over a world camera without HDR it draws into the same texture, over what the world drew. Over an HDR one (whose + // texture is of another format) it draws into its own, cleared to nothing, and lays that over the world's picture. + let (clear, output) = if hdr { + let blend = CameraOutputMode::Write { blend_state: Some(BlendState::PREMULTIPLIED_ALPHA_BLENDING), clear_color: ClearColorConfig::None }; + (ClearColorConfig::Custom(Color::NONE), blend) + } else { + (ClearColorConfig::None, CameraOutputMode::default()) + }; + let same_output = |a: &CameraOutputMode| match (a, &output) { + (CameraOutputMode::Write { blend_state: x, clear_color: c }, CameraOutputMode::Write { blend_state: y, clear_color: d }) => x == y && same_clear(c, d), + (CameraOutputMode::Skip, CameraOutputMode::Skip) => true, + _ => false, + }; let camera = match existing { Some((camera, _, mut cam, mut proj, has_hdr, has_msaa, has_tone, has_grading)) => { let active = world_camera.is_active && !in_shot; @@ -138,16 +169,16 @@ fn sync_view_model( cam.order = world_camera.order + 1; cam.is_active = active; } + if !same_clear(&cam.clear_color, &clear) || !same_output(&cam.output_mode) { + cam.clear_color = clear; + cam.output_mode = output; + } if !right_projection(&proj) { *proj = projection; } let mut e = commands.entity(camera); - if has_hdr != hdr { - if hdr { - e.insert(Hdr); - } else { - e.remove::(); - } + if has_hdr { + e.remove::(); } if has_msaa.copied() != msaa.copied() && let Some(msaa) = msaa @@ -172,15 +203,12 @@ fn sync_view_model( Name::new("view model camera"), ViewModelCamera, Camera3d::default(), - Camera { order: world_camera.order + 1, is_active: world_camera.is_active && !in_shot, clear_color: ClearColorConfig::None, ..default() }, + Camera { order: world_camera.order + 1, is_active: world_camera.is_active && !in_shot, clear_color: clear, output_mode: output, ..default() }, projection, RenderLayers::layer(VIEW_MODEL_LAYER), Transform::IDENTITY, ChildOf(world), )); - if hdr { - e.insert(Hdr); - } if let Some(msaa) = msaa { e.insert(*msaa); } diff --git a/crates/shards_motion/Cargo.toml b/crates/shards_motion/Cargo.toml index 902a2a24..ba94126d 100644 --- a/crates/shards_motion/Cargo.toml +++ b/crates/shards_motion/Cargo.toml @@ -10,7 +10,7 @@ license.workspace = true [features] # The third-person camera systems and the collider overlay (they need a window to be seen; # the pure camera math and the data types are always built). -render = ["ai_core/render", "bevy/bevy_post_process", "bevy/bevy_light", "bevy/bevy_pbr", "bevy/bevy_core_pipeline"] +render = ["ai_core/render", "bevy/bevy_post_process", "bevy/bevy_light", "bevy/bevy_pbr", "bevy/bevy_core_pipeline", "bevy/bevy_anti_alias"] # Real gamepads through gilrs (needs libudev). Without it `Gamepad` entities still work, # a game or a test just has to spawn them. gamepad = ["bevy/bevy_gilrs"] diff --git a/crates/shards_motion/src/camera/mod.rs b/crates/shards_motion/src/camera/mod.rs index 4de451bc..1ae4e8df 100644 --- a/crates/shards_motion/src/camera/mod.rs +++ b/crates/shards_motion/src/camera/mod.rs @@ -53,7 +53,7 @@ pub use first_person::{ pub use grading::{grade_drawn_in_full, picture_clock, Grading, GradingBlend, GradingDef, GradingVolume}; #[cfg(feature = "render")] pub use grading::GradingSet; -pub use picture::{BloomComposite, BloomTuning, PictureTuning, SsaoQuality, SsaoTuning, ToneMapping}; +pub use picture::{AntiAliasing, BloomComposite, BloomTuning, PictureTuning, SsaoQuality, SsaoTuning, ToneMapping}; pub use tuning::{ArmTuning, AutoCentreTuning, CameraOffsets, CameraTuning, FitTuning, FlickTuning, FramingTuning, TraumaTuning}; pub use shot::{ShotDef, ShotEnded, ShotKey, ShotPoint, ShotStarted, Shots}; diff --git a/crates/shards_motion/src/camera/picture.rs b/crates/shards_motion/src/camera/picture.rs index 127e163e..bb9f1198 100644 --- a/crates/shards_motion/src/camera/picture.rs +++ b/crates/shards_motion/src/camera/picture.rs @@ -15,8 +15,13 @@ //! and a camera without MSAA: while the content gives a camera SSAO, the camera gets the prepasses it //! lacks (again, if another module takes one away) and `Msaa::Off`, and taking SSAO out of the content //! gives it back its own MSAA and drops the prepasses it did not have. The view model's camera -//! (`shards_action`) copies the world camera's MSAA, so the two still share one main texture; it gets no -//! SSAO of its own (the arms are drawn over the occluded world). +//! (`shards_action`) copies the world camera's MSAA while the two share one main texture (the world camera +//! not in HDR), and keeps its own 4x MSAA over an HDR one; it gets no SSAO of its own (the arms are drawn +//! over the occluded world). +//! +//! An anti-aliasing pass ([`AntiAliasing`]: Bevy's `Fxaa` or `Smaa`) smooths the edges in the finished +//! picture, as MSAA does while the picture is drawn: what a camera that SSAO took MSAA from wants. Taking it +//! out of the content gives the camera back its own (or none). //! //! Only the picture changes: the `camera` kind is not simulation content, and nothing here is in a //! snapshot or a replay. @@ -132,6 +137,16 @@ impl Default for SsaoTuning { } } +/// An anti-aliasing pass over the finished picture, for a camera without MSAA (SSAO turns it off): Bevy's FXAA (cheap, +/// a little soft) or SMAA (its `High` preset: sharper, dearer). Both run after the tone mapping and leave the UI alone. +#[derive(Reflect, Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq)] +pub enum AntiAliasing { + /// Bevy's `Fxaa` with its defaults. + Fxaa, + /// Bevy's `Smaa` with its `High` preset. + Smaa, +} + /// The picture a camera draws: each part left out leaves the camera as the game made it. /// /// ```ron @@ -158,6 +173,10 @@ pub struct PictureTuning { /// prepass. #[serde(skip_serializing_if = "Option::is_none")] pub ssao: Option, + /// An anti-aliasing pass over the picture ([`AntiAliasing`]); `None` keeps the camera's own (none, unless the game + /// gave it one). With `ssao`, which turns MSAA off, the edges want one. + #[serde(skip_serializing_if = "Option::is_none")] + pub anti_aliasing: Option, } impl PictureTuning { @@ -205,6 +224,8 @@ pub(super) use render::apply_picture; #[cfg(feature = "render")] mod render { + use bevy::anti_alias::fxaa::Fxaa; + use bevy::anti_alias::smaa::{Smaa, SmaaPreset}; use bevy::camera::Hdr; use bevy::core_pipeline::prepass::{DepthPrepass, NormalPrepass}; use bevy::pbr::{ScreenSpaceAmbientOcclusion, ScreenSpaceAmbientOcclusionQualityLevel}; @@ -212,7 +233,7 @@ mod render { use bevy::prelude::*; use bevy::render::view::{Msaa, Tonemapping}; - use super::{BloomComposite, BloomTuning, SsaoQuality, SsaoTuning, ToneMapping}; + use super::{AntiAliasing, BloomComposite, BloomTuning, SsaoQuality, SsaoTuning, ToneMapping}; use crate::camera::{CameraTuning, FirstPersonCamera, ThirdPersonCamera}; impl ToneMapping { @@ -276,6 +297,8 @@ mod render { hdr_added: bool, /// The camera's own SSAO (or none) and MSAA (or none) while the content's SSAO is in force. ssao: Option, + /// The camera's own FXAA and SMAA (or none) while the content's anti-aliasing is in force. + anti_aliasing: Option<(Option, Option)>, } /// What a camera had before the content gave it SSAO. @@ -298,7 +321,15 @@ mod render { type Cameras<'w, 's> = Query< 'w, 's, - (Entity, Option<&'static Tonemapping>, Option<&'static Bloom>, Has, Option<&'static PictureSet>, SsaoNeeds), + ( + Entity, + Option<&'static Tonemapping>, + Option<&'static Bloom>, + Has, + Option<&'static PictureSet>, + SsaoNeeds, + (Option<&'static Fxaa>, Option<&'static Smaa>), + ), (With, Or<(With, With)>), >; @@ -328,7 +359,7 @@ mod render { return; } let picture = &tuning.picture; - for (entity, tone_mapping, bloom, hdr, set, (ssao, msaa, depth, normal)) in &cameras { + for (entity, tone_mapping, bloom, hdr, set, (ssao, msaa, depth, normal), (fxaa, smaa)) in &cameras { let mut set = set.cloned().unwrap_or_default(); let mut camera = commands.entity(entity); match (picture.tone_mapping, set.tone_mapping) { @@ -415,7 +446,41 @@ mod render { } (None, None) => {} } - if set.tone_mapping.is_none() && set.bloom.is_none() && set.ssao.is_none() { + match (picture.anti_aliasing, set.anti_aliasing.take()) { + (Some(want), own) => { + set.anti_aliasing = Some(own.unwrap_or_else(|| (fxaa.cloned(), smaa.cloned()))); + match want { + AntiAliasing::Fxaa => { + if smaa.is_some() { + camera.remove::(); + } + if fxaa.is_none_or(|f| !f.enabled) { + camera.insert(Fxaa::default()); + } + } + AntiAliasing::Smaa => { + if fxaa.is_some() { + camera.remove::(); + } + if smaa.is_none_or(|s| s.preset != SmaaPreset::High) { + camera.insert(Smaa { preset: SmaaPreset::High }); + } + } + } + } + (None, Some((own_fxaa, own_smaa))) => { + match own_fxaa { + Some(theirs) => camera.insert(theirs), + None => camera.remove::(), + }; + match own_smaa { + Some(theirs) => camera.insert(theirs), + None => camera.remove::(), + }; + } + (None, None) => {} + } + if set.tone_mapping.is_none() && set.bloom.is_none() && set.ssao.is_none() && set.anti_aliasing.is_none() { camera.remove::(); } else { camera.insert(set); @@ -527,6 +592,21 @@ mod render { assert!(world.get::(camera).is_none(), "no MSAA component before, none after"); } + #[test] + fn the_contents_anti_aliasing_goes_on_and_gives_the_camera_back_its_own() { + let (mut app, camera) = app(); + app.world_mut().entity_mut(camera).insert(Fxaa { enabled: true, ..default() }); + set(&mut app, PictureTuning { anti_aliasing: Some(AntiAliasing::Smaa), ..default() }); + let world = app.world(); + assert!(world.get::(camera).is_some_and(|s| s.preset == SmaaPreset::High) && world.get::(camera).is_none(), "SMAA in, the camera's FXAA out"); + set(&mut app, PictureTuning { anti_aliasing: Some(AntiAliasing::Fxaa), ..default() }); + assert!(app.world().get::(camera).is_some() && app.world().get::(camera).is_none(), "FXAA in its place"); + set(&mut app, PictureTuning::default()); + let world = app.world(); + assert!(world.get::(camera).is_some_and(|f| f.enabled) && world.get::(camera).is_none(), "the camera's own FXAA again"); + assert!(world.get::(camera).is_none(), "and nothing kept"); + } + #[test] fn a_camera_that_appears_later_gets_the_picture_too() { let (mut app, _) = app(); diff --git a/docs/manual.md b/docs/manual.md index 50ec4c0c..74f4bdcc 100644 --- a/docs/manual.md +++ b/docs/manual.md @@ -1114,6 +1114,7 @@ For the AI: `observe` shows `slowed x0.60, rooted, capped 3.0m/s, no sprint, spr | `picture.bloom.composite` | `EnergyConserving` | `EnergyConserving`: the glow takes its share of the light from the picture (Bevy's natural bloom); `Additive`: it is added on top | | `picture.ssao` | `None`: the camera's own (none) | screen-space ambient occlusion: the light that comes from no one direction (an ambient light, an irradiance volume, a reflection probe) darkens in creases and where things meet. It turns the camera's MSAA off while it is set and adds a depth and a normal prepass (the picture, below) | | `picture.ssao.quality` / `radius` / `thickness` | `High` / `0.7285` / `0.25` | Bevy's `ScreenSpaceAmbientOcclusion`: `Low` (4 samples a pixel), `Medium` (8), `High` (18) or `Ultra` (54); how far round a pixel occluders are looked for (m, above 0); how thick everything on screen is taken to be (m, above 0) | +| `picture.anti_aliasing` | `None`: the camera's own (none) | an anti-aliasing pass over the finished picture: `Fxaa` (Bevy's FXAA, cheap and a little soft) or `Smaa` (Bevy's SMAA at its `High` preset, sharper and dearer); for a camera without MSAA, which `ssao` turns off (the picture, below) | | `picture.grading` | `None`: the camera's own | a colour grade of the whole picture: `exposure` (stops), `temperature` and `tint` (white balance, `-1` to `1`), `hue_deg`, `saturation`, `contrast`, `lift`, `gamma` and `gain` (the neutral values: 0, 0, 0, 0, 1, 1, 0, 1, 1); Bevy's `ColorGrading` with the same values for shadows, midtones and highlights. Bevy grades just before tone mapping, so it shows nothing under `tone_mapping: None`, and **a camera that does not draw in HDR shows only the `exposure`**: the rest is drawn once a `bloom` (or the game's `Hdr`) puts the camera in HDR ("Lights and colour grading (F13)", "Colour grading"). A grading volume blends the picture away from it and back (the picture, below; "Lights and colour grading (F13)") | | `mode` | `ThirdPerson` | the camera the game plays through: `FirstPerson` puts a `FirstPersonCamera` on every `ThirdPersonCamera` entity (F1b, "The first-person camera and the view model") | | `first_person.*` | see the table in "The first-person camera and the view model (F1b)" | the first-person camera's own numbers: the ease on steps, the landing dip, the bob, the lean, the default view model; read by `FirstPersonCamera` only | @@ -1178,12 +1179,12 @@ down the framed arm may go (`(0.0, 0.7)` keeps it level with the head next to a lock pick and the flick read the camera's `Transform`, so with a tilt they measure from what the player sees. The far plane (Bevy's default 1000 m) did not need a number. The sandbox's `combat/camera.camera.ron` turns the fit on for its colossus. -**The picture (`picture`).** The camera content can also say how the picture is drawn: its tone mapping, its bloom, its colour grade and its ambient occlusion (`shards::motion::camera::{PictureTuning, ToneMapping, BloomTuning, BloomComposite, Grading, SsaoTuning, SsaoQuality}`). All four are left out by default, and then every camera keeps what the game spawned it with, so a game without a `picture` sees no change. They apply to every 3D camera with `ThirdPersonCamera` or `FirstPersonCamera`, a camera spawned later included. A bloom makes the camera draw in HDR (Bevy's `Bloom` requires `Hdr`): the materials' colours are no longer stopped at full, and tone mapping moves from each material's shader to one pass over the whole picture, so light brighter than white (a lamp, an effect with an `intensity` above 1, see "Effects and decals") keeps its brightness until the tone mapping and the bloom see it. Taking `bloom` out of the content (or the whole definition) gives the camera back its own bloom, or none, and leaves HDR off again if the content turned it on. The same holds for `tone_mapping`. A game that sets its own `Bloom`, `Hdr` or `Tonemapping` on the camera keeps them while the content says nothing. The picture changes nothing else: the `camera` kind is not simulation content, so no replay changes. With HDR on, everything is tone mapped once, in the post pass, particles included (the particles' shader has no tone mapping of its own, so without HDR their colours reach the screen as written). +**The picture (`picture`).** The camera content can also say how the picture is drawn: its tone mapping, its bloom, its colour grade, its ambient occlusion and an anti-aliasing pass (`shards::motion::camera::{PictureTuning, ToneMapping, BloomTuning, BloomComposite, Grading, SsaoTuning, SsaoQuality, AntiAliasing}`). All five are left out by default, and then every camera keeps what the game spawned it with, so a game without a `picture` sees no change. They apply to every 3D camera with `ThirdPersonCamera` or `FirstPersonCamera`, a camera spawned later included. A bloom makes the camera draw in HDR (Bevy's `Bloom` requires `Hdr`): the materials' colours are no longer stopped at full, and tone mapping moves from each material's shader to one pass over the whole picture, so light brighter than white (a lamp, an effect with an `intensity` above 1, see "Effects and decals") keeps its brightness until the tone mapping and the bloom see it. Taking `bloom` out of the content (or the whole definition) gives the camera back its own bloom, or none, and leaves HDR off again if the content turned it on. The same holds for `tone_mapping`. A game that sets its own `Bloom`, `Hdr` or `Tonemapping` on the camera keeps them while the content says nothing. The picture changes nothing else: the `camera` kind is not simulation content, so no replay changes. With HDR on, everything is tone mapped once, in the post pass, particles included (the particles' shader has no tone mapping of its own, so without HDR their colours reach the screen as written). -*Ambient occlusion.* `picture.ssao` gives the camera Bevy's `ScreenSpaceAmbientOcclusion`: from the depth and normals of what is on screen it darkens the indirect light (an ambient light, a camera's own `AmbientLight` fill, an irradiance volume, a reflection probe) in creases, corners and where a body meets the floor. It never darkens a point, spot or directional light, and Bevy does not apply it to a lightmap's light either (a bake has its occlusion in it): on a level with lightmaps it shows on what moves, lit by the probes and the ambient. Bevy's SSAO needs a depth prepass, a normal prepass and a camera without MSAA (with MSAA it logs an error and draws none): while the content gives a camera SSAO, the camera gets the prepasses it lacks and `Msaa::Off`; if another module takes a prepass away (the decals' depth prepass goes when the decals do) it is put back the next frame. Taking `ssao` out of the content gives the camera back its own SSAO (or none) and its own MSAA, and drops the prepasses it did not have. The first-person view model's camera copies the world camera's MSAA (the two share one main texture) and has no SSAO of its own: the arms are drawn over the occluded world. Without MSAA edges alias: a game that turns SSAO on wants an anti-aliasing pass of its own (FXAA, SMAA or TAA on the camera; TAA also smooths SSAO's noise). What it costs, measured on an RTX 5080 at 1920×1080 (`offscreen_measure_what_ssao_costs_on_the_gpu` in `crates/shards/tests/level_render.rs`, `#[ignore]`: Bevy's GPU timestamps of each pass over a floor with a grid of blocks): the SSAO pass takes 0.09 ms at `Low`, 0.13 ms at `Medium`, 0.22 ms at `High` and 0.60 ms at `Ultra`, and the depth and normal prepass 0.01 ms more; the whole frame grows by 0.07, 0.12, 0.20 and 0.58 ms (the prepass lets the main pass skip hidden pixels, which pays a little back). The cost goes with the pixels on screen, not with what is in the world; a weaker GPU pays several times more. +*Ambient occlusion.* `picture.ssao` gives the camera Bevy's `ScreenSpaceAmbientOcclusion`: from the depth and normals of what is on screen it darkens the indirect light (an ambient light, a camera's own `AmbientLight` fill, an irradiance volume, a reflection probe) in creases, corners and where a body meets the floor. It never darkens a point, spot or directional light, and Bevy does not apply it to a lightmap's light either (a bake has its occlusion in it): on a level with lightmaps it shows on what moves, lit by the probes and the ambient. Bevy's SSAO needs a depth prepass, a normal prepass and a camera without MSAA (with MSAA it logs an error and draws none): while the content gives a camera SSAO, the camera gets the prepasses it lacks and `Msaa::Off`; if another module takes a prepass away (the decals' depth prepass goes when the decals do) it is put back the next frame. Taking `ssao` out of the content gives the camera back its own SSAO (or none) and its own MSAA, and drops the prepasses it did not have. The first-person view model's camera copies the world camera's MSAA while the two share one main texture (a world camera without HDR), keeps its own 4x MSAA over an HDR one (a bloom: it has a texture of its own there), and has no SSAO of its own: the arms are drawn over the occluded world. Without MSAA edges alias: a game that turns SSAO on wants an anti-aliasing pass, which the content gives with `picture.anti_aliasing: Some(Smaa)` (or `Fxaa`): Bevy's pass over the finished picture, after the tone mapping (taking it out gives the camera back its own, or none). TAA, which would also smooth SSAO's noise, is not offered: it needs motion vectors and a jittered projection the first-person cameras do not have. What it costs, measured on an RTX 5080 at 1920×1080 (`offscreen_measure_what_ssao_costs_on_the_gpu` in `crates/shards/tests/level_render.rs`, `#[ignore]`: Bevy's GPU timestamps of each pass over a floor with a grid of blocks): the SSAO pass takes 0.09 ms at `Low`, 0.13 ms at `Medium`, 0.22 ms at `High` and 0.60 ms at `Ultra`, and the depth and normal prepass 0.01 ms more; the whole frame grows by 0.07, 0.12, 0.20 and 0.58 ms (the prepass lets the main pass skip hidden pixels, which pays a little back). The cost goes with the pixels on screen, not with what is in the world; a weaker GPU pays several times more. ```ron -{ "default": (picture: (ssao: Some((quality: Medium, radius: 0.5)))) } +{ "default": (picture: (ssao: Some((quality: Medium, radius: 0.5)), anti_aliasing: Some(Smaa))) } ``` ```ron @@ -1361,7 +1362,7 @@ A first-person game looks through the eye of the body it plays. `FirstPersonCame Every number is checked (`--check-content` names `first_person.landing.omega` and the like). The step is `EyeState::step`, exact for any frame time, tested without a window. - **The own body is not drawn** to its own camera: every mesh under the looked-through body (the model as it loads, a prop the bridge mounts later) is put on render layer **`OWN_BODY_LAYER` = 62**, which the camera, drawing the default layer 0 alone, never draws; what a mesh carried before comes back when the camera stops looking through that body (a possession, the mode going back). **`VIEW_MODEL_LAYER` = 63** is the view model's. The numbers are high on purpose: a game's own layers (a minimap, a preview) are the low ones. `shards_look`'s outline hulls copy their mesh's layers, so a hidden body has no outline either. Layers also decide **light and shadow** in Bevy (a shadow caster counts only for a light that shares its layer, and a light lights a camera only if they share one), so while a first-person camera exists the engine gives every light with no `RenderLayers` of its own the layers `[0, 62, 63]` (the body still casts its shadow, the arms are lit) and every other 3D camera with none `[0, 62]` (a mirror, a minimap shows the body); lights and cameras the game gave layers are its own and need those layers too. When the first-person camera goes, the engine takes back what it gave. A K3 shot over a first-person camera shows no own body unless the game adds the layer for it. -- **The view model** is a glTF rig (arms, a weapon) drawn by a **second camera** (`ViewModelCamera`, a child of the first-person camera, so it rides with the shake, the bob and the lean), one `order` above it, drawing `VIEW_MODEL_LAYER` alone with the definition's own field of view and near plane, so it never clips into a wall: it loads what the world camera drew and clears only the depth. It copies the world camera's anti-aliasing and tone mapping and, for an HDR world camera (the sandbox's), draws in HDR with no tone mapping of its own (the world camera has tone mapped what it drew), so the two share a main texture. The UI goes to the camera that draws last, so the HUD is over the arms. Content: +- **The view model** is a glTF rig (arms, a weapon) drawn by a **second camera** (`ViewModelCamera`, a child of the first-person camera, so it rides with the shake, the bob and the lean), one `order` above it, drawing `VIEW_MODEL_LAYER` alone with the definition's own field of view and near plane, so it never clips into a wall: it loads what the world camera drew and clears only the depth. It copies the world camera's anti-aliasing, tone mapping and grade, and draws without HDR whatever the world camera does: its materials tone map in their shaders and take the grade's exposure, so the arms are drawn alike over a world camera with HDR and without. Over a world camera without HDR the two share a main texture; over an HDR one (a bloom, the sandbox's) the view model draws into a texture of its own, cleared to nothing, which is laid over the world's finished picture (premultiplied alpha, Bevy's `CameraOutputMode`), so the bloom and the rest of the grade are the world's alone. The UI goes to the camera that draws last, so the HUD is over the arms. Content: - kind **`view_model`** (`*.view_model.ron`, a picture: outside the replay's content check): `model` (a `.glb` or `.gltf` in the assets folder, scene 0, made to face -Z: the camera looks along -Z; a relative path inside the folder: a leading `/` or `\`, a drive and `..` are errors on every platform), `animset` (the `animset` that moves it), `look` (optional: a `look` to dress it in; none: the file's materials), `fov_deg` (60), `near` (0.02), `offset` (where the rig sits in front of the camera: right, up, forward) and `scale`. `--check-content` checks that the file exists, that the animset and the look exist, and the numbers. - **Which one** is the weapon's: `MovesetDef::view_model` (a `view_model` id, left out when `None`, so no moveset hash moves) names it, so the moveset of the weapon in hand, which an `Arsenal` switch changes (F4), changes what is drawn within a frame; `first_person.view_model` is the one for a body whose moveset names none. Only the id belongs to the moveset's simulation content: the model, its animset and its numbers are the picture's. A moveset that names none under a camera that names none draws no view model, and no second camera is made. - **Animation.** The rig is `Animated` by its own animset and carries `ShowsBody(body)`: the animation bridge drives its skeleton from the **body's** `ActionState`, `MotionState`, `Fighter` and the rest, never from copies on the rig (an `ActionState` on another entity would be ticked by the action machine as a second fighter). So everything an animset does for a body works for a view model on its own skeleton: a clip for each locomotion state and action (`actions`, `tags`, the moveset's `by_moveset` families), layers, `sockets`, `carry` and `mounts` with `@moveset`, so a weapon switch can raise one prop and lower another on the arms. The rig has no `AiId` and is in no snapshot or replay; the body's overlays (`damaged`, `blocked`) do not play on it. Its meshes are put on the view model layer, made shadow-free (`NotShadowCaster`: a weapon that floats casts none) and never culled by their bounds, as they appear. @@ -7169,7 +7170,7 @@ The content check names the file, the definition and the field: `intensity` 0 or - `temperature` and `tint` are Bevy's: what is taken from the *x* of the white point and added to its *y* in CIE 1931 (D65 is (0.3127, 0.3290)). Small numbers are strong: a `temperature` of 0.02 to 0.05 is a clear warm or cool cast (at 0.05 the sandbox's grey room draws a fifth redder), and `tint` works on the same scale; near 0.3 the white point leaves the colour diagram and the picture loses its green and blue. The content check allows -1 to 1. - Bevy grades in this order: the white balance, saturation and contrast, lift, gamma and gain, and the `exposure` last. `contrast` pivots on 0.5 of the linear picture before the exposure, so in a dark scene that the grade's exposure lifts, a `contrast` above 1 sends the darks below zero and the picture goes black. Keep such a grade's `contrast` at 1, or light the scene (or expose the camera, Bevy's `Exposure`) instead of the grade. -A first-person view model is drawn by a second camera over the world ("The first-person camera and the view model (F1b)"). Without HDR it takes the world camera's grade (its exposure); in HDR it is drawn over the finished picture with no tone mapping and no grade, so a grade's exposure brightens the world and not the arms. +A first-person view model is drawn by a second camera over the world ("The first-person camera and the view model (F1b)"). It never draws in HDR: it takes the world camera's grade, of which it draws the exposure, with HDR on the world camera or without, so a grade's exposure brightens the arms as it brightens the world, and turning a bloom on leaves them as they were. The rest of an HDR world's grade (a white balance, a contrast) and its bloom are not drawn on the arms. A **grading volume** changes it where the player stands. A level node with `marker = "trigger"` (a collider shapes it, `auto` by default) and `grading = "rust"`, or a prefab with `"GradingVolume": (id: "rust")` on an entity with a trigger `Volume`: while the local player's body touches it (`MotionState::volumes`), the picture blends from what it shows toward the `rust` definition over its `blend_s` (eased, smoothstep), holds it, and blends back to the camera's own grade over the same time when the player leaves; a game with no local player uses the volumes the camera stands in. Where volumes overlap, the one placed last (the highest collider id) wins; a blend that changes course starts from what is shown, so nothing jumps. The state is the resource `GradingBlend`, tracked in `FixedLast` on every tick (so a `step` of 100 ticks sees the tick the player crossed the line) and evaluated on the simulation's clock, which is why a headless game can say where the blend is. It is in no snapshot or replay. @@ -7191,7 +7192,7 @@ grading: the camera's own **In the sandbox.** `content/light/` has the lights (`lamp`, `sodium`, `tube`, `flasher`, `dimmer`, `torch`), the gradings (`rust`, `cold`), the prefabs `lit_lamp` and `lit_flasher`, and the level `lit_room` (`assets/levels/lit_room.gltf`, written by `tests/sandbox/lights.rs`): a floor and three walls with six lights (four on Blender lamps that the content lights replace, two on empties) and a trigger volume over its right half that grades with `rust`. `scenarios/lights.scenario` plays it with queries alone, so it runs headless. Tests: `shards_light` (unit tests for the definitions, the flicker and the budget; `tests/light/` for the content check, the query, the clock and the Bevy lights of a drawn game) and the sandbox's `lights.rs`, whose `#[ignore]`d tests need a GPU (`cargo test -p sandbox --test sandbox -- --ignored lights`): the picture holds exactly the six content lights, a flashing lamp lights the room at one moment and not at the next, and a grading volume changes the channel means of the shot and gives them back. -**What is not here.** Directional lights (a sun) are not content yet. Emissive bulbs do not follow a flicker (the material is the game's). There is no area light or light cookie and no hysteresis in the budget. A light cannot be confined to a room: a light without a shadow lights through walls (see "Confining a light to a room" below). The view model's camera (F1b) takes the world camera's grade when that camera does not draw in HDR; under an HDR camera (any `picture.bloom`) it draws over the graded picture and stays ungraded, and any other second camera that draws the world is the game's to grade. Checked on a GPU with `--offscreen` (RTX 5080); not checked by eye in a window. +**What is not here.** Directional lights (a sun) are not content yet. Emissive bulbs do not follow a flicker (the material is the game's). There is no area light or light cookie and no hysteresis in the budget. A light cannot be confined to a room: a light without a shadow lights through walls (see "Confining a light to a room" below). The view model's camera (F1b) draws a grade's exposure alone, under an HDR world camera too; any other second camera that draws the world is the game's to grade. Checked on a GPU with `--offscreen` (RTX 5080); not checked by eye in a window. **Confining a light to a room.** A light lights everything inside its `range` (and a spot's cone) that faces it; only its shadow map stops it at a wall, so a lamp without a shadow (over the budget, or `shadows: false`) lights the next room through the wall. There is no clean way in Bevy 0.20 to clip a light to a box or a room. Its clustered lights carry no room or volume (the GPU struct `GpuClusteredLight` and its WGSL twin `ClusteredLight` are Bevy's, with `pub(crate)` fields, and the mesh view bind group is fixed), its clustering does not read a light's `RenderLayers`, and `RenderLayers` filter a light per camera, not per surface, so they would not confine a light to a room even where honoured. A clean confinement needs a patched `bevy_pbr`: a component on the light (an axis-aligned box, or a room mask matched against a per-mesh mask) extracted into the clustered light (16 to 32 bytes more per light), and a test in the point and spot light functions of `pbr_lighting.wesl` that returns no light for a fragment outside it (six compares per light per fragment, nothing on the CPU). That is a fork of Bevy's renderer to carry from version to version, so it is not done. What the engine does give: a budget in shadow views (`graphics.shadow_views`, above), which gives many spots a shadow where one point light would; and baked light (`baked_light` with `baked: true` on the lamps the bake holds), whose lightmaps carry the walls' occlusion, so a baked lamp lights no lightmapped surface at all, through a wall or not, and only what moves and the surfaces' shine take its live light.