Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix(rendering): base camera transition blur on frame motion

Richie McIlroyd0f9750dd871
diff --git a/crates/rendering/src/lib.rs b/crates/rendering/src/lib.rs
index 9d6a7d70c..a7fd3c712 100644
--- a/crates/rendering/src/lib.rs
+++ b/crates/rendering/src/lib.rs
@@ -2867,10 +2867,6 @@ const MAX_ZOOM_BLUR_AMOUNT: f32 = 0.5;
const DISPLAY_MOVE_MULTIPLIER: f32 = 1.0;
const DISPLAY_ZOOM_MULTIPLIER: f32 = 1.0;
const CAMERA_MULTIPLIER: f32 = 1.0;
-const CAMERA_ONLY_MULTIPLIER: f32 = 0.45;
-/// Ceiling for synthetic transition blur (scene morphs, camera-only
-/// entrances). These are art-directed effects that predate the proportional
-/// model and are tuned to their own visual scale, not to real velocity.
const TRANSITION_ZOOM_CAP: f32 = 0.08;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
@@ -3286,9 +3282,6 @@ impl ProjectUniforms {
analysis.size_delta_px /= frame_span;
analysis.zoom_magnitude /= frame_span;
if extra_zoom > 0.0 {
- // Scene transitions inject synthetic radial blur; they also move
- // the bounds a lot, so force the zoom branch past the dominance
- // check or the pan delta would win and hide it.
analysis.zoom_magnitude = (analysis.zoom_magnitude + extra_zoom).min(3.0);
analysis.prefer_zoom = true;
}
@@ -3876,7 +3869,11 @@ impl ProjectUniforms {
let (prev_start, prev_end) =
Self::display_bounds(&motion_prev_zoom, display_offset, display_size);
- let scene_blur_strength = (scene.screen_blur as f32 * 0.8).min(1.2);
+ let scene_blur_strength = if options.camera_size.is_some() && !project.camera.hide {
+ scene.camera_only_motion(&prev_scene)
+ } else {
+ 0.0
+ };
// An instant-animation zoom snap is a deliberate hard cut; the
// bounds delta across it is not motion, so blurring it would smear
@@ -4508,20 +4505,14 @@ impl ProjectUniforms {
let crop_bounds =
inset_crop_bounds(crop_bounds, frame_size, CAMERA_EDGE_CROP_INSET_PX);
- let camera_only_blur = (scene.camera_only_blur as f32
- * CAMERA_ONLY_MULTIPLIER
- * normalized_screen_motion)
- .clamp(0.0, 1.0);
+ let camera_only_blur =
+ scene.camera_only_motion(&prev_scene) * normalized_screen_motion;
let camera_only_descriptor = if camera_only_blur <= f32::EPSILON {
MotionBlurDescriptor::none()
} else {
- // Synthetic transition blur (not velocity-derived): keep
- // its ray length on the old visual scale — the shader no
- // longer softens via a sharp/blur crossfade, so the
- // amount alone sets the look.
MotionBlurDescriptor::zoom(
XY::new(0.5, 0.5),
- (camera_only_blur * 0.75).min(TRANSITION_ZOOM_CAP),
+ camera_only_blur.min(TRANSITION_ZOOM_CAP),
1.0,
)
};
diff --git a/crates/rendering/src/scene.rs b/crates/rendering/src/scene.rs
index acb5dae7a..6c12e8152 100644
--- a/crates/rendering/src/scene.rs
+++ b/crates/rendering/src/scene.rs
@@ -67,9 +67,7 @@ pub struct InterpolatedScene {
pub transition_progress: f64,
pub from_mode: SceneMode,
pub to_mode: SceneMode,
- pub screen_blur: f64,
pub camera_only_zoom: f64,
- pub camera_only_blur: f64,
/// 0.0 = no split layout, 1.0 = fully side-by-side. Ramps with
/// `transition_progress` when entering/leaving [`SceneMode::SplitScreen`]
/// or [`SceneMode::Floating`] so the compositor morphs the screen+camera
@@ -95,9 +93,7 @@ impl InterpolatedScene {
transition_progress: 1.0,
from_mode: scene_mode,
to_mode: scene_mode,
- screen_blur: 0.0,
camera_only_zoom: 1.0,
- camera_only_blur: 0.0,
split_factor: if is_split_mode(&scene_mode) { 1.0 } else { 0.0 },
floating_factor: if matches!(scene_mode, SceneMode::Floating) {
1.0
@@ -234,24 +230,6 @@ impl InterpolatedScene {
);
let camera_scale = Self::lerp(start_camera_scale, end_camera_scale, transition_progress);
- let screen_blur = if matches!(current_mode, SceneMode::CameraOnly)
- || matches!(next_mode, SceneMode::CameraOnly)
- {
- if matches!(current_mode, SceneMode::CameraOnly)
- && !matches!(next_mode, SceneMode::CameraOnly)
- {
- Self::lerp(1.0, 0.0, transition_progress)
- } else if !matches!(current_mode, SceneMode::CameraOnly)
- && matches!(next_mode, SceneMode::CameraOnly)
- {
- transition_progress
- } else {
- 0.0
- }
- } else {
- 0.0
- };
-
let camera_only_zoom = if matches!(next_mode, SceneMode::CameraOnly)
&& !matches!(current_mode, SceneMode::CameraOnly)
{
@@ -264,18 +242,6 @@ impl InterpolatedScene {
1.0
};
- let camera_only_blur = if matches!(next_mode, SceneMode::CameraOnly)
- && !matches!(current_mode, SceneMode::CameraOnly)
- {
- Self::lerp(1.0, 0.0, transition_progress)
- } else if matches!(current_mode, SceneMode::CameraOnly)
- && !matches!(next_mode, SceneMode::CameraOnly)
- {
- transition_progress
- } else {
- 0.0
- };
-
let from_split = is_split_mode(&current_mode);
let to_split = is_split_mode(&next_mode);
let split_factor = match (from_split, to_split) {
@@ -306,9 +272,7 @@ impl InterpolatedScene {
transition_progress,
from_mode: current_mode,
to_mode: next_mode,
- screen_blur,
camera_only_zoom,
- camera_only_blur,
split_factor,
floating_factor,
}
@@ -335,7 +299,7 @@ impl InterpolatedScene {
}
pub fn should_render_screen(&self) -> bool {
- self.screen_opacity > 0.01 || self.screen_blur > 0.01
+ self.screen_opacity > 0.01
}
pub fn is_split(&self) -> bool {
@@ -365,6 +329,19 @@ impl InterpolatedScene {
}
}
+ pub fn camera_only_motion(&self, previous: &Self) -> f32 {
+ if matches!(self.from_mode, SceneMode::CameraOnly)
+ == matches!(self.to_mode, SceneMode::CameraOnly)
+ {
+ return 0.0;
+ }
+
+ // The invisible camera jumps to 1.1x at entry. Opacity tracks the
+ // continuous part of that 10% zoom without counting the jump as motion.
+ ((self.camera_only_transition_opacity() - previous.camera_only_transition_opacity()).abs()
+ * 0.1) as f32
+ }
+
pub fn regular_camera_transition_opacity(&self) -> f64 {
if matches!(self.to_mode, SceneMode::CameraOnly)
&& !matches!(self.from_mode, SceneMode::CameraOnly)
@@ -385,3 +362,57 @@ impl InterpolatedScene {
}
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ fn scene_at(time: f64, segments: &[SceneSegment]) -> InterpolatedScene {
+ InterpolatedScene::new(SceneSegmentsCursor::new(time, segments))
+ }
+
+ fn camera_scene(transition: f64) -> SceneSegment {
+ SceneSegment {
+ start: 2.0,
+ end: 5.0,
+ mode: SceneMode::CameraOnly,
+ split_layout: None,
+ transition_in: transition,
+ transition_out: transition,
+ }
+ }
+
+ #[test]
+ fn camera_only_blur_tracks_motion_at_both_boundaries() {
+ let segments = [camera_scene(0.3)];
+ for fps in [30, 60, 120] {
+ let motion_at = |frame: u32| {
+ let scene = scene_at(f64::from(frame) / f64::from(fps), &segments);
+ let previous = scene_at(f64::from(frame - 1) / f64::from(fps), &segments);
+ scene.camera_only_motion(&previous) * fps as f32 / 60.0
+ };
+ let peak = (fps..6 * fps).map(motion_at).fold(0.0_f32, f32::max);
+ assert!(peak > 0.005 && peak < 0.011, "{fps} fps: {peak}");
+ for time in [1.7, 2.0, 4.7, 5.0] {
+ let frame = (time * f64::from(fps)).round() as u32;
+ assert!(motion_at(frame) < 0.003, "{fps} fps at {time}");
+ assert!(motion_at(frame + 1) < 0.003, "{fps} fps after {time}");
+ }
+ for time in [1, 3, 6] {
+ assert_eq!(motion_at(time * fps), 0.0);
+ }
+ }
+ }
+
+ #[test]
+ fn camera_only_cuts_and_contiguous_scenes_do_not_blur() {
+ let mut segments = [camera_scene(0.0), camera_scene(0.3)];
+ segments[1].start = segments[0].end;
+ segments[1].end = 8.0;
+ for time in [2.0, 4.99, 5.0, 5.01] {
+ let scene = scene_at(time, &segments);
+ let previous = scene_at(time - 1.0 / 60.0, &segments);
+ assert_eq!(scene.camera_only_motion(&previous), 0.0);
+ }
+ }
+}