#882: pixel-exact Composition viewer at 100 % and above

Problem: the viewer blurred hard edges even at Full resolution and 100 %
(reported on Discord). The frame rect was centred without snapping to
physical pixels, so bilinear sampling blended neighbouring pixels at 1:1
(worst at 125 %/150 % display scaling); More Accurate also magnified
bilinearly, so 200 %+ and lower resolutions were smoothed; and Zoom In /
Zoom Out stepped in points, so at 125 % scaling they never reached 100 %.

Fix: snap the frame origin (and the ViewerMap overlays use) to the
physical pixel grid; magnify with nearest in both Zoom Quality modes
(CPU texture options and the GPU frame sampler), keeping the averaged
minification below 100 % (#417); the snapshot texture follows the same
options; Zoom In / Out step through screen-pixel magnifications.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
vangel76
2026-10-11 18:50:53 +02:00
co-authored by Claude Opus 5.5
parent 67434e9038
commit 8ac8612ace
5 changed files with 105 additions and 14 deletions
+30 -6
View File
@@ -860,13 +860,9 @@ pub fn frontend(app: &mut EffectcraftApp, ctx: &egui::Context, id: &str, p: Valu
r
}
"view.zoomIn" | "view.zoomOut" => {
let ppp = ctx.pixels_per_point();
let cur = v.zoom.unwrap_or_else(|| crate::panels::viewer::last_fit(ctx));
const STEPS: [f32; 16] = [0.015, 0.03, 0.0625, 0.125, 0.25, 0.333, 0.5, 0.66, 1.0, 1.5, 2.0, 3.0, 4.0, 8.0, 16.0, 32.0];
let next = if id == "view.zoomIn" {
STEPS.iter().copied().find(|s| *s > cur + 1e-3).unwrap_or(32.0)
} else {
STEPS.iter().rev().copied().find(|s| *s < cur - 1e-3).unwrap_or(0.015)
};
let next = zoom_step(cur, ppp, id == "view.zoomIn");
v.zoom = Some(next);
json!({"zoom": next})
}
@@ -1932,10 +1928,38 @@ fn menu_entry(app: &EffectcraftApp, ui: &mut egui::Ui, e: &MenuEntry) -> egui::R
ui.add_enabled(enabled, b)
}
/// View ▸ Zoom In / Zoom Out: the next standard magnification (as a share of screen pixels, so
/// 100 % is one comp pixel per screen pixel at any display scaling) above or below `cur`, which is
/// in points per comp pixel like the result (#882).
fn zoom_step(cur: f32, ppp: f32, zoom_in: bool) -> f32 {
const STEPS: [f32; 16] = [0.015, 0.03, 0.0625, 0.125, 0.25, 0.333, 0.5, 0.66, 1.0, 1.5, 2.0, 3.0, 4.0, 8.0, 16.0, 32.0];
let ppp = if ppp.is_finite() && ppp > 0.0 { ppp } else { 1.0 };
let shown = cur * ppp;
let next = if zoom_in {
STEPS.iter().copied().find(|s| *s > shown + 1e-3).unwrap_or(32.0)
} else {
STEPS.iter().rev().copied().find(|s| *s < shown - 1e-3).unwrap_or(0.015)
};
next / ppp
}
#[cfg(test)]
mod tests {
use super::*;
/// #882: at 125 % / 150 % display scaling Zoom In reaches 100 % (one comp pixel per screen
/// pixel), not 100 % in points (125 % / 150 % on screen).
#[test]
fn zoom_steps_land_on_whole_screen_magnifications() {
for ppp in [1.0f32, 1.25, 1.5, 2.0] {
let at_100 = zoom_step(0.7 / ppp, ppp, true);
assert!((at_100 * ppp - 1.0).abs() < 1e-6, "ppp {ppp}: {}", at_100 * ppp);
assert!((zoom_step(at_100, ppp, true) * ppp - 1.5).abs() < 1e-6);
assert!((zoom_step(at_100, ppp, false) * ppp - 0.66).abs() < 1e-6);
}
assert!(zoom_step(1.0, 0.0, true).is_finite());
}
#[test]
fn shortcut_passes_share_frame_start_modifiers() {
let ctx = egui::Context::default();