Merge pull request #1249 from rdbtCVS/t3/fix-menu-background-blur

🤖 Agent: merged after verify passed and the wave 2 integration run on the desktop (main + 16 contributor PRs, tree 71afc562: workspace tests 1887/0, launcher 113, naga translations 0 failures, parity --changed 304/0).
This commit is contained in:
Ludovic Marie
2026-10-22 21:59:29 +02:00
committed by GitHub
4 changed files with 130 additions and 11 deletions
+9 -4
View File
@@ -4849,6 +4849,9 @@ impl Game<'_> {
self.draw_chat(&mut batch);
self.draw_tab_list(&mut batch);
}
// Screen.extractBlurredBackground blurs the world and HUD, while the
// screen's background, widgets, toasts and debug overlay stay sharp.
batch.blur_at = batch.vertices.len() as u32;
match self.screen {
Screen::Paused if self.pause_menu => self.draw_pause_menu(&mut batch),
// PauseScreen(false): only its title, at the top.
@@ -10018,9 +10021,8 @@ impl Game<'_> {
};
level_loading::draw(batch, atlas, Some(&status), Some(self.loading_progress));
}
/// `Screen.extractBlurredBackground` over the panorama: every classic
/// screen of the title menus but the title itself (`TitleScreen`
/// doesn't blur), when `menuBackgroundBlurriness` is at least 1.
/// `Screen.extractBlurredBackground` over the panorama or the world and
/// HUD, when `menuBackgroundBlurriness` is at least 1.
fn menu_blur(&self) -> Option<f32> {
let loading = self.loading_reason() == Some(horizon_client::level_loading::Reason::Other);
let blurred = !horizon_client::ui_theme::horizon()
@@ -10028,7 +10030,10 @@ impl Game<'_> {
|| self.title.as_ref().is_some_and(|t| {
self.screen == Screen::Options
|| !matches!(t.mode, horizon_client::title::Mode::Main)
}));
})
|| (self.title.is_none()
&& self.player.is_some()
&& self.screen.blurs_background(self.pause_menu)));
let radius = self.settings.menu_blur as f32;
(blurred && radius >= 1.0).then_some(radius)
}
+46 -1
View File
@@ -7,6 +7,24 @@ use horizon_client::{
ui,
};
impl Screen {
/// Screen.extractBackground for non-isInGameUi screens, and
/// PauseScreen.extractBackground only when showPauseMenu is true.
pub(super) fn blurs_background(self, pause_menu: bool) -> bool {
match self {
Self::Paused => pause_menu,
Self::Options | Self::Stats | Self::Advancements | Self::WorldOptions => true,
Self::Playing
| Self::GameModeSwitcher
| Self::Chat
| Self::Creative
| Self::Inventory
| Self::Dead
| Self::CommandBlock => false,
}
}
}
/// PauseScreen buttons: (x, y, width, label key, action id, active).
/// https://mcsrc.dev/2/26.3/net/minecraft/client/gui/screens/PauseScreen
fn pause_buttons(w: f32, h: f32, remote: bool) -> Vec<(f32, f32, f32, &'static str, u8, bool)> {
@@ -334,7 +352,34 @@ impl Game<'_> {
#[cfg(test)]
mod tests {
use super::pause_buttons;
use super::{Screen, pause_buttons};
#[test]
fn menu_blur_matches_vanilla_screen_backgrounds() {
for screen in [
Screen::Options,
Screen::Stats,
Screen::Advancements,
Screen::WorldOptions,
] {
assert!(screen.blurs_background(false));
assert!(screen.blurs_background(true));
}
assert!(Screen::Paused.blurs_background(true));
assert!(!Screen::Paused.blurs_background(false));
for screen in [
Screen::Playing,
Screen::GameModeSwitcher,
Screen::Chat,
Screen::Creative,
Screen::Inventory,
Screen::Dead,
Screen::CommandBlock,
] {
assert!(!screen.blurs_background(true));
assert!(!screen.blurs_background(false));
}
}
#[test]
fn pause_menu_uses_disconnect_for_servers_and_keeps_world_options() {
+15 -4
View File
@@ -3841,9 +3841,19 @@ impl Renderer {
let first = debug_depth + debug_top;
pass.draw(0..4, first..first + crosshair);
}
if let Some(radius) = frame.menu_blur
&& self.config.usage.contains(wgpu::TextureUsages::COPY_SRC)
{
let menu_blur = frame
.menu_blur
.filter(|_| self.config.usage.contains(wgpu::TextureUsages::COPY_SRC));
let blur_at = menu_blur.map_or(0, |_| frame.hud.blur_at);
self.hud.draw_range(
&mut encoder,
&view_target,
&self.depth,
frame.hud,
[self.config.width, self.config.height],
0..blur_at,
);
if let Some(radius) = menu_blur {
let format = self.config.format;
let device = &self.device;
self.menu_blur
@@ -3875,12 +3885,13 @@ impl Renderer {
grade,
);
}
self.hud.draw(
self.hud.draw_range(
&mut encoder,
&view_target,
&self.depth,
frame.hud,
[self.config.width, self.config.height],
blur_at..frame.hud.vertices.len() as u32,
);
if culling && let Some(cull) = &mut self.cull {
cull.end(&self.device, &mut encoder);
+60 -2
View File
@@ -365,6 +365,8 @@ pub struct HudBatch {
pub patches: Vec<crate::font::Patch>,
/// Vertex ranges with another blend or depth/scissor state, in order.
pub blends: Vec<(std::ops::Range<u32>, Blend)>,
/// Screen's first vertex: the preceding HUD is part of its blurred background.
pub blur_at: u32,
}
/// How a run of HUD vertices blends and tests depth.
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
@@ -400,6 +402,7 @@ impl HudBatch {
height: (window[1] as f32 / scale as f32).ceil(),
patches: Vec::new(),
blends: Vec::new(),
blur_at: 0,
}
}
/// Draw the vertices added since `start` with the inverting blend.
@@ -452,6 +455,14 @@ impl HudBatch {
}
out
}
fn runs_in(&self, vertices: std::ops::Range<u32>) -> Vec<(std::ops::Range<u32>, Blend)> {
let mut runs = self.runs();
for (range, _) in &mut runs {
*range = range.start.max(vertices.start)..range.end.min(vertices.end);
}
runs.retain(|(range, _)| !range.is_empty());
runs
}
/// `AbstractContainerScreen.init`: center in integer GUI coordinates.
pub fn centered_origin(&self, width: f32, height: f32) -> (f32, f32) {
(
@@ -1080,7 +1091,26 @@ impl HudRenderer {
batch: &HudBatch,
size: [u32; 2],
) {
if batch.vertices.is_empty() || size.contains(&0) {
self.draw_range(
encoder,
target,
depth,
batch,
size,
0..batch.vertices.len() as u32,
);
}
/// Draw part of the prepared batch, preserving its blend/depth runs.
pub fn draw_range(
&self,
encoder: &mut wgpu::CommandEncoder,
target: &wgpu::TextureView,
depth: &wgpu::TextureView,
batch: &HudBatch,
size: [u32; 2],
vertices: std::ops::Range<u32>,
) {
if vertices.is_empty() || size.contains(&0) {
return;
}
let attachments = [Some(wgpu::RenderPassColorAttachment {
@@ -1092,7 +1122,7 @@ impl HudRenderer {
store: wgpu::StoreOp::Store,
},
})];
let runs = batch.runs();
let runs = batch.runs_in(vertices);
let mut at = 0;
while at < runs.len() {
let clip = match runs[at].1 {
@@ -1331,6 +1361,33 @@ mod tests {
]
);
}
#[test]
fn blur_boundary_splits_blend_runs_without_losing_or_repeating_vertices() {
let mut batch = HudBatch::new([854, 480]);
for _ in 0..5 {
batch.quad([[0.0; 2]; 4], [[0.0; 2]; 4], 0);
}
batch.blends = vec![
(6..18, Blend::Invert),
(18..24, Blend::Depth([0, 0, 10, 10])),
];
for split in [0, 6, 12, 18, 24, 30] {
let before = batch.runs_in(0..split);
let after = batch.runs_in(split..30);
let actual: Vec<_> = before
.into_iter()
.chain(after)
.flat_map(|(range, blend)| range.map(move |v| (v, blend)))
.collect();
let expected: Vec<_> = batch
.runs()
.into_iter()
.flat_map(|(range, blend)| range.map(move |v| (v, blend)))
.collect();
assert_eq!(actual, expected, "blur at {split}");
}
}
#[test]
fn container_origins_use_java_integer_division() {
// Odd scaled dimensions, odd image sizes and an oversized panel.
@@ -1342,6 +1399,7 @@ mod tests {
height: height as f32,
patches: Vec::new(),
blends: Vec::new(),
blur_at: 0,
};
for (image_width, image_height) in [(195, 136), (176, 166), (176, 222)] {
assert_eq!(