Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat(rendering): add Camera3D warp layer and CoC blur

Richie McIlroyb03360b65600
diff --git a/crates/rendering/src/camera3d.rs b/crates/rendering/src/camera3d.rs
new file mode 100644
index 000000000..8fe324318
--- /dev/null
+++ b/crates/rendering/src/camera3d.rs
@@ -0,0 +1,769 @@
+//! 3D camera transform for the composed content plane.
+//!
+//! Geometry: the content plane's longest side spans 2 world units, centered
+//! at the origin facing +Z. The camera orbits via Euler YXZ (`tilt_y`,
+//! `tilt_x`, `roll`), the plane itself rotates via `rotate_y`·`rotate_x`,
+//! `zoom` is the camera distance, `pan_x`/`pan_y` truck the camera in its own
+//! plane, and `fov` is the vertical field of view with no size compensation:
+//! apparent size ∝ 1 / (zoom · tan(fov/2)).
+//!
+//! view(p) = T(pan_x, pan_y, -zoom) · R_cam · R_obj · p
+//! R_cam = Ry(tilt_y)·Rx(tilt_x)·Rz(roll) R_obj = Ry(rotate_y)·Rx(rotate_x)
+//!
+//! Keyframes are per-property tracks with a split-handle bezier easing: the
+//! segment between two keyframes lerps the value linearly with time remapped
+//! by cubic-bezier(P1 = left.out_easing ?? [0.65, 0],
+//! P2 = right.in_easing ?? [0.35, 1]).
+//!
+//! Cap addition: `transition_in`/`transition_out` ease the whole effect from
+//! the flat frame (zoom at the exact fill distance, all angles zero) into the
+//! pose, so a segment always enters and leaves gracefully.
+
+use cap_project::{Camera3DBlurMode, Camera3DKeyframe, Camera3DProperties, Camera3DSegment};
+
+/// Default split handles: cubic ease-in-out.
+const DEFAULT_OUT_EASING: [f64; 2] = [0.65, 0.0];
+const DEFAULT_IN_EASING: [f64; 2] = [0.35, 1.0];
+
+/// Blur strength is authored in pixels at this output height and scaled by the
+/// renderer so preview and export match (same convention as mask effects).
+pub const CAMERA3D_BLUR_BASE_HEIGHT: f64 = 1080.0;
+
+/// Effective, fully-sampled 3D state for one frame.
+#[derive(Clone, Copy, Debug)]
+pub struct Camera3DFrame {
+ /// `None` when the frame is exactly flat (warp pass can be skipped).
+ pub pose: Option<Camera3DProperties>,
+ /// `None` when no blur should render this frame.
+ pub blur: Option<Camera3DBlurFrame>,
+ /// Boundary ramp 0..1. Decorations that read wrong in 3D (the flat drop
+ /// shadow baked into the content) fade out with this.
+ pub activity: f64,
+}
+
+#[derive(Clone, Copy, Debug, PartialEq)]
+pub struct Camera3DBlurFrame {
+ pub mode: Camera3DBlurMode,
+ /// Pixels at [`CAMERA3D_BLUR_BASE_HEIGHT`]; already boundary-ramped and
+ /// bokeh-capped.
+ pub strength: f64,
+ pub falloff: f64,
+ pub focus_x: f64,
+ pub focus_y: f64,
+ pub focus_size: f64,
+ /// Radians.
+ pub angle: f64,
+ pub dir_position: f64,
+ pub bokeh: bool,
+}
+
+/// Samples the active 3d segment at `frame_time`, or `None` when no segment
+/// covers the frame (or the sampled state is visually flat with no blur).
+pub fn interpolate_camera3d(
+ frame_time: f64,
+ segments: &[Camera3DSegment],
+ aspect: f64,
+) -> Option<Camera3DFrame> {
+ let segment = segments
+ .iter()
+ .filter(|s| s.enabled)
+ .find(|s| frame_time >= s.start && frame_time <= s.end)?;
+
+ let rel = frame_time - segment.start;
+ let tracks = &segment.tracks;
+ let base = &segment.properties;
+ let blur_base = &segment.blur;
+
+ let pose = Camera3DProperties {
+ tilt_x: sample_track(base.tilt_x, &tracks.tilt_x, rel),
+ tilt_y: sample_track(base.tilt_y, &tracks.tilt_y, rel),
+ roll: sample_track(base.roll, &tracks.roll, rel),
+ rotate_x: sample_track(base.rotate_x, &tracks.rotate_x, rel),
+ rotate_y: sample_track(base.rotate_y, &tracks.rotate_y, rel),
+ fov: sample_track(base.fov, &tracks.fov, rel),
+ zoom: sample_track(base.zoom, &tracks.zoom, rel),
+ pan_x: sample_track(base.pan_x, &tracks.pan_x, rel),
+ pan_y: sample_track(base.pan_y, &tracks.pan_y, rel),
+ };
+
+ let blur = Camera3DBlurFrame {
+ mode: blur_base.mode,
+ strength: sample_track(blur_base.strength, &tracks.blur_strength, rel),
+ falloff: sample_track(blur_base.falloff, &tracks.blur_falloff, rel),
+ focus_x: sample_track(blur_base.focus_x, &tracks.blur_focus_x, rel),
+ focus_y: sample_track(blur_base.focus_y, &tracks.blur_focus_y, rel),
+ focus_size: sample_track(blur_base.focus_size, &tracks.blur_focus_size, rel),
+ angle: sample_track(blur_base.angle, &tracks.blur_angle, rel).to_radians(),
+ dir_position: sample_track(blur_base.dir_position, &tracks.blur_dir_position, rel),
+ bokeh: blur_base.bokeh,
+ };
+
+ let activity = boundary_activity(segment, frame_time);
+ Some(effective_frame(&pose, &blur, activity, aspect))
+}
+
+fn effective_frame(
+ pose: &Camera3DProperties,
+ blur: &Camera3DBlurFrame,
+ activity: f64,
+ aspect: f64,
+) -> Camera3DFrame {
+ let fov = pose.fov.clamp(1.0, 179.0);
+ let (_, hy) = plane_half_extents(aspect);
+ // The camera distance at which the plane exactly fills the frame — the
+ // "flat" end of the boundary ramp.
+ let fill_zoom = hy / (fov.to_radians() / 2.0).tan();
+
+ let eased = pose_from_activity(pose, activity, fill_zoom);
+
+ let flat = eased.tilt_x.abs() < 1e-3
+ && eased.tilt_y.abs() < 1e-3
+ && eased.roll.abs() < 1e-3
+ && eased.rotate_x.abs() < 1e-3
+ && eased.rotate_y.abs() < 1e-3
+ && eased.pan_x.abs() < 1e-4
+ && eased.pan_y.abs() < 1e-4
+ && (eased.zoom - fill_zoom).abs() < 1e-4;
+
+ let mut strength = blur.strength.max(0.0) * activity;
+ if blur.bokeh {
+ strength = strength.min(20.0);
+ } else {
+ strength = strength.min(60.0);
+ }
+ let blur_active =
+ blur.mode != Camera3DBlurMode::None && strength >= 0.5 && strength.is_finite();
+
+ Camera3DFrame {
+ pose: (!flat).then_some(eased),
+ blur: blur_active.then_some(Camera3DBlurFrame {
+ strength,
+ ..*blur
+ }),
+ activity: activity.clamp(0.0, 1.0),
+ }
+}
+
+fn pose_from_activity(pose: &Camera3DProperties, activity: f64, fill_zoom: f64) -> Camera3DProperties {
+ let a = activity.clamp(0.0, 1.0);
+ let zoom = pose.zoom.clamp(0.05, 100.0);
+ Camera3DProperties {
+ tilt_x: pose.tilt_x * a,
+ tilt_y: pose.tilt_y * a,
+ roll: pose.roll * a,
+ rotate_x: pose.rotate_x * a,
+ rotate_y: pose.rotate_y * a,
+ fov: pose.fov,
+ zoom: fill_zoom + (zoom - fill_zoom) * a,
+ pan_x: pose.pan_x * a,
+ pan_y: pose.pan_y * a,
+ }
+}
+
+/// 0 at the segment edges, ramping to 1 over `transition_in`/`transition_out`.
+fn boundary_activity(segment: &Camera3DSegment, frame_time: f64) -> f64 {
+ let len = (segment.end - segment.start).max(0.0);
+ let half = len / 2.0;
+ let t_in = segment.transition_in.clamp(0.0, half);
+ let t_out = segment.transition_out.clamp(0.0, half);
+
+ let a_in = if t_in > 0.0 {
+ ((frame_time - segment.start) / t_in).clamp(0.0, 1.0)
+ } else {
+ 1.0
+ };
+ let a_out = if t_out > 0.0 {
+ ((segment.end - frame_time) / t_out).clamp(0.0, 1.0)
+ } else {
+ 1.0
+ };
+
+ bezier_ease(DEFAULT_OUT_EASING, DEFAULT_IN_EASING, a_in)
+ * bezier_ease(DEFAULT_OUT_EASING, DEFAULT_IN_EASING, a_out)
+}
+
+/// Samples one per-property track: base value when empty, hold outside the
+/// keyed range, split-handle bezier lerp between neighbours.
+pub fn sample_track(base: f64, keys: &[Camera3DKeyframe], time: f64) -> f64 {
+ if keys.is_empty() {
+ return base;
+ }
+
+ let mut sorted = keys.to_vec();
+ sorted.sort_by(|a, b| {
+ a.time
+ .partial_cmp(&b.time)
+ .unwrap_or(std::cmp::Ordering::Equal)
+ });
+
+ if time <= sorted[0].time {
+ return sorted[0].value;
+ }
+
+ for window in sorted.windows(2) {
+ let prev = &window[0];
+ let next = &window[1];
+ if time <= next.time {
+ let span = (next.time - prev.time).max(1e-6);
+ let progress = ((time - prev.time) / span).clamp(0.0, 1.0);
+ let p1 = prev.out_easing.unwrap_or(DEFAULT_OUT_EASING);
+ let p2 = next.in_easing.unwrap_or(DEFAULT_IN_EASING);
+ let eased = bezier_ease(p1, p2, progress);
+ return prev.value + (next.value - prev.value) * eased;
+ }
+ }
+
+ sorted.last().map(|k| k.value).unwrap_or(base)
+}
+
+fn bezier_component(p1: f64, p2: f64, t: f64) -> f64 {
+ let inv = 1.0 - t;
+ 3.0 * inv * inv * t * p1 + 3.0 * inv * t * t * p2 + t * t * t
+}
+
+fn bezier_derivative(p1: f64, p2: f64, t: f64) -> f64 {
+ let a = 1.0 - 3.0 * p2 + 3.0 * p1;
+ let b = 3.0 * p2 - 6.0 * p1;
+ let c = 3.0 * p1;
+ (3.0 * a * t + 2.0 * b) * t + c
+}
+
+/// Cubic-bezier timing with control points P1/P2 (P0=(0,0), P3=(1,1)):
+/// 8 Newton iterations then bisection.
+pub fn bezier_ease(p1: [f64; 2], p2: [f64; 2], t: f64) -> f64 {
+ if t <= 0.0 {
+ return 0.0;
+ }
+ if t >= 1.0 {
+ return 1.0;
+ }
+ let [x1, y1] = p1;
+ let [x2, y2] = p2;
+ // Linear fast path ([0,0]/[1,1] handles).
+ if x1 == y1 && x2 == y2 && x1 == 0.0 && x2 == 1.0 {
+ return t;
+ }
+
+ let mut guess = t;
+ for _ in 0..8 {
+ let error = bezier_component(x1, x2, guess) - t;
+ if error.abs() < 1e-5 {
+ return bezier_component(y1, y2, guess);
+ }
+ let slope = bezier_derivative(x1, x2, guess);
+ if slope.abs() < 1e-6 {
+ break;
+ }
+ guess -= error / slope;
+ }
+
+ let mut lo = 0.0;
+ let mut hi = 1.0;
+ guess = t;
+ for _ in 0..30 {
+ let error = bezier_component(x1, x2, guess) - t;
+ if error.abs() < 1e-5 {
+ break;
+ }
+ if error > 0.0 {
+ hi = guess;
+ } else {
+ lo = guess;
+ }
+ guess = (lo + hi) / 2.0;
+ }
+ bezier_component(y1, y2, guess)
+}
+
+/// Half-extents of the content plane: the longest side spans 2 world units.
+pub fn plane_half_extents(aspect: f64) -> (f64, f64) {
+ let aspect = if aspect.is_finite() && aspect > 0.0 {
+ aspect
+ } else {
+ 1.0
+ };
+ if aspect >= 1.0 {
+ (1.0, 1.0 / aspect)
+ } else {
+ (aspect, 1.0)
+ }
+}
+
+/// The 2D zoom while a 3D pose is active: magnify the card on screen by
+/// `amount` about the zoom target (given as content-frame UV, y-down). The
+/// target eases toward frame center as the magnification grows, matching the
+/// flat zoom's framing.
+#[derive(Clone, Copy, Debug, PartialEq)]
+pub struct Camera3DScreenZoom {
+ pub content_uv: cap_project::XY<f64>,
+ pub amount: f64,
+}
+
+/// Rows of the 3×3 inverse homography mapping y-up NDC (x, y, 1) back to
+/// plane coordinates (X·w, Y·w, w), plus the plane half-extents for UV
+/// mapping in the shader.
+#[derive(Clone, Copy, Debug, PartialEq)]
+pub struct Camera3DHomography {
+ pub inverse_rows: [[f32; 3]; 3],
+ pub half_extents: (f32, f32),
+}
+
+type Mat3 = [[f64; 3]; 3];
+
+fn mat3_mul(a: &Mat3, b: &Mat3) -> Mat3 {
+ let mut out = [[0.0; 3]; 3];
+ for (i, out_row) in out.iter_mut().enumerate() {
+ for (j, cell) in out_row.iter_mut().enumerate() {
+ *cell = (0..3).map(|k| a[i][k] * b[k][j]).sum();
+ }
+ }
+ out
+}
+
+fn rot_x3(theta: f64) -> Mat3 {
+ let (s, c) = theta.sin_cos();
+ [[1.0, 0.0, 0.0], [0.0, c, -s], [0.0, s, c]]
+}
+
+fn rot_y3(theta: f64) -> Mat3 {
+ let (s, c) = theta.sin_cos();
+ [[c, 0.0, s], [0.0, 1.0, 0.0], [-s, 0.0, c]]
+}
+
+fn rot_z3(theta: f64) -> Mat3 {
+ let (s, c) = theta.sin_cos();
+ [[c, -s, 0.0], [s, c, 0.0], [0.0, 0.0, 1.0]]
+}
+
+/// Builds the inverse homography for a pose, or `None` when degenerate.
+/// `screen_zoom` composes the 2D zoom as an NDC magnification of the card.
+pub fn camera3d_inverse_homography(
+ props: &Camera3DProperties,
+ aspect: f64,
+ screen_zoom: Option<&Camera3DScreenZoom>,
+) -> Option<Camera3DHomography> {
+ let aspect = if aspect.is_finite() && aspect > 0.0 {
+ aspect
+ } else {
+ 1.0
+ };
+ let (hx, hy) = plane_half_extents(aspect);
+
+ let fov = props.fov.clamp(1.0, 179.0).to_radians();
+ let f = 1.0 / (fov / 2.0).tan();
+ let zoom = props.zoom.clamp(0.05, 100.0);
+
+ let r_cam = mat3_mul(
+ &rot_y3(props.tilt_y.to_radians()),
+ &mat3_mul(
+ &rot_x3(props.tilt_x.to_radians()),
+ &rot_z3(props.roll.to_radians()),
+ ),
+ );
+ let r_obj = mat3_mul(
+ &rot_y3(props.rotate_y.to_radians()),
+ &rot_x3(props.rotate_x.to_radians()),
+ );
+ let r = mat3_mul(&r_cam, &r_obj);
+
+ // view = R·(X, Y, 0) + (pan_x, pan_y, -zoom); homography on [X, Y, 1]:
+ let fx = f / aspect;
+ let mut forward = [
+ [fx * r[0][0], fx * r[0][1], fx * props.pan_x],
+ [f * r[1][0], f * r[1][1], f * props.pan_y],
+ [-r[2][0], -r[2][1], zoom],
+ ];
+
+ if let Some(screen_zoom) = screen_zoom
+ && screen_zoom.amount > 1.001
+ && screen_zoom.amount.is_finite()
+ {
+ // Project the zoom target (content UV, y-down) to NDC through the
+ // pose, then scale about it. The fixed point slides toward frame
+ // center as `q / amount`, mirroring the flat zoom's centering.
+ let plane_x = (2.0 * screen_zoom.content_uv.x - 1.0) * hx;
+ let plane_y = (1.0 - 2.0 * screen_zoom.content_uv.y) * hy;
+ let w = forward[2][0] * plane_x + forward[2][1] * plane_y + forward[2][2];
+ if w > 1e-6 {
+ let qx = (forward[0][0] * plane_x + forward[0][1] * plane_y + forward[0][2]) / w;
+ let qy = (forward[1][0] * plane_x + forward[1][1] * plane_y + forward[1][2]) / w;
+ let amount = screen_zoom.amount;
+ let recenter = amount - 1.0 / amount;
+ let magnify = [
+ [amount, 0.0, -qx * recenter],
+ [0.0, amount, -qy * recenter],
+ [0.0, 0.0, 1.0],
+ ];
+ forward = mat3_mul(&magnify, &forward);
+ }
+ }
+
+ invert3(&forward).map(|inv| Camera3DHomography {
+ inverse_rows: inv.map(|row| row.map(|v| v as f32)),
+ half_extents: (hx as f32, hy as f32),
+ })
+}
+
+fn invert3(m: &[[f64; 3]; 3]) -> Option<[[f64; 3]; 3]> {
+ let c00 = m[1][1] * m[2][2] - m[1][2] * m[2][1];
+ let c01 = m[1][2] * m[2][0] - m[1][0] * m[2][2];
+ let c02 = m[1][0] * m[2][1] - m[1][1] * m[2][0];
+
+ let det = m[0][0] * c00 + m[0][1] * c01 + m[0][2] * c02;
+ if !det.is_finite() || det.abs() < 1e-12 {
+ return None;
+ }
+ let inv_det = 1.0 / det;
+
+ Some([
+ [
+ c00 * inv_det,
+ (m[0][2] * m[2][1] - m[0][1] * m[2][2]) * inv_det,
+ (m[0][1] * m[1][2] - m[0][2] * m[1][1]) * inv_det,
+ ],
+ [
+ c01 * inv_det,
+ (m[0][0] * m[2][2] - m[0][2] * m[2][0]) * inv_det,
+ (m[0][2] * m[1][0] - m[0][0] * m[1][2]) * inv_det,
+ ],
+ [
+ c02 * inv_det,
+ (m[0][1] * m[2][0] - m[0][0] * m[2][1]) * inv_det,
+ (m[0][0] * m[1][1] - m[0][1] * m[1][0]) * inv_det,
+ ],
+ ])
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use cap_project::{Camera3DBlur, Camera3DTracks};
+
+ const ASPECT: f64 = 16.0 / 9.0;
+ const HY: f64 = 9.0 / 16.0;
+
+ fn apply3(rows: &[[f32; 3]; 3], v: [f64; 3]) -> [f64; 3] {
+ let mut out = [0.0; 3];
+ for (i, row) in rows.iter().enumerate() {
+ out[i] = row.iter().zip(v.iter()).map(|(a, b)| *a as f64 * b).sum();
+ }
+ out
+ }
+
+ fn ndc_to_plane(h: &Camera3DHomography, ndc: [f64; 2]) -> [f64; 2] {
+ let q = apply3(&h.inverse_rows, [ndc[0], ndc[1], 1.0]);
+ assert!(q[2] > 0.0, "point must be in front of the camera");
+ [q[0] / q[2], q[1] / q[2]]
+ }
+
+ fn forward_ndc(h: &Camera3DHomography, plane: [f64; 2]) -> [f64; 2] {
+ let inv = h.inverse_rows.map(|r| r.map(|v| v as f64));
+ let fwd = invert3(&inv).unwrap();
+ let s = apply3(&fwd.map(|r| r.map(|v| v as f32)), [plane[0], plane[1], 1.0]);
+ [s[0] / s[2], s[1] / s[2]]
+ }
+
+ fn assert_close(a: f64, b: f64, eps: f64, label: &str) {
+ assert!((a - b).abs() < eps, "{label}: {a} vs {b}");
+ }
+
+ fn fill_zoom(fov_deg: f64) -> f64 {
+ HY / (fov_deg.to_radians() / 2.0).tan()
+ }
+
+ #[test]
+ fn fill_distance_maps_frame_corners_to_plane_corners() {
+ for fov in [24.0, 45.0, 60.0] {
+ let props = Camera3DProperties {
+ fov,
+ zoom: fill_zoom(fov),
+ ..Default::default()
+ };
+ let h = camera3d_inverse_homography(&props, ASPECT, None).unwrap();
+ let p = ndc_to_plane(&h, [1.0, 1.0]);
+ assert_close(p[0], 1.0, 1e-4, "corner x");
+ assert_close(p[1], HY, 1e-4, "corner y");
+ }
+ }
+
+ #[test]
+ fn default_framing_matches_expected_size() {
+ // fov 45 / zoom 2.25 puts the 16:9 card at ~60% of frame height
+ // (size law: size ∝ 1/(zoom·tan(fov/2))).
+ let props = Camera3DProperties {
+ zoom: 2.25,
+ ..Default::default()
+ };
+ let h = camera3d_inverse_homography(&props, ASPECT, None).unwrap();
+ let top = forward_ndc(&h, [0.0, HY]);
+ assert_close(top[1], 0.6035, 1e-3, "subject half-height in NDC");
+
+ // fov 24 / zoom 4.5 (the reset pose) frames almost identically.
+ let props = Camera3DProperties {
+ fov: 24.0,
+ zoom: 4.5,
+ ..Default::default()
+ };
+ let h = camera3d_inverse_homography(&props, ASPECT, None).unwrap();
+ let top = forward_ndc(&h, [0.0, HY]);
+ assert_close(top[1], 0.5876, 1e-3, "long-lens half-height");
+ }
+
+ #[test]
+ fn fov_is_not_size_compensated() {
+ let at = |fov: f64| {
+ let props = Camera3DProperties {
+ fov,
+ zoom: 2.0,
+ ..Default::default()
+ };
+ let h = camera3d_inverse_homography(&props, ASPECT, None).unwrap();
+ forward_ndc(&h, [0.0, HY])[1]
+ };
+ // Wider fov at the same distance makes the subject smaller.
+ assert!(at(100.0) < at(45.0));
+ assert!(at(45.0) < at(10.0));
+ }
+
+ #[test]
+ fn zoom_is_distance() {
+ let at = |zoom: f64| {
+ let props = Camera3DProperties {
+ zoom,
+ ..Default::default()
+ };
+ let h = camera3d_inverse_homography(&props, ASPECT, None).unwrap();
+ forward_ndc(&h, [0.0, HY])[1]
+ };
+ assert!(at(4.0) < at(2.0), "further away is smaller");
+ assert_close(at(4.0), at(2.0) / 2.0, 1e-6, "size ∝ 1/zoom");
+ }
+
+ #[test]
+ fn pan_moves_subject_in_screen_direction() {
+ let props = Camera3DProperties {
+ pan_x: 0.5,
+ pan_y: 0.25,
+ ..Default::default()
+ };
+ let h = camera3d_inverse_homography(&props, ASPECT, None).unwrap();
+ let center = forward_ndc(&h, [0.0, 0.0]);
+ assert!(center[0] > 0.0, "+pan_x moves subject right");
+ assert!(center[1] > 0.0, "+pan_y moves subject up");
+ }
+
+ #[test]
+ fn screen_zoom_magnifies_about_target() {
+ // Flat pose at the fill distance: the card exactly fills the frame,
+ // so a 2x screen zoom at content center doubles every NDC coordinate.
+ let props = Camera3DProperties {
+ zoom: fill_zoom(45.0),
+ ..Default::default()
+ };
+ let zoom = Camera3DScreenZoom {
+ content_uv: cap_project::XY::new(0.5, 0.5),
+ amount: 2.0,
+ };
+ let h = camera3d_inverse_homography(&props, ASPECT, Some(&zoom)).unwrap();
+ let p = ndc_to_plane(&h, [1.0, 1.0]);
+ assert_close(p[0], 0.5, 1e-4, "half plane x visible");
+ assert_close(p[1], HY / 2.0, 1e-4, "half plane y visible");
+
+ // An off-center target slides toward frame center as q / amount.
+ let zoom = Camera3DScreenZoom {
+ content_uv: cap_project::XY::new(0.75, 0.5),
+ amount: 2.0,
+ };
+ let h = camera3d_inverse_homography(&props, ASPECT, Some(&zoom)).unwrap();
+ // Content u 0.75 sits at plane x 0.5·hx, NDC 0.5 unzoomed.
+ let target = forward_ndc(&h, [0.5, 0.0]);
+ assert_close(target[0], 0.25, 1e-4, "target recenters as q/amount");
+ assert_close(target[1], 0.0, 1e-4, "target y");
+
+ // Amount 1 (or None) leaves the homography untouched.
+ let identity_zoom = Camera3DScreenZoom {
+ content_uv: cap_project::XY::new(0.2, 0.9),
+ amount: 1.0,
+ };
+ let with_zoom =
+ camera3d_inverse_homography(&props, ASPECT, Some(&identity_zoom)).unwrap();
+ let without = camera3d_inverse_homography(&props, ASPECT, None).unwrap();
+ assert_eq!(with_zoom.inverse_rows, without.inverse_rows);
+ }
+
+ #[test]
+ fn tilt_y_positive_recedes_right_edge() {
+ let props = Camera3DProperties {
+ tilt_y: 30.0,
+ ..Default::default()
+ };
+ let h = camera3d_inverse_homography(&props, ASPECT, None).unwrap();
+ let inv = h.inverse_rows.map(|r| r.map(|v| v as f64));
+ let fwd = invert3(&inv).unwrap();
+ let w_right = apply3(&fwd.map(|r| r.map(|v| v as f32)), [1.0, 0.0, 1.0])[2];
+ let w_left = apply3(&fwd.map(|r| r.map(|v| v as f32)), [-1.0, 0.0, 1.0])[2];
+ assert!(w_right > w_left, "right edge should be further away");
+ }
+
+ #[test]
+ fn rotate_x_positive_brings_top_closer() {
+ // Matches the CSS-3D preview (rotateX(-rotateX) in y-down CSS):
+ // positive rotate_x tips the top toward the viewer.
+ let props = Camera3DProperties {
+ rotate_x: 30.0,
+ ..Default::default()
+ };
+ let h = camera3d_inverse_homography(&props, ASPECT, None).unwrap();
+ let inv = h.inverse_rows.map(|r| r.map(|v| v as f64));
+ let fwd = invert3(&inv).unwrap();
+ let w_top = apply3(&fwd.map(|r| r.map(|v| v as f32)), [0.0, HY, 1.0])[2];
+ let w_bottom = apply3(&fwd.map(|r| r.map(|v| v as f32)), [0.0, -HY, 1.0])[2];
+ assert!(w_top < w_bottom, "top should be closer");
+ }
+
+ #[test]
+ fn track_sampling_holds_and_lerps() {
+ let keys = vec![
+ Camera3DKeyframe {
+ time: 1.0,
+ value: 10.0,
+ out_easing: Some([0.0, 0.0]),
+ in_easing: None,
+ },
+ Camera3DKeyframe {
+ time: 3.0,
+ value: 20.0,
+ out_easing: None,
+ in_easing: Some([1.0, 1.0]),
+ },
+ ];
+ assert_eq!(sample_track(5.0, &[], 0.0), 5.0);
+ assert_eq!(sample_track(5.0, &keys, 0.0), 10.0, );
+ // Linear handles ([0,0]/[1,1]) give an exact linear midpoint.
+ assert_close(sample_track(5.0, &keys, 2.0), 15.0, 1e-9, "linear mid");
+ assert_eq!(sample_track(5.0, &keys, 9.0), 20.0);
+ }
+
+ #[test]
+ fn default_handles_are_cubic_ease_in_out() {
+ let keys = vec![
+ Camera3DKeyframe {
+ time: 0.0,
+ value: 0.0,
+ out_easing: None,
+ in_easing: None,
+ },
+ Camera3DKeyframe {
+ time: 1.0,
+ value: 1.0,
+ out_easing: None,
+ in_easing: None,
+ },
+ ];
+ // cubic-bezier(0.65, 0, 0.35, 1): slow start, midpoint exactly 0.5.
+ let quarter = sample_track(0.0, &keys, 0.25);
+ assert!(quarter < 0.15, "eased quarter should lag linear, got {quarter}");
+ assert_close(sample_track(0.0, &keys, 0.5), 0.5, 1e-4, "eased mid");
+ }
+
+ fn segment() -> Camera3DSegment {
+ Camera3DSegment {
+ start: 2.0,
+ end: 8.0,
+ enabled: true,
+ properties: Camera3DProperties {
+ tilt_y: 26.0,
+ tilt_x: -28.0,
+ zoom: 1.59,
+ ..Default::default()
+ },
+ blur: Camera3DBlur::default(),
+ tracks: Camera3DTracks::default(),
+ transition_in: 0.5,
+ transition_out: 0.5,
+ }
+ }
+
+ #[test]
+ fn outside_segments_is_none() {
+ assert!(interpolate_camera3d(1.0, &[segment()], ASPECT).is_none());
+ assert!(interpolate_camera3d(9.0, &[segment()], ASPECT).is_none());
+ assert!(interpolate_camera3d(5.0, &[], ASPECT).is_none());
+ }
+
+ #[test]
+ fn segment_edges_ramp_from_flat() {
+ let seg = segment();
+ // At the exact edge the pose is flat (skipped) and blur is off.
+ let frame = interpolate_camera3d(2.0, std::slice::from_ref(&seg), ASPECT).unwrap();
+ assert!(frame.pose.is_none());
+ assert!(frame.blur.is_none());
+
+ let mid_ramp = interpolate_camera3d(2.25, std::slice::from_ref(&seg), ASPECT)
+ .unwrap()
+ .pose
+ .unwrap();
+ assert!(mid_ramp.tilt_y > 0.0 && mid_ramp.tilt_y < 26.0);
+ // The ramp dollies from the fill distance toward the pose zoom.
+ let fill = fill_zoom(45.0);
+ let (lo, hi) = (fill.min(1.59), fill.max(1.59));
+ assert!(
+ mid_ramp.zoom > lo && mid_ramp.zoom < hi,
+ "mid-ramp zoom {} should sit between {lo} and {hi}",
+ mid_ramp.zoom
+ );
+
+ let settled = interpolate_camera3d(5.0, std::slice::from_ref(&seg), ASPECT)
+ .unwrap()
+ .pose
+ .unwrap();
+ assert_close(settled.tilt_y, 26.0, 1e-9, "settled tilt_y");
+ assert_close(settled.zoom, 1.59, 1e-9, "settled zoom");
+ }
+
+ #[test]
+ fn blur_requires_mode_and_strength() {
+ let mut seg = segment();
+ seg.transition_in = 0.0;
+ seg.transition_out = 0.0;
+ seg.blur.strength = 19.0;
+ // Mode none: no blur even with strength.
+ let frame = interpolate_camera3d(5.0, std::slice::from_ref(&seg), ASPECT).unwrap();
+ assert!(frame.blur.is_none());
+
+ seg.blur.mode = Camera3DBlurMode::Radial;
+ let frame = interpolate_camera3d(5.0, std::slice::from_ref(&seg), ASPECT).unwrap();
+ let blur = frame.blur.unwrap();
+ assert_close(blur.strength, 19.0, 1e-9, "blur strength");
+
+ // Bokeh caps strength at 20.
+ seg.blur.bokeh = true;
+ seg.blur.strength = 45.0;
+ let frame = interpolate_camera3d(5.0, std::slice::from_ref(&seg), ASPECT).unwrap();
+ assert_close(frame.blur.unwrap().strength, 20.0, 1e-9, "bokeh cap");
+ }
+
+ #[test]
+ fn blur_is_keyframable() {
+ let mut seg = segment();
+ seg.transition_in = 0.0;
+ seg.transition_out = 0.0;
+ seg.blur.mode = Camera3DBlurMode::TiltShift;
+ seg.tracks.blur_strength = vec![
+ Camera3DKeyframe {
+ time: 0.0,
+ value: 0.0,
+ out_easing: Some([0.0, 0.0]),
+ in_easing: None,
+ },
+ Camera3DKeyframe {
+ time: 6.0,
+ value: 30.0,
+ out_easing: None,
+ in_easing: Some([1.0, 1.0]),
+ },
+ ];
+ let frame = interpolate_camera3d(5.0, std::slice::from_ref(&seg), ASPECT).unwrap();
+ assert_close(frame.blur.unwrap().strength, 15.0, 1e-6, "keyed strength");
+ }
+}
diff --git a/crates/rendering/src/layers/camera3d.rs b/crates/rendering/src/layers/camera3d.rs
new file mode 100644
index 000000000..ea9b32754
--- /dev/null
+++ b/crates/rendering/src/layers/camera3d.rs
@@ -0,0 +1,432 @@
+use bytemuck::{Pod, Zeroable};
+use wgpu::util::DeviceExt;
+
+use crate::ProjectUniforms;
+use crate::camera3d::{CAMERA3D_BLUR_BASE_HEIGHT, camera3d_inverse_homography};
+use cap_project::Camera3DBlurMode;
+
+/// Which blur kernel runs this frame.
+#[derive(Clone, Copy, PartialEq, Eq)]
+pub enum Camera3DBlurKind {
+ /// Separable gaussian: horizontal pass then vertical pass.
+ Gaussian,
+ /// Single-pass ring-disc bokeh.
+ Bokeh,
+}
+
+/// Warps the composed content texture through the timeline's 3D camera pose
+/// and applies a screen-space focus blur.
+/// See `shaders/camera3d.wgsl` and `shaders/camera3d-blur.wgsl`.
+pub struct Camera3DLayer {
+ warp_active: bool,
+ blur_kind: Option<Camera3DBlurKind>,
+ sampler: wgpu::Sampler,
+ warp_uniforms_buffer: wgpu::Buffer,
+ warp_pipeline: Camera3DPipeline,
+ cached_warp_uniforms: Option<Camera3DUniforms>,
+ // Separate H/V buffers: both passes are encoded before submission, so a
+ // single buffer would make the H pass read the V parameters.
+ blur_h_buffer: wgpu::Buffer,
+ blur_v_buffer: wgpu::Buffer,
+ blur_pipeline: Camera3DBlurPipeline,
+ cached_blur_uniforms: Option<(Camera3DBlurUniforms, Camera3DBlurUniforms)>,
+}
+
+impl Camera3DLayer {
+ pub fn new(device: &wgpu::Device) -> Self {
+ let make_blur_buffer = |label: &str| {
+ device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
+ label: Some(label),
+ contents: bytemuck::cast_slice(&[Camera3DBlurUniforms::default()]),
+ usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
+ })
+ };
+ Self {
+ warp_active: false,
+ blur_kind: None,
+ sampler: device.create_sampler(&wgpu::SamplerDescriptor {
+ address_mode_u: wgpu::AddressMode::ClampToEdge,
+ address_mode_v: wgpu::AddressMode::ClampToEdge,
+ address_mode_w: wgpu::AddressMode::ClampToEdge,
+ mag_filter: wgpu::FilterMode::Linear,
+ min_filter: wgpu::FilterMode::Linear,
+ mipmap_filter: wgpu::FilterMode::Nearest,
+ ..Default::default()
+ }),
+ warp_uniforms_buffer: device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
+ label: Some("Camera3D Uniform Buffer"),
+ contents: bytemuck::cast_slice(&[Camera3DUniforms::default()]),
+ usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
+ }),
+ warp_pipeline: Camera3DPipeline::new(device),
+ cached_warp_uniforms: None,
+ blur_h_buffer: make_blur_buffer("Camera3D Blur H Uniform Buffer"),
+ blur_v_buffer: make_blur_buffer("Camera3D Blur V Uniform Buffer"),
+ blur_pipeline: Camera3DBlurPipeline::new(device),
+ cached_blur_uniforms: None,
+ }
+ }
+
+ /// Whether the warp pass should run this frame.
+ pub fn is_active(&self) -> bool {
+ self.warp_active
+ }
+
+ pub fn blur_kind(&self) -> Option<Camera3DBlurKind> {
+ self.blur_kind
+ }
+
+ pub fn prepare(&mut self, queue: &wgpu::Queue, uniforms: &ProjectUniforms) {
+ self.warp_active = false;
+ self.blur_kind = None;
+
+ let Some(frame) = uniforms.camera3d else {
+ return;
+ };
+ let (out_w, out_h) = (uniforms.output_size.0.max(1), uniforms.output_size.1.max(1));
+ let aspect = out_w as f64 / out_h as f64;
+
+ if let Some(pose) = frame.pose
+ && let Some(homography) = camera3d_inverse_homography(&pose, aspect, uniforms.camera3d_zoom.as_ref())
+ {
+ let rows = homography.inverse_rows;
+ let (hx, hy) = homography.half_extents;
+ let warp_uniforms = Camera3DUniforms {
+ inv_row0: [rows[0][0], rows[0][1], rows[0][2], 0.0],
+ inv_row1: [rows[1][0], rows[1][1], rows[1][2], hx],
+ inv_row2: [rows[2][0], rows[2][1], rows[2][2], hy],
+ };
+
+ if self.cached_warp_uniforms.as_ref() != Some(&warp_uniforms) {
+ queue.write_buffer(
+ &self.warp_uniforms_buffer,
+ 0,
+ bytemuck::cast_slice(&[warp_uniforms]),
+ );
+ self.cached_warp_uniforms = Some(warp_uniforms);
+ }
+ self.warp_active = true;
+ }
+
+ if let Some(blur) = frame.blur {
+ // Strength is authored at 1080p output height; scale so preview
+ // and export produce the same look.
+ let strength_px = (blur.strength * out_h as f64 / CAMERA3D_BLUR_BASE_HEIGHT) as f32;
+ let mode = match blur.mode {
+ Camera3DBlurMode::None => return,
+ Camera3DBlurMode::Radial => 1.0,
+ Camera3DBlurMode::Directional => 2.0,
+ Camera3DBlurMode::TiltShift => 3.0,
+ };
+ let params = |pass: f32| Camera3DBlurUniforms {
+ params0: [pass, mode, strength_px, blur.falloff as f32],
+ params1: [
+ blur.focus_x as f32,
+ blur.focus_y as f32,
+ blur.focus_size as f32,
+ blur.angle as f32,
+ ],
+ params2: [blur.dir_position as f32, out_w as f32, out_h as f32, 0.0],
+ };
+ let (h, v) = if blur.bokeh {
+ // Bokeh is single-pass; only the "V" slot is used.
+ (params(2.0), params(2.0))
+ } else {
+ (params(0.0), params(1.0))
+ };
+
+ if self.cached_blur_uniforms.as_ref() != Some(&(h, v)) {
+ if !blur.bokeh {
+ // Bokeh never reads the H buffer (lib.rs only runs the V
+ // pass for it), so skip the redundant upload.
+ queue.write_buffer(&self.blur_h_buffer, 0, bytemuck::cast_slice(&[h]));
+ }
+ queue.write_buffer(&self.blur_v_buffer, 0, bytemuck::cast_slice(&[v]));
+ self.cached_blur_uniforms = Some((h, v));
+ }
+ self.blur_kind = Some(if blur.bokeh {
+ Camera3DBlurKind::Bokeh
+ } else {
+ Camera3DBlurKind::Gaussian
+ });
+ }
+ }
+
+ pub fn render(
+ &self,
+ pass: &mut wgpu::RenderPass<'_>,
+ device: &wgpu::Device,
+ content_texture: &wgpu::TextureView,
+ ) {
+ pass.set_pipeline(&self.warp_pipeline.render_pipeline);
+ pass.set_bind_group(
+ 0,
+ &self.warp_pipeline.bind_group(
+ device,
+ &self.warp_uniforms_buffer,
+ content_texture,
+ &self.sampler,
+ ),
+ &[],
+ );
+ pass.draw(0..3, 0..1);
+ }
+
+ /// Horizontal gaussian pass (or the single bokeh pass, which uses the V
+ /// buffer via [`Self::render_blur_v`] instead).
+ pub fn render_blur_h(
+ &self,
+ pass: &mut wgpu::RenderPass<'_>,
+ device: &wgpu::Device,
+ source_texture: &wgpu::TextureView,
+ ) {
+ self.render_blur(pass, device, &self.blur_h_buffer, source_texture);
+ }
+
+ pub fn render_blur_v(
+ &self,
+ pass: &mut wgpu::RenderPass<'_>,
+ device: &wgpu::Device,
+ source_texture: &wgpu::TextureView,
+ ) {
+ self.render_blur(pass, device, &self.blur_v_buffer, source_texture);
+ }
+
+ fn render_blur(
+ &self,
+ pass: &mut wgpu::RenderPass<'_>,
+ device: &wgpu::Device,
+ buffer: &wgpu::Buffer,
+ source_texture: &wgpu::TextureView,
+ ) {
+ pass.set_pipeline(&self.blur_pipeline.render_pipeline);
+ pass.set_bind_group(
+ 0,
+ &self
+ .blur_pipeline
+ .bind_group(device, buffer, source_texture, &self.sampler),
+ &[],
+ );
+ pass.draw(0..3, 0..1);
+ }
+}
+
+#[repr(C)]
+#[derive(Debug, Clone, Copy, Pod, Zeroable, Default, PartialEq)]
+struct Camera3DUniforms {
+ inv_row0: [f32; 4],
+ inv_row1: [f32; 4],
+ inv_row2: [f32; 4],
+}
+
+#[repr(C)]
+#[derive(Debug, Clone, Copy, Pod, Zeroable, Default, PartialEq)]
+struct Camera3DBlurUniforms {
+ params0: [f32; 4],
+ params1: [f32; 4],
+ params2: [f32; 4],
+}
+
+fn make_bind_group_layout(device: &wgpu::Device, label: &str) -> wgpu::BindGroupLayout {
+ device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
+ label: Some(label),
+ entries: &[
+ wgpu::BindGroupLayoutEntry {
+ binding: 0,
+ visibility: wgpu::ShaderStages::VERTEX_FRAGMENT,
+ ty: wgpu::BindingType::Buffer {
+ ty: wgpu::BufferBindingType::Uniform,
+ has_dynamic_offset: false,
+ min_binding_size: None,
+ },
+ count: None,
+ },
+ wgpu::BindGroupLayoutEntry {
+ binding: 1,
+ visibility: wgpu::ShaderStages::FRAGMENT,
+ ty: wgpu::BindingType::Texture {
+ sample_type: wgpu::TextureSampleType::Float { filterable: true },
+ view_dimension: wgpu::TextureViewDimension::D2,
+ multisampled: false,
+ },
+ count: None,
+ },
+ wgpu::BindGroupLayoutEntry {
+ binding: 2,
+ visibility: wgpu::ShaderStages::FRAGMENT,
+ ty: wgpu::BindingType::Sampler(wgpu::SamplerBindingType::Filtering),
+ count: None,
+ },
+ ],
+ })
+}
+
+fn make_pipeline(
+ device: &wgpu::Device,
+ label: &str,
+ shader: wgpu::ShaderModuleDescriptor<'_>,
+ layout: &wgpu::BindGroupLayout,
+ blend: wgpu::BlendState,
+) -> wgpu::RenderPipeline {
+ let shader = device.create_shader_module(shader);
+ let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
+ label: Some(label),
+ bind_group_layouts: &[layout],
+ push_constant_ranges: &[],
+ });
+ device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
+ label: Some(label),
+ layout: Some(&pipeline_layout),
+ vertex: wgpu::VertexState {
+ module: &shader,
+ entry_point: Some("vs_main"),
+ buffers: &[],
+ compilation_options: wgpu::PipelineCompilationOptions {
+ constants: &[],
+ zero_initialize_workgroup_memory: false,
+ },
+ },
+ fragment: Some(wgpu::FragmentState {
+ module: &shader,
+ entry_point: Some("fs_main"),
+ targets: &[Some(wgpu::ColorTargetState {
+ format: wgpu::TextureFormat::Rgba8Unorm,
+ blend: Some(blend),
+ write_mask: wgpu::ColorWrites::ALL,
+ })],
+ compilation_options: wgpu::PipelineCompilationOptions {
+ constants: &[],
+ zero_initialize_workgroup_memory: false,
+ },
+ }),
+ primitive: wgpu::PrimitiveState {
+ topology: wgpu::PrimitiveTopology::TriangleList,
+ strip_index_format: None,
+ front_face: wgpu::FrontFace::Ccw,
+ cull_mode: None,
+ polygon_mode: wgpu::PolygonMode::Fill,
+ unclipped_depth: false,
+ conservative: false,
+ },
+ depth_stencil: None,
+ multisample: wgpu::MultisampleState::default(),
+ multiview: None,
+ cache: None,
+ })
+}
+
+fn make_bind_group(
+ device: &wgpu::Device,
+ label: &str,
+ layout: &wgpu::BindGroupLayout,
+ uniform_buffer: &wgpu::Buffer,
+ texture_view: &wgpu::TextureView,
+ sampler: &wgpu::Sampler,
+) -> wgpu::BindGroup {
+ device.create_bind_group(&wgpu::BindGroupDescriptor {
+ label: Some(label),
+ layout,
+ entries: &[
+ wgpu::BindGroupEntry {
+ binding: 0,
+ resource: uniform_buffer.as_entire_binding(),
+ },
+ wgpu::BindGroupEntry {
+ binding: 1,
+ resource: wgpu::BindingResource::TextureView(texture_view),
+ },
+ wgpu::BindGroupEntry {
+ binding: 2,
+ resource: wgpu::BindingResource::Sampler(sampler),
+ },
+ ],
+ })
+}
+
+struct Camera3DPipeline {
+ bind_group_layout: wgpu::BindGroupLayout,
+ render_pipeline: wgpu::RenderPipeline,
+}
+
+impl Camera3DPipeline {
+ fn new(device: &wgpu::Device) -> Self {
+ let bind_group_layout = make_bind_group_layout(device, "camera3d Bind Group Layout");
+ let render_pipeline = make_pipeline(
+ device,
+ "Camera3D Pipeline",
+ wgpu::ShaderModuleDescriptor {
+ label: Some("Camera3D Shader"),
+ source: wgpu::ShaderSource::Wgsl(include_str!("../shaders/camera3d.wgsl").into()),
+ },
+ &bind_group_layout,
+ // The content texture is premultiplied; composite it over the
+ // background that's already in the target.
+ wgpu::BlendState::PREMULTIPLIED_ALPHA_BLENDING,
+ );
+ Self {
+ bind_group_layout,
+ render_pipeline,
+ }
+ }
+
+ fn bind_group(
+ &self,
+ device: &wgpu::Device,
+ uniform_buffer: &wgpu::Buffer,
+ texture_view: &wgpu::TextureView,
+ sampler: &wgpu::Sampler,
+ ) -> wgpu::BindGroup {
+ make_bind_group(
+ device,
+ "Camera3D Bind Group",
+ &self.bind_group_layout,
+ uniform_buffer,
+ texture_view,
+ sampler,
+ )
+ }
+}
+
+struct Camera3DBlurPipeline {
+ bind_group_layout: wgpu::BindGroupLayout,
+ render_pipeline: wgpu::RenderPipeline,
+}
+
+impl Camera3DBlurPipeline {
+ fn new(device: &wgpu::Device) -> Self {
+ let bind_group_layout = make_bind_group_layout(device, "camera3d-blur Bind Group Layout");
+ let render_pipeline = make_pipeline(
+ device,
+ "Camera3D Blur Pipeline",
+ wgpu::ShaderModuleDescriptor {
+ label: Some("Camera3D Blur Shader"),
+ source: wgpu::ShaderSource::Wgsl(
+ include_str!("../shaders/camera3d-blur.wgsl").into(),
+ ),
+ },
+ &bind_group_layout,
+ wgpu::BlendState::REPLACE,
+ );
+ Self {
+ bind_group_layout,
+ render_pipeline,
+ }
+ }
+
+ fn bind_group(
+ &self,
+ device: &wgpu::Device,
+ uniform_buffer: &wgpu::Buffer,
+ texture_view: &wgpu::TextureView,
+ sampler: &wgpu::Sampler,
+ ) -> wgpu::BindGroup {
+ make_bind_group(
+ device,
+ "Camera3D Blur Bind Group",
+ &self.bind_group_layout,
+ uniform_buffer,
+ texture_view,
+ sampler,
+ )
+ }
+}
diff --git a/crates/rendering/src/layers/mod.rs b/crates/rendering/src/layers/mod.rs
index 258af84ed..cb96d8b4d 100644
--- a/crates/rendering/src/layers/mod.rs
+++ b/crates/rendering/src/layers/mod.rs
@@ -1,6 +1,7 @@
mod background;
mod blur;
mod camera;
+mod camera3d;
mod captions;
mod cursor;
mod display;
@@ -64,6 +65,7 @@ pub(crate) fn new_font_system() -> glyphon::FontSystem {
pub use background::*;
pub use blur::*;
pub use camera::*;
+pub use camera3d::*;
pub use captions::*;
pub use cursor::*;
pub use display::*;
diff --git a/crates/rendering/src/lib.rs b/crates/rendering/src/lib.rs
index eb41f1116..df9d3c720 100644
--- a/crates/rendering/src/lib.rs
+++ b/crates/rendering/src/lib.rs
@@ -17,8 +17,9 @@ use frame_pipeline::{
};
use futures::future::OptionFuture;
use layers::{
- Background, BackgroundLayer, BlurLayer, CameraLayer, CaptionsLayer, CursorLayer, DisplayLayer,
- FrameLayer, KeyboardLayer, MaskLayer, NotchLayer, NotchUniforms, TextLayer,
+ Background, BackgroundLayer, BlurLayer, Camera3DBlurKind, Camera3DLayer, CameraLayer,
+ CaptionsLayer, CursorLayer, DisplayLayer, FrameLayer, KeyboardLayer, MaskLayer, NotchLayer,
+ NotchUniforms, TextLayer,
};
use specta::Type;
use spring_mass_damper::SpringMassDamperSimulationConfig;
@@ -29,6 +30,7 @@ use std::sync::{
use std::{path::PathBuf, time::Instant};
use tokio::sync::mpsc;
+pub mod camera3d;
pub mod composite_frame;
mod coord;
pub mod cpu_yuv;
@@ -68,6 +70,7 @@ pub fn prewarm_fonts() {
drop(layers::new_font_system());
}
+use camera3d::{Camera3DFrame, interpolate_camera3d};
pub use cursor_interpolation::PrecomputedCursorTimeline;
use mask::interpolate_masks;
use scene::*;
@@ -2262,6 +2265,12 @@ pub struct ProjectUniforms {
pub motion_blur_amount: f32,
pub masks: Vec<PreparedMask>,
pub texts: Vec<PreparedText>,
+ /// Effective 3D camera state for this frame; `None` when the frame is
+ /// outside every 3d segment (the warp and blur passes are skipped).
+ pub camera3d: Option<Camera3DFrame>,
+ /// The 2D zoom re-expressed as an on-screen card magnification while a 3D
+ /// pose is active (the display itself renders unzoomed into the card).
+ pub camera3d_zoom: Option<camera3d::Camera3DScreenZoom>,
}
#[derive(Debug, Clone)]
@@ -3348,6 +3357,35 @@ impl ProjectUniforms {
scene_segments,
));
+ let camera3d = project.timeline.as_ref().and_then(|timeline| {
+ interpolate_camera3d(
+ frame_time as f64,
+ &timeline.camera3d_segments,
+ output_size.0 as f64 / output_size.1.max(1) as f64,
+ )
+ });
+ // The card's flat drop shadow is baked into the warped texture, so in
+ // 3D it would rotate with the plane and clip at the texture edge.
+ // A floating card has no baked shadow, so fade ours out.
+ let camera3d_shadow_fade = 1.0 - camera3d.map_or(0.0, |c| c.activity) as f32;
+
+ // While a 3D pose is active the 2D zoom must not crop the display
+ // inside the card texture (the crop edge reads as the card arbitrarily
+ // cutting content off). The content renders unzoomed and the sampled
+ // zoom becomes a screen-space magnification of the whole card about
+ // the zoom target instead (see `camera3d_zoom` below).
+ let camera3d_pose_active = camera3d.as_ref().is_some_and(|c| c.pose.is_some());
+ let raw_zoom = zoom;
+ let (zoom, prev_zoom, motion_prev_zoom) = if camera3d_pose_active {
+ (
+ InterpolatedZoom::default(),
+ InterpolatedZoom::default(),
+ InterpolatedZoom::default(),
+ )
+ } else {
+ (zoom, prev_zoom, motion_prev_zoom)
+ };
+
// Resolve the side-by-side layout once and share it with the display,
// camera and cursor layers. Only engages when a camera actually exists;
// otherwise the layers render normally (graceful full-screen fallback).
@@ -3467,6 +3505,7 @@ impl ProjectUniforms {
None
};
+ let mut camera3d_zoom: Option<camera3d::Camera3DScreenZoom> = None;
let (display, display_motion_parent, frame_chrome, display_outer_bounds, notch) = {
let output_size = XY::new(output_size.0 as f64, output_size.1 as f64);
let size = [options.screen_size.x as f32, options.screen_size.y as f32];
@@ -3485,6 +3524,27 @@ impl ProjectUniforms {
let display_size = Coord::<FrameSpace>::new(layout.content_size);
let frame_config = project.background.frame.clone().filter(|f| f.is_active());
+ if camera3d_pose_active {
+ // Re-express the (neutralized) 2D zoom as a magnification of
+ // the whole card about the zoom target's on-card position.
+ let bounds = raw_zoom.bounds;
+ let span = bounds.bottom_right - bounds.top_left;
+ let amount = ((span.x + span.y) / 2.0).max(1.0);
+ if amount > 1.001 {
+ let center_u = (0.5 - bounds.top_left.x) / span.x.max(1e-6);
+ let center_v = (0.5 - bounds.top_left.y) / span.y.max(1e-6);
+ let frame_x = display_offset.coord.x + center_u * display_size.coord.x;
+ let frame_y = display_offset.coord.y + center_v * display_size.coord.y;
+ camera3d_zoom = Some(camera3d::Camera3DScreenZoom {
+ content_uv: XY::new(
+ frame_x / output_size.x.max(1.0),
+ frame_y / output_size.y.max(1.0),
+ ),
+ amount,
+ });
+ }
+ }
+
let (start, end) = Self::display_bounds(&zoom, display_offset, display_size);
let (prev_start, prev_end) =
Self::display_bounds(&motion_prev_zoom, display_offset, display_size);
@@ -3631,7 +3691,7 @@ impl ProjectUniforms {
0.0,
],
shadow: if decorated {
- project.background.shadow * split_fade
+ project.background.shadow * split_fade * camera3d_shadow_fade
} else {
0.0
},
@@ -3645,7 +3705,8 @@ impl ProjectUniforms {
.advanced_shadow
.as_ref()
.map_or(18.0, |s| s.opacity)
- * split_fade,
+ * split_fade
+ * camera3d_shadow_fade,
shadow_blur: project
.background
.advanced_shadow
@@ -3744,7 +3805,9 @@ impl ProjectUniforms {
descriptor.zoom_amount,
0.0,
],
- shadow: project.background.shadow * display_decoration_fade,
+ shadow: project.background.shadow
+ * display_decoration_fade
+ * camera3d_shadow_fade,
shadow_size: project
.background
.advanced_shadow
@@ -3755,7 +3818,8 @@ impl ProjectUniforms {
.advanced_shadow
.as_ref()
.map_or(18.0, |s| s.opacity)
- * display_decoration_fade,
+ * display_decoration_fade
+ * camera3d_shadow_fade,
shadow_blur: project
.background
.advanced_shadow
@@ -3949,7 +4013,7 @@ impl ProjectUniforms {
camera_descriptor.zoom_amount,
0.0,
],
- shadow: project.camera.shadow * chrome_fade,
+ shadow: project.camera.shadow * chrome_fade * camera3d_shadow_fade,
shadow_size: project
.camera
.advanced_shadow
@@ -3960,7 +4024,8 @@ impl ProjectUniforms {
.advanced_shadow
.as_ref()
.map_or(18.0, |s| s.opacity)
- * chrome_fade,
+ * chrome_fade
+ * camera3d_shadow_fade,
shadow_blur: project
.camera
.advanced_shadow
@@ -4122,6 +4187,8 @@ impl ProjectUniforms {
motion_blur_amount: cursor_motion_blur,
masks,
texts,
+ camera3d,
+ camera3d_zoom,
}
}
}
@@ -5191,6 +5258,7 @@ pub struct RendererLayers {
text: TextLayer,
captions: CaptionsLayer,
keyboard: KeyboardLayer,
+ camera3d: Camera3DLayer,
camera_blur_processor: Option<cap_camera_effects::BlurProcessor>,
camera_blur_init_failed: bool,
}
@@ -5235,6 +5303,7 @@ impl RendererLayers {
text: TextLayer::new(device, queue),
captions: CaptionsLayer::new(device, queue),
keyboard: KeyboardLayer::new(device, queue),
+ camera3d: Camera3DLayer::new(device),
camera_blur_processor: None,
camera_blur_init_failed: false,
}
@@ -5637,6 +5706,8 @@ impl RendererLayers {
);
timings.keyboard_prepare_duration = start.elapsed();
+ self.camera3d.prepare(&constants.queue, uniforms);
+
Ok(timings)
}
@@ -5699,31 +5770,53 @@ impl RendererLayers {
true
};
+ // When a 3D camera pose is active, the content group (frame chrome,
+ // display, cursor, notch, camera) renders into the spare ping-pong
+ // texture, and the camera3d pass then warps it over the untouched
+ // background. Overlay annotations (masks, text, keyboard, captions)
+ // stay flat on top. When inactive this is exactly the flat path.
+ let camera3d_active = self.camera3d.is_active();
+ if camera3d_active {
+ let _pass = render_pass!(
+ session.other_texture_view(),
+ wgpu::LoadOp::Clear(wgpu::Color::TRANSPARENT)
+ );
+ }
+ macro_rules! content_view {
+ () => {
+ if camera3d_active {
+ session.other_texture_view()
+ } else {
+ session.current_texture_view()
+ }
+ };
+ }
+
if should_render_screen && self.frame.has_content() {
- let mut pass = render_pass!(session.current_texture_view(), wgpu::LoadOp::Load);
+ let mut pass = render_pass!(content_view!(), wgpu::LoadOp::Load);
self.frame.render(&mut pass);
}
if should_render_screen {
- let mut pass = render_pass!(session.current_texture_view(), wgpu::LoadOp::Load);
+ let mut pass = render_pass!(content_view!(), wgpu::LoadOp::Load);
self.display.render(&mut pass);
}
if should_render_cursor {
- let mut pass = render_pass!(session.current_texture_view(), wgpu::LoadOp::Load);
+ let mut pass = render_pass!(content_view!(), wgpu::LoadOp::Load);
self.cursor.render(&mut pass);
}
// After the cursor, which really does disappear behind the notch on a
// Mac, but before masks and text, which are editor annotations.
if should_render_screen && self.notch.has_content() {
- let mut pass = render_pass!(session.current_texture_view(), wgpu::LoadOp::Load);
+ let mut pass = render_pass!(content_view!(), wgpu::LoadOp::Load);
self.notch.render(&mut pass);
}
// Render camera-only layer when transitioning with CameraOnly mode
if uniforms.scene.is_transitioning_camera_only() {
- let mut pass = render_pass!(session.current_texture_view(), wgpu::LoadOp::Load);
+ let mut pass = render_pass!(content_view!(), wgpu::LoadOp::Load);
self.camera_only.render(&mut pass);
}
@@ -5731,10 +5824,46 @@ impl RendererLayers {
if uniforms.scene.should_render_camera()
&& uniforms.scene.regular_camera_transition_opacity() > 0.01
{
- let mut pass = render_pass!(session.current_texture_view(), wgpu::LoadOp::Load);
+ let mut pass = render_pass!(content_view!(), wgpu::LoadOp::Load);
self.camera.render(&mut pass);
}
+ if camera3d_active {
+ let mut pass = render_pass!(session.current_texture_view(), wgpu::LoadOp::Load);
+ self.camera3d
+ .render(&mut pass, device, session.other_texture_view());
+ }
+
+ // Focus blur over the composed frame (background and warped content
+ // together), before the flat annotations.
+ match self.camera3d.blur_kind() {
+ Some(Camera3DBlurKind::Gaussian) => {
+ {
+ let mut pass = render_pass!(session.other_texture_view(), wgpu::LoadOp::Load);
+ self.camera3d.render_blur_h(
+ &mut pass,
+ device,
+ session.current_texture_view(),
+ );
+ }
+ let mut pass = render_pass!(session.current_texture_view(), wgpu::LoadOp::Load);
+ self.camera3d
+ .render_blur_v(&mut pass, device, session.other_texture_view());
+ }
+ Some(Camera3DBlurKind::Bokeh) => {
+ {
+ let mut pass = render_pass!(session.other_texture_view(), wgpu::LoadOp::Load);
+ self.camera3d.render_blur_v(
+ &mut pass,
+ device,
+ session.current_texture_view(),
+ );
+ }
+ session.swap_textures();
+ }
+ None => {}
+ }
+
if !uniforms.masks.is_empty() {
for mask in &uniforms.masks {
self.mask.render(device, queue, session, encoder, mask);
diff --git a/crates/rendering/src/shaders/camera3d-blur.wgsl b/crates/rendering/src/shaders/camera3d-blur.wgsl
new file mode 100644
index 000000000..4ab74b697
--- /dev/null
+++ b/crates/rendering/src/shaders/camera3d-blur.wgsl
@@ -0,0 +1,174 @@
+// Screen-space focus blur system.
+//
+// The "depth of field" is a UV-mask variable-radius blur: a per-pixel CoC
+// (blur radius in output pixels) computed from the focus configuration, fed to
+// either a separable gaussian (two passes, pass 0 = horizontal, pass 1 =
+// vertical) or a single-pass ring-disc bokeh kernel with highlight gain
+// (pass 2). Runs on the fully composed frame; the sharp region is wherever
+// the focus mask says it is, exactly like the original.
+//
+// params0: (pass, mode, strength_px, falloff)
+// pass: 0 = gaussian H, 1 = gaussian V, 2 = bokeh
+// mode: 1 = radial, 2 = directional, 3 = tilt-shift
+// strength_px: blur radius, already scaled to this render resolution
+// params1: (focus_x, focus_y, focus_size, angle_rad)
+// params2: (dir_position, resolution_x, resolution_y, unused)
+//
+// Focus coordinates and angles work in GL-style UV space (origin bottom-left,
+// y up), matching the original shaders; screen_uv is converted on entry.
+
+struct Camera3DBlurUniforms {
+ params0: vec4<f32>,
+ params1: vec4<f32>,
+ params2: vec4<f32>,
+};
+
+@group(0) @binding(0) var<uniform> u: Camera3DBlurUniforms;
+@group(0) @binding(1) var t_source: texture_2d<f32>;
+@group(0) @binding(2) var s_source: sampler;
+
+struct VertexOutput {
+ @builtin(position) position: vec4<f32>,
+ @location(0) screen_uv: vec2<f32>,
+};
+
+@vertex
+fn vs_main(@builtin(vertex_index) vertex_index: u32) -> VertexOutput {
+ let uv = vec2<f32>(
+ f32((vertex_index << 1u) & 2u),
+ f32(vertex_index & 2u),
+ );
+ var out: VertexOutput;
+ out.position = vec4<f32>(uv * 2.0 - 1.0, 0.0, 1.0);
+ out.screen_uv = vec2<f32>(uv.x, 1.0 - uv.y);
+ return out;
+}
+
+// CoC (circle of confusion) function.
+fn blur_amount(gl_uv: vec2<f32>) -> f32 {
+ let mode = u.params0.y;
+ let strength = u.params0.z;
+ let falloff = u.params0.w;
+ let resolution = u.params2.yz;
+ let aspect = resolution.x / max(resolution.y, 1.0);
+
+ let widen = 1.0 + falloff * 3.0;
+ let curve = mix(2.0, 0.7, falloff);
+
+ if (mode == 2.0) {
+ // Directional: one-sided blur past a line through frame center.
+ let angle = u.params1.w;
+ let dir = vec2<f32>(cos(angle), sin(angle));
+ var diff = gl_uv - vec2<f32>(0.5);
+ diff.x = diff.x * aspect;
+ let projected = dot(diff, dir);
+ let reach = aspect * 0.5 + 0.5;
+ let threshold = mix(-reach, reach, u.params2.x);
+ let d = max(projected - threshold, 0.0);
+ let t = smoothstep(0.0, 0.7 * widen, d);
+ return pow(t, curve) * strength;
+ }
+
+ var diff = gl_uv - u.params1.xy;
+ diff.x = diff.x * aspect;
+
+ var dist = 0.0;
+ if (mode == 3.0) {
+ // Tilt-shift: sharp band around the focus line.
+ let angle = u.params1.w;
+ let perp = vec2<f32>(sin(angle), cos(angle));
+ let d = abs(dot(diff, perp));
+ let band = u.params1.z * 0.5;
+ dist = max(d - band, 0.0);
+ } else {
+ // Radial: sharp circle around the focus point.
+ dist = length(diff);
+ }
+
+ let edge = u.params1.z * 0.5;
+ let t = smoothstep(0.0, (edge + 0.35) * widen, dist - edge);
+ return pow(t, curve) * strength;
+}
+
+fn gaussian(gl_uv: vec2<f32>, screen_uv: vec2<f32>, horizontal: bool) -> vec4<f32> {
+ let coc = blur_amount(gl_uv);
+ let center = textureSampleLevel(t_source, s_source, screen_uv, 0.0);
+ if (coc < 0.5) {
+ return center;
+ }
+
+ let resolution = u.params2.yz;
+ let texel = 1.0 / max(resolution, vec2<f32>(1.0));
+ // The radius cap scales with output height, exactly like strength_px does
+ // on the CPU side (camera3d.rs), so the kernel covers the same fraction of
+ // the gaussian curve at every resolution and preview matches export. The
+ // flat ceiling (the scaled cap at 8K) bounds per-fragment cost.
+ let radius_cap = min(resolution.y * (40.0 / 1080.0), 160.0);
+ let radius = i32(min(coc, radius_cap));
+ let sigma = coc * 0.5;
+ let inv_sigma2 = 1.0 / (2.0 * sigma * sigma);
+
+ var color = vec4<f32>(0.0);
+ var total = 0.0;
+ for (var i = -radius; i <= radius; i++) {
+ let fi = f32(i);
+ let weight = exp(-fi * fi * inv_sigma2);
+ var offset: vec2<f32>;
+ if (horizontal) {
+ offset = vec2<f32>(texel.x * fi, 0.0);
+ } else {
+ offset = vec2<f32>(0.0, texel.y * fi);
+ }
+ color += textureSampleLevel(t_source, s_source, screen_uv + offset, 0.0) * weight;
+ total += weight;
+ }
+ return color / max(total, 1e-6);
+}
+
+// Ring-disc bokeh: 3 rings × (5·ring) samples with highlight gain, so bright
+// spots read as discs. Offsets are aspect-corrected to circles (fixing the
+// original's inverted correction).
+fn bokeh(gl_uv: vec2<f32>, screen_uv: vec2<f32>) -> vec4<f32> {
+ let coc = blur_amount(gl_uv);
+ let center = textureSampleLevel(t_source, s_source, screen_uv, 0.0);
+ if (coc < 0.5) {
+ return center;
+ }
+
+ let resolution = u.params2.yz;
+ let texel = 1.0 / max(resolution, vec2<f32>(1.0));
+ let aspect = resolution.x / max(resolution.y, 1.0);
+ let ring_step = coc / 3.0;
+
+ var acc = center;
+ var wsum = 1.0;
+ for (var ring = 1; ring <= 3; ring++) {
+ let ring_samples = ring * 5;
+ let r = f32(ring) * ring_step;
+ let ring_weight = mix(1.0, f32(ring) / 3.0, 0.3);
+ for (var j = 0; j < 15; j++) {
+ if (j >= ring_samples) {
+ break;
+ }
+ let a = 6.28318530718 * f32(j) / f32(ring_samples);
+ let offset = vec2<f32>(cos(a) / aspect, sin(a)) * r * texel.y;
+ // texel.y scale + /aspect on x keeps the disc circular on screen.
+ let s = textureSampleLevel(t_source, s_source, screen_uv + vec2<f32>(offset.x, -offset.y), 0.0);
+ let luma = dot(s.rgb, vec3<f32>(0.299, 0.587, 0.114));
+ let gain = 1.0 + smoothstep(0.7, 1.0, luma) * 1.5;
+ acc += s * ring_weight * gain;
+ wsum += ring_weight * gain;
+ }
+ }
+ return acc / wsum;
+}
+
+@fragment
+fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
+ let gl_uv = vec2<f32>(in.screen_uv.x, 1.0 - in.screen_uv.y);
+ let pass_kind = u.params0.x;
+ if (pass_kind == 2.0) {
+ return bokeh(gl_uv, in.screen_uv);
+ }
+ return gaussian(gl_uv, in.screen_uv, pass_kind == 0.0);
+}
diff --git a/crates/rendering/src/shaders/camera3d.wgsl b/crates/rendering/src/shaders/camera3d.wgsl
new file mode 100644
index 000000000..dc2c9a3f9
--- /dev/null
+++ b/crates/rendering/src/shaders/camera3d.wgsl
@@ -0,0 +1,79 @@
+// 3D perspective warp for the composed content plane.
+//
+// The content group (frame chrome, display, cursor, notch, camera) is rendered
+// into a transparent texture; this pass maps each output pixel back onto that
+// texture through the inverse planar homography and composites the result over
+// the untouched background with premultiplied alpha.
+//
+// Row layouts: inv_row0.w is unused; inv_row1.w and inv_row2.w carry the
+// plane half-extents (hx, hy) — the content plane spans [-hx, hx] × [-hy, hy]
+// in world units with its longest side equal to 2.
+
+struct Camera3DUniforms {
+ inv_row0: vec4<f32>,
+ inv_row1: vec4<f32>,
+ inv_row2: vec4<f32>,
+};
+
+@group(0) @binding(0) var<uniform> u: Camera3DUniforms;
+@group(0) @binding(1) var t_content: texture_2d<f32>;
+@group(0) @binding(2) var s_content: sampler;
+
+struct VertexOutput {
+ @builtin(position) position: vec4<f32>,
+ @location(0) screen_uv: vec2<f32>,
+};
+
+@vertex
+fn vs_main(@builtin(vertex_index) vertex_index: u32) -> VertexOutput {
+ // Fullscreen triangle.
+ let uv = vec2<f32>(
+ f32((vertex_index << 1u) & 2u),
+ f32(vertex_index & 2u),
+ );
+ var out: VertexOutput;
+ out.position = vec4<f32>(uv * 2.0 - 1.0, 0.0, 1.0);
+ out.screen_uv = vec2<f32>(uv.x, 1.0 - uv.y);
+ return out;
+}
+
+@fragment
+fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
+ let half_extents = vec2<f32>(u.inv_row1.w, u.inv_row2.w);
+ // y-up NDC of this output pixel.
+ let ndc = vec3<f32>(
+ in.screen_uv.x * 2.0 - 1.0,
+ 1.0 - in.screen_uv.y * 2.0,
+ 1.0,
+ );
+
+ let q = vec3<f32>(
+ dot(u.inv_row0.xyz, ndc),
+ dot(u.inv_row1.xyz, ndc),
+ dot(u.inv_row2.xyz, ndc),
+ );
+
+ // q.z <= 0 means the ray hits the plane behind the camera (past the
+ // horizon of an extreme rotation) — those pixels stay background.
+ let in_front = f32(q.z > 1e-6);
+
+ // Plane coords: X in [-hx, hx], Y in [-hy, hy] inside the content.
+ let denom = select(q.z, 1e-6, abs(q.z) <= 1e-6);
+ let plane = q.xy / denom;
+ let content_uv = vec2<f32>(
+ (plane.x / half_extents.x + 1.0) * 0.5,
+ (1.0 - plane.y / half_extents.y) * 0.5,
+ );
+
+ // Analytic edge anti-aliasing: fade coverage over one output pixel.
+ let width = max(fwidth(content_uv), vec2<f32>(1e-6));
+ let edge = smoothstep(vec2<f32>(0.0), width, content_uv)
+ * smoothstep(vec2<f32>(0.0), width, vec2<f32>(1.0) - content_uv);
+ let coverage = edge.x * edge.y * in_front;
+
+ let clamped = clamp(content_uv, vec2<f32>(0.0), vec2<f32>(1.0));
+ // The content texture is premultiplied (straight-alpha layers composited
+ // onto transparent black), so coverage scales the whole texel.
+ let color = textureSampleLevel(t_content, s_content, clamped, 0.0);
+ return color * coverage;
+}
diff --git a/crates/rendering/src/zoom.rs b/crates/rendering/src/zoom.rs
index 9623dca9b..be66af9e9 100644
--- a/crates/rendering/src/zoom.rs
+++ b/crates/rendering/src/zoom.rs
@@ -106,6 +106,16 @@ impl InterpolatedZoom {
}
}
+impl Default for InterpolatedZoom {
+ /// The resting transform: no zoom engaged.
+ fn default() -> Self {
+ Self {
+ t: 0.0,
+ bounds: SegmentBounds::default(),
+ }
+ }
+}
+
#[cfg(test)]
mod test {
use super::*;
diff --git a/crates/rendering/src/zoom_spring.rs b/crates/rendering/src/zoom_spring.rs
index 0ae204440..540e71c7d 100644
--- a/crates/rendering/src/zoom_spring.rs
+++ b/crates/rendering/src/zoom_spring.rs
@@ -1501,6 +1501,7 @@ mod tests {
caption_segments: vec![],
keyboard_segments: vec![],
audio_segments: vec![],
+ camera3d_segments: Vec::new(),
};
let cursor = CursorEvents {
moves: vec![
@@ -1570,6 +1571,7 @@ mod tests {
caption_segments: Vec::new(),
keyboard_segments: Vec::new(),
audio_segments: Vec::new(),
+ camera3d_segments: Vec::new(),
};
let map = build_time_map(Some(&timeline));