Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ A raw capture goes in and comes out ready to post — on X, Reddit, YouTube, a d
## Core Features
- Record a specific window, or your whole screen.
- Record microphone and system audio.
- Webcam overlay with picture-in-picture, eight snap positions, adjustable roundness, mirroring, and shape options.
- Webcam overlay with picture-in-picture, eight snap positions, adjustable roundness, mirroring, and shape options, plus a drop shadow: six presets (Close, Soft, Lifted, Floating, Ambient, or none) that you can customize by dragging where the shadow falls and setting its blur, spread, opacity, and color.
- Auto or manual zooms with adjustable depth, duration, easing, and pixel-precise position; auto-zoom follows your cursor as you work.
- Custom cursor size, smoothing, and click effects, with post-recording path smoothing.
- Automatic captions for voiceovers, transcribed on-device with no upload (works offline), with an editable transcript you can cut from and optional subtitle translation.
Expand Down
19 changes: 14 additions & 5 deletions crates/compositor/src/compositor_linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1637,6 +1637,7 @@ impl Compositor {
spread: f32,
offset_px: [f32; 2],
opacity: f32,
color: [f32; 3],
) -> LayerCB {
let (rw, rh) = (self.render_w as f32, self.render_h as f32);
let (sx, sy) = (spread / rw, spread / rh);
Expand All @@ -1646,7 +1647,7 @@ impl Compositor {
quad_px: [size_px[0] + 2.0 * spread, size_px[1] + 2.0 * spread],
radius_px: radius,
mode: 2.0,
color: [0.0, 0.0, 0.0, opacity],
color: [color[0], color[1], color[2], opacity],
fx: [spread, 0.0, 0.0, 0.0],
mb: [0.0, 1.0, 1.0, 0.0],
..Default::default()
Expand Down Expand Up @@ -2740,7 +2741,7 @@ impl Compositor {
Some(cb) => cb,
None => match g.shadow_caster([rw, rh]) {
ShadowCaster::Upright { dst, size_px, radius } => {
self.shadow_cb(dst, size_px, radius, spread, offset, opacity)
self.shadow_cb(dst, size_px, radius, spread, offset, opacity, [0.0; 3])
}
ShadowCaster::Tilted { corners, center_px, radius, mask } => self
.quad_shadow_cb(&corners, center_px, radius, mask, spread, offset, opacity),
Expand Down Expand Up @@ -2931,13 +2932,21 @@ impl Compositor {
&& !is_cutout
&& g.webcam_shadow > 0.0)
.then(|| {
let cb = self.shadow_cb(
let style = g.webcam_shadow_style;
let (caster, caster_px, caster_radius) = crate::frame_geometry::spread_shadow_caster(
g.w_dst,
g.w_px,
g.w_radius,
crate::frame_geometry::WEBCAM_SHADOW_SPREAD_FRAC * g.frame_min_px,
[0.0, crate::frame_geometry::WEBCAM_SHADOW_OFFSET_FRAC * g.frame_min_px],
style.spread_frac * g.frame_min_px,
);
let cb = self.shadow_cb(
caster,
caster_px,
caster_radius,
style.blur_frac * g.frame_min_px,
[style.offset_frac[0] * g.frame_min_px, style.offset_frac[1] * g.frame_min_px],
crate::frame_geometry::WEBCAM_SHADOW_OPACITY * g.shape_fade * g.webcam_shadow,
style.color,
);
self.make_bind(&cb, None, &dummy)
});
Expand Down
24 changes: 16 additions & 8 deletions crates/compositor/src/compositor_macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ pub use crate::frame_geometry::{
live_params_from_scene, webcam_shape_code, FIXTURE_FRAMES, LayerCB, LiveParams, OUT_H, OUT_W,
};
use crate::frame_geometry::{parse_hex, FrameGeometryInput, ShadowCaster,
SCREEN_SHADOW_SPREAD_FRAC, WEBCAM_SHADOW_OFFSET_FRAC, WEBCAM_SHADOW_OPACITY,
WEBCAM_SHADOW_SPREAD_FRAC};
spread_shadow_caster, SCREEN_SHADOW_SPREAD_FRAC, WEBCAM_SHADOW_OPACITY};
use crate::scene::{Scene, SceneBackground, SceneShaderEffect, ShaderEffectTarget, WallpaperMotion};
use anyhow::{anyhow, Result};
use metal::foreign_types::ForeignType;
Expand Down Expand Up @@ -1320,6 +1319,7 @@ impl Compositor {
spread: f32,
offset_px: [f32; 2],
opacity: f32,
color: [f32; 3],
) {
let (rw, rh) = (self.render_w as f32, self.render_h as f32);
let (sx, sy) = (spread / rw, spread / rh);
Expand All @@ -1329,7 +1329,7 @@ impl Compositor {
quad_px: [size_px[0] + 2.0 * spread, size_px[1] + 2.0 * spread],
radius_px: radius,
mode: 2.0,
color: [0.0, 0.0, 0.0, opacity],
color: [color[0], color[1], color[2], opacity],
fx: [spread, 0.0, 0.0, 0.0],
mb: [0.0, 1.0, 1.0, 0.0],
..Default::default()
Expand Down Expand Up @@ -2849,7 +2849,7 @@ impl Compositor {
} else {
match g.shadow_caster([rw, rh]) {
ShadowCaster::Upright { dst, size_px, radius } => {
self.draw_shadow(enc, dst, size_px, radius, spread, offset, opacity)
self.draw_shadow(enc, dst, size_px, radius, spread, offset, opacity, [0.0; 3])
}
ShadowCaster::Tilted { corners, center_px, radius, mask } => self.draw_quad_shadow(
enc, &corners, center_px, radius, mask, spread, offset, opacity,
Expand Down Expand Up @@ -3078,14 +3078,22 @@ impl Compositor {
// garde donc son ombre.
let is_cutout = matches!(effect, Some((code, _)) if code == 1.0);
if cfg.shadow && g.webcam_shadow > 0.0 && !is_cutout && g.shape_fade > 0.0 {
self.draw_shadow(
enc,
let style = g.webcam_shadow_style;
let (caster, caster_px, caster_radius) = spread_shadow_caster(
g.w_dst,
g.w_px,
g.w_radius,
WEBCAM_SHADOW_SPREAD_FRAC * g.frame_min_px,
[0.0, WEBCAM_SHADOW_OFFSET_FRAC * g.frame_min_px],
style.spread_frac * g.frame_min_px,
);
self.draw_shadow(
enc,
caster,
caster_px,
caster_radius,
style.blur_frac * g.frame_min_px,
[style.offset_frac[0] * g.frame_min_px, style.offset_frac[1] * g.frame_min_px],
WEBCAM_SHADOW_OPACITY * g.shape_fade * g.webcam_shadow,
style.color,
);
}

Expand Down
23 changes: 14 additions & 9 deletions crates/compositor/src/compositor_windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use crate::frame_geometry::{
cover_crop_uv, cover_uv_rect, decode_data_uri, ease_in_out_cubic, lerp,
lerp4, parse_hex, preset_placements, remap_box, screen_source_rect, timeline, CursorPlacement,
FrameParams, Placement, ShadowCaster, SpriteShape, CURSOR_BASE_SIZE_FRAC, FPS,
SCREEN_SHADOW_SPREAD_FRAC, SHADOW_TUNING_REF_PX, WEBCAM_SHADOW_OFFSET_FRAC,
WEBCAM_SHADOW_OPACITY, WEBCAM_SHADOW_SPREAD_FRAC,
spread_shadow_caster, SCREEN_SHADOW_SPREAD_FRAC, SHADOW_TUNING_REF_PX,
WEBCAM_SHADOW_OPACITY,
};
use crate::cursor::CursorTrack;
use crate::scene::{
Expand Down Expand Up @@ -2284,6 +2284,7 @@ impl Compositor {
spread: f32,
offset_px: [f32; 2],
opacity: f32,
color: [f32; 3],
) {
let sx = spread / self.rw();
let sy = spread / self.rh();
Expand All @@ -2294,7 +2295,7 @@ impl Compositor {
quad_px: [size_px[0] + 2.0 * spread, size_px[1] + 2.0 * spread],
radius_px: radius,
mode: 2.0,
color: [0.0, 0.0, 0.0, opacity],
color: [color[0], color[1], color[2], opacity],
fx: [spread, 0.0, 0.0, 0.0],
mb: [0.0, 1.0, 1.0, 0.0],
..Default::default()
Expand Down Expand Up @@ -2601,7 +2602,7 @@ impl Compositor {
} else {
match g.shadow_caster(render_px) {
ShadowCaster::Upright { dst, size_px, radius } => {
self.draw_shadow(dst, size_px, radius, spread, offset, opacity)
self.draw_shadow(dst, size_px, radius, spread, offset, opacity, [0.0; 3])
}
// Même rayon que le plan incliné lui-même (cf. le dessin du mode 8).
ShadowCaster::Tilted { corners, center_px, radius, mask } => self
Expand Down Expand Up @@ -2854,13 +2855,17 @@ impl Compositor {
) && self.webcam_mask.borrow().is_some();
if cfg.shadow && g.webcam_shadow > 0.0 && !is_cutout && shape_fade > 0.0 {
let strength = WEBCAM_SHADOW_OPACITY * shape_fade * g.webcam_shadow;
let style = g.webcam_shadow_style;
let (caster, caster_px, caster_radius) =
spread_shadow_caster(w_dst, w_px, w_radius, style.spread_frac * frame_min_px);
self.draw_shadow(
w_dst,
w_px,
w_radius,
WEBCAM_SHADOW_SPREAD_FRAC * frame_min_px,
[0.0, WEBCAM_SHADOW_OFFSET_FRAC * frame_min_px],
caster,
caster_px,
caster_radius,
style.blur_frac * frame_min_px,
[style.offset_frac[0] * frame_min_px, style.offset_frac[1] * frame_min_px],
strength,
style.color,
);
}
// Effet d'arrière-plan : le mode vient de la scène, le masque par pixel de
Expand Down
143 changes: 142 additions & 1 deletion crates/compositor/src/frame_geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,85 @@ pub(crate) const WEBCAM_SHADOW_OFFSET_FRAC: f32 = 12.0 / SHADOW_TUNING_REF_PX;
/// la position du slider. Parité avec le preset PiP côté web (`compositeLayout.ts`,
/// `rgba(0,0,0,0.35)`), dont l'ombre est elle aussi un forfait fixe et PiP-only.
pub(crate) const WEBCAM_SHADOW_OPACITY: f32 = 0.35;
/// Bounds of the camera shadow, as fractions of the 1080 px reference. They mirror
/// `WEBCAM_SHADOW_BOUNDS` in src/lib/webcamShadowStyles.ts, so a hand-edited project cannot push
/// the shadow off the frame or past what the pane offers.
pub(crate) const WEBCAM_SHADOW_OFFSET_RANGE: (f32, f32) = (-80.0 / SHADOW_TUNING_REF_PX, 80.0 / SHADOW_TUNING_REF_PX);
/// The blur floor is half a pixel AT THE 1080 REFERENCE, not in render pixels: the shader fades
/// with `smoothstep(0, blur, d)`, undefined at a zero width, and a floor taken after scaling
/// would collapse every blur under it in a small preview (1 px and 2 px both reaching the
/// floor in a 270 px tall preview) while the export still told them apart.
pub(crate) const WEBCAM_SHADOW_BLUR_RANGE: (f32, f32) = (0.5 / SHADOW_TUNING_REF_PX, 120.0 / SHADOW_TUNING_REF_PX);
pub(crate) const WEBCAM_SHADOW_SPREAD_RANGE: (f32, f32) = (-40.0 / SHADOW_TUNING_REF_PX, 40.0 / SHADOW_TUNING_REF_PX);

/// The camera shadow as `plan_frame` hands it to the backends: lengths as fractions of the
/// frame's short side, and `strength` as the scene's opacity over `WEBCAM_SHADOW_OPACITY`, the
/// factor the backends already multiply by.
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct WebcamShadowPlan {
pub blur_frac: f32,
pub offset_frac: [f32; 2],
pub spread_frac: f32,
pub color: [f32; 3],
pub strength: f32,
}

impl WebcamShadowPlan {
/// The tuned 35% black shadow every scene had before the presets, at `strength`.
pub(crate) fn tuned(strength: f32) -> Self {
Self {
blur_frac: WEBCAM_SHADOW_SPREAD_FRAC,
offset_frac: [0.0, WEBCAM_SHADOW_OFFSET_FRAC],
spread_frac: 0.0,
color: [0.0, 0.0, 0.0],
strength,
}
}
}

fn webcam_shadow_plan(effects: Option<&crate::scene::SceneEffects>) -> WebcamShadowPlan {
let finite = |v: f32, fallback: f32| if v.is_finite() { v } else { fallback };
let clamp = |v: f32, (lo, hi): (f32, f32)| finite(v, 0.0).clamp(lo, hi);
match effects.and_then(|e| e.webcam_shadow_style) {
Some(style) => WebcamShadowPlan {
blur_frac: clamp(style.blur_frac, WEBCAM_SHADOW_BLUR_RANGE),
offset_frac: [
clamp(style.offset_frac[0], WEBCAM_SHADOW_OFFSET_RANGE),
clamp(style.offset_frac[1], WEBCAM_SHADOW_OFFSET_RANGE),
],
spread_frac: clamp(style.spread_frac, WEBCAM_SHADOW_SPREAD_RANGE),
color: style.color.map(|c| clamp(c, (0.0, 1.0))),
strength: clamp(style.opacity, (0.0, 1.0)) / WEBCAM_SHADOW_OPACITY,
},
// `webcam_shadow` was a strength where 0.6 drew the tuned shadow.
None => WebcamShadowPlan::tuned(
effects.and_then(|e| e.webcam_shadow).unwrap_or(0.6).clamp(0.0, 1.0) / 0.6,
),
}
}

/// The rectangle a camera shadow is cast from: the camera's own, grown (or shrunk, with a
/// negative `spread_px`) on every side, its corners following so a round camera stays round.
/// `dst` is in the render target's normalised units, so its scale per pixel comes from `size_px`.
pub(crate) fn spread_shadow_caster(
dst: [f32; 4],
size_px: [f32; 2],
radius_px: f32,
spread_px: f32,
) -> ([f32; 4], [f32; 2], f32) {
if spread_px == 0.0 || size_px[0] <= 0.0 || size_px[1] <= 0.0 {
return (dst, size_px, radius_px);
}
// Never shrink past a pixel: a negative size would turn the rect inside out.
let spread = spread_px.max(0.5 - size_px[0].min(size_px[1]) / 2.0);
let (ux, uy) = (dst[2] / size_px[0], dst[3] / size_px[1]);
(
[dst[0] - spread * ux, dst[1] - spread * uy, dst[2] + 2.0 * spread * ux, dst[3] + 2.0 * spread * uy],
[size_px[0] + 2.0 * spread, size_px[1] + 2.0 * spread],
(radius_px + spread).max(0.0),
)
}

/// Taille de base du curseur, même convention (34 px réglés contre un cadre 1080).
pub(crate) const CURSOR_BASE_SIZE_FRAC: f32 = 34.0 / SHADOW_TUNING_REF_PX;

Expand Down Expand Up @@ -1910,6 +1989,8 @@ pub struct FrameGeometry {
pub show_screen: bool,
/// Continuous PiP shadow weight through a layout change.
pub webcam_shadow: f32,
/// The camera shadow's look; `webcam_shadow` above carries its strength through layouts.
pub webcam_shadow_style: WebcamShadowPlan,
pub mb_taps: f32,
pub mb_amount: f32,
pub source_t: f32,
Expand Down Expand Up @@ -3711,11 +3792,13 @@ pub fn plan_frame(input: &FrameGeometryInput) -> FrameGeometry {
Some(sample) => sample.preset != "camera-only" || sample.progress < 1.0,
None => scene_preset.as_deref() != Some("camera-only"),
});
let webcam_shadow_style = webcam_shadow_plan(input.scene.map(|scene| &scene.effects));
FrameGeometry {
show_screen,
webcam_shadow: sampled_layout.as_ref().map(|s| s.webcam_shadow)
.unwrap_or_else(|| if matches!(scene_preset.as_deref(), Some("dual-frame") | Some("vertical-stack") | Some("camera-only")) { 0.0 } else { 1.0 })
* input.scene.and_then(|scene| scene.effects.webcam_shadow).unwrap_or(0.6).clamp(0.0, 1.0) / 0.6,
* webcam_shadow_style.strength,
webcam_shadow_style,
scene_preset,
mb_taps,
mb_amount,
Expand Down Expand Up @@ -5256,6 +5339,63 @@ mod tests {
}
}

#[test]
fn webcam_shadow_style_reaches_the_plan_and_old_scenes_keep_the_tuned_shadow() {
let mut scene = golden_scene();
let cfg = crate::config::all().pop().expect("compositor config");
// A scene from before the presets: the tuned shadow, exactly.
let baseline = plan_frame(&golden_input(&scene, &cfg));
assert_eq!(baseline.webcam_shadow_style, WebcamShadowPlan::tuned(1.0));

scene.effects.webcam_shadow_style = Some(crate::scene::SceneWebcamShadow {
offset_frac: [-0.01, 0.03],
blur_frac: 0.08,
spread_frac: -0.01,
opacity: WEBCAM_SHADOW_OPACITY * 2.0,
color: [0.2, 0.4, 0.6],
});
let styled = plan_frame(&golden_input(&scene, &cfg));
let s = styled.webcam_shadow_style;
assert_eq!((s.offset_frac, s.blur_frac, s.spread_frac, s.color), ([-0.01, 0.03], 0.08, -0.01, [0.2, 0.4, 0.6]));
// Opacity is a strength over the tuned 35%, which every backend already multiplies by.
// Absolute weights, so a planner that suppressed the shadow (0 and 0) cannot pass.
assert!((baseline.webcam_shadow - 1.0).abs() < 1e-5, "{}", baseline.webcam_shadow);
assert!((styled.webcam_shadow - 2.0).abs() < 1e-5, "{}", styled.webcam_shadow);
// The shadow never moves the camera itself.
assert_eq!(styled.w_dst, baseline.w_dst);

// A hand-edited scene is held to the pane's ranges, and a NaN to nothing.
scene.effects.webcam_shadow_style = Some(crate::scene::SceneWebcamShadow {
offset_frac: [5.0, f32::NAN],
blur_frac: -1.0,
spread_frac: 9.0,
opacity: 7.0,
color: [2.0, -1.0, 0.5],
});
let s = plan_frame(&golden_input(&scene, &cfg)).webcam_shadow_style;
assert_eq!(s.offset_frac, [WEBCAM_SHADOW_OFFSET_RANGE.1, 0.0]);
assert_eq!(s.blur_frac, WEBCAM_SHADOW_BLUR_RANGE.0);
assert_eq!(s.spread_frac, WEBCAM_SHADOW_SPREAD_RANGE.1);
assert_eq!(s.color, [1.0, 0.0, 0.5]);
assert!((s.strength - 1.0 / WEBCAM_SHADOW_OPACITY).abs() < 1e-5);
}

#[test]
fn spread_grows_the_caster_on_every_side_and_never_inverts_it() {
// 200x100 px at 0.002 normalised units per pixel.
let dst = [0.5, 0.5, 0.4, 0.2];
let (d, px, r) = spread_shadow_caster(dst, [200.0, 100.0], 20.0, 10.0);
assert_eq!(px, [220.0, 120.0]);
assert_eq!(r, 30.0);
for (got, want) in d.iter().zip([0.48, 0.48, 0.44, 0.24]) {
assert!((got - want).abs() < 1e-6, "{d:?}");
}
let (_, px, r) = spread_shadow_caster(dst, [200.0, 100.0], 20.0, -500.0);
assert!(px[1] >= 1.0 - 1e-6 && px[0] > px[1], "{px:?}");
assert_eq!(r, 0.0);
assert_eq!(spread_shadow_caster(dst, [200.0, 100.0], 20.0, 0.0), (dst, [200.0, 100.0], 20.0));
}

/// Le JSON de la scène zoomée, brut : `tilted_golden_scene` n'en change QUE la
/// rotation, et le faire par substitution garantit que les deux scènes ne diffèrent
/// pas ailleurs sans qu'on s'en aperçoive.
Expand Down Expand Up @@ -8674,6 +8814,7 @@ mod tests {
show_screen: true,
scene_preset: None,
webcam_shadow: 1.0,
webcam_shadow_style: WebcamShadowPlan::tuned(1.0),
mb_taps: 1.0,
mb_amount: 0.0,
source_t: 0.0,
Expand Down
17 changes: 17 additions & 0 deletions crates/compositor/src/scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,19 @@ fn blur_amount<'de, D: serde::Deserializer<'de>>(d: D) -> Result<f32, D::Error>
})
}

/// The camera's drop shadow. Lengths are fractions of a 1080 px reference, like
/// `roundness_frac`: the native side multiplies them by the frame it draws.
#[derive(Debug, Clone, Copy, Deserialize, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct SceneWebcamShadow {
pub offset_frac: [f32; 2],
pub blur_frac: f32,
pub spread_frac: f32,
pub opacity: f32,
/// sRGB, 0..1 per channel.
pub color: [f32; 3],
}

/// Effets de cadre (padding, blur, ombre, coins, motion blur).
#[derive(Debug, Clone, Copy, Deserialize)]
#[serde(rename_all = "camelCase")]
Expand All @@ -284,6 +297,10 @@ pub struct SceneEffects {
pub shadow: f32,
#[serde(default)]
pub webcam_shadow: Option<f32>,
/// The PiP camera's drop shadow (`SceneWebcamShadow` in sceneDescription.ts). Absent in
/// scenes from before the presets, which keep the tuned shadow scaled by `webcam_shadow`.
#[serde(default)]
pub webcam_shadow_style: Option<SceneWebcamShadow>,
/// Slider Roundness, en FRACTION du petit côté du cadre de sortie.
///
/// Toute longueur qui traverse ce contrat est une fraction, jamais un nombre de pixels, et
Expand Down
Loading
Loading