Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat: Zoom out camera + cursor motion blur

Richie McIlroyb5792e565dce
diff --git a/apps/desktop/src/routes/editor/ConfigSidebar.tsx b/apps/desktop/src/routes/editor/ConfigSidebar.tsx
index 93be76bf1..7acc42df0 100644
--- a/apps/desktop/src/routes/editor/ConfigSidebar.tsx
+++ b/apps/desktop/src/routes/editor/ConfigSidebar.tsx
@@ -444,6 +444,18 @@ export function ConfigSidebar() {
step={0.1}
/>
</Field>
+ <Field name="Size During Zoom" icon={<IconCapEnlarge />}>
+ <Slider
+ value={[project.camera.zoom_size ?? 20]}
+ onChange={(v) => setProject("camera", "zoom_size", v[0])}
+ minValue={10}
+ maxValue={60}
+ step={0.1}
+ />
+ <div class="text-sm text-gray-500 mt-1">
+ Camera size when zoomed in (default: 70% of normal size)
+ </div>
+ </Field>
<Field name="Rounded Corners" icon={<IconCapCorners />}>
<Slider
value={[project.camera.rounding ?? 100.0]}
diff --git a/apps/desktop/src/utils/tauri.ts b/apps/desktop/src/utils/tauri.ts
index 3fc0a74cc..98d803c49 100644
--- a/apps/desktop/src/utils/tauri.ts
+++ b/apps/desktop/src/utils/tauri.ts
@@ -375,7 +375,7 @@ export type AuthenticationInvalid = null
export type BackgroundConfiguration = { source: BackgroundSource; blur: number; padding: number; rounding: number; inset: number; crop: Crop | null }
export type BackgroundSource = { type: "wallpaper"; id: number } | { type: "image"; path: string | null } | { type: "color"; value: [number, number, number] } | { type: "gradient"; from: [number, number, number]; to: [number, number, number]; angle?: number }
export type Bounds = { x: number; y: number; width: number; height: number }
-export type CameraConfiguration = { hide: boolean; mirror: boolean; position: CameraPosition; rounding: number; shadow: number; size: number }
+export type Camera = { hide: boolean; mirror: boolean; position: CameraPosition; size: number; zoom_size: number | null; rounding: number; shadow: number }
export type CameraMeta = { path: string }
export type CameraPosition = { x: CameraXPosition; y: CameraYPosition }
export type CameraXPosition = "left" | "center" | "right"
@@ -404,7 +404,7 @@ export type OSPermissionStatus = "notNeeded" | "empty" | "granted" | "denied"
export type OSPermissionsCheck = { screenRecording: OSPermissionStatus; microphone: OSPermissionStatus; camera: OSPermissionStatus; accessibility: OSPermissionStatus }
export type Plan = { upgraded: boolean; last_checked: number }
export type PreCreatedVideo = { id: string; link: string; config: S3UploadMeta }
-export type ProjectConfiguration = { aspectRatio: AspectRatio | null; background: BackgroundConfiguration; camera: CameraConfiguration; audio: AudioConfiguration; cursor: CursorConfiguration; hotkeys: HotkeysConfiguration; timeline?: TimelineConfiguration | null; motionBlur: number | null }
+export type ProjectConfiguration = { aspectRatio: AspectRatio | null; background: BackgroundConfiguration; camera: Camera; audio: AudioConfiguration; cursor: CursorConfiguration; hotkeys: HotkeysConfiguration; timeline?: TimelineConfiguration | null; motionBlur: number | null }
export type ProjectRecordings = { display: Video; camera: Video | null; audio: Audio | null }
export type RecordingMeta = { pretty_name: string; sharing?: SharingMeta | null; display: Display; camera?: CameraMeta | null; audio?: AudioMeta | null; segments?: RecordingSegment[]; cursor: string | null }
export type RecordingMetaChanged = { id: string }
diff --git a/crates/project/src/configuration.rs b/crates/project/src/configuration.rs
index 181c492a9..c3df56a83 100644
--- a/crates/project/src/configuration.rs
+++ b/crates/project/src/configuration.rs
@@ -185,40 +185,31 @@ pub struct CameraPosition {
pub y: CameraYPosition,
}
-#[derive(Type, Serialize, Deserialize, Clone, Debug)]
-#[serde(rename_all = "camelCase")]
-pub struct CameraConfiguration {
+#[derive(Debug, Clone, Serialize, Deserialize, Type)]
+pub struct Camera {
pub hide: bool,
pub mirror: bool,
pub position: CameraPosition,
- pub rounding: f32,
- pub shadow: u32,
pub size: f32,
+ pub zoom_size: Option<f32>,
+ pub rounding: f32,
+ pub shadow: f32,
}
-impl Default for CameraConfiguration {
+impl Default for Camera {
fn default() -> Self {
Self {
hide: false,
mirror: false,
position: CameraPosition::default(),
- rounding: Self::default_rounding(),
- shadow: 0,
- size: Self::default_size(),
+ size: 30.0,
+ zoom_size: None,
+ rounding: 100.0,
+ shadow: 0.0,
}
}
}
-impl CameraConfiguration {
- fn default_size() -> f32 {
- 30.0
- }
-
- fn default_rounding() -> f32 {
- 100.0
- }
-}
-
#[derive(Type, Serialize, Deserialize, Clone, Debug, Default)]
#[serde(rename_all = "camelCase")]
pub struct AudioConfiguration {
@@ -322,7 +313,7 @@ impl TimelineConfiguration {
pub struct ProjectConfiguration {
pub aspect_ratio: Option<AspectRatio>,
pub background: BackgroundConfiguration,
- pub camera: CameraConfiguration,
+ pub camera: Camera,
pub audio: AudioConfiguration,
pub cursor: CursorConfiguration,
pub hotkeys: HotkeysConfiguration,
@@ -357,7 +348,7 @@ impl Default for ProjectConfiguration {
source: BackgroundSource::default(),
..Default::default()
},
- camera: CameraConfiguration::default(),
+ camera: Camera::default(),
audio: AudioConfiguration::default(),
cursor: CursorConfiguration::default(),
hotkeys: HotkeysConfiguration::default(),
diff --git a/crates/rendering/src/lib.rs b/crates/rendering/src/lib.rs
index 5811e0740..85d2d8330 100644
--- a/crates/rendering/src/lib.rs
+++ b/crates/rendering/src/lib.rs
@@ -580,13 +580,29 @@ impl ProjectUniforms {
.filter(|_| !project.camera.hide)
.map(|camera_size| {
let output_size = [output_size.0 as f32, output_size.1 as f32];
-
let frame_size = [camera_size.x as f32, camera_size.y as f32];
let min_axis = output_size[0].min(output_size[1]);
+ // Calculate camera size based on zoom
+ let base_size = project.camera.size / 100.0;
+ let zoom_amount = zoom_keyframes.get_amount(time as f64) as f32;
+ let zoomed_size = if zoom_amount > 1.0 {
+ // Get the zoom size as a percentage (0-1 range)
+ let zoom_size = project.camera.zoom_size.unwrap_or(20.0) / 100.0;
+
+ // Smoothly interpolate between base size and zoom size
+ let t = (zoom_amount - 1.0) / 1.5; // Normalize to 0-1 range
+ let t = t.min(1.0); // Clamp to prevent over-scaling
+
+ // Lerp between base_size and zoom_size
+ base_size * (1.0 - t) + zoom_size * t
+ } else {
+ base_size
+ };
+
let size = [
- min_axis * project.camera.size / 100.0 + CAMERA_PADDING,
- min_axis * project.camera.size / 100.0 + CAMERA_PADDING,
+ min_axis * zoomed_size + CAMERA_PADDING,
+ min_axis * zoomed_size + CAMERA_PADDING,
];
let position = {
@@ -1019,6 +1035,25 @@ fn draw_cursor(
return;
};
+ // Calculate previous position for velocity
+ let prev_position = interpolate_cursor_position(&constants.cursor, time - 1.0 / 30.0);
+
+ // Calculate velocity in screen space
+ let velocity = if let Some(prev_pos) = prev_position {
+ let curr_frame_pos = cursor_position.to_frame_space(&constants.options, &uniforms.project);
+ let prev_frame_pos = prev_pos.to_frame_space(&constants.options, &uniforms.project);
+ let frame_velocity = curr_frame_pos.coord - prev_frame_pos.coord;
+
+ // Convert to pixels per frame
+ [frame_velocity.x as f32, frame_velocity.y as f32]
+ } else {
+ [0.0, 0.0]
+ };
+
+ // Calculate motion blur amount based on velocity magnitude
+ let speed = (velocity[0] * velocity[0] + velocity[1] * velocity[1]).sqrt();
+ let motion_blur_amount = (speed * 0.3).min(1.0) * uniforms.project.motion_blur.unwrap_or(0.8);
+
let cursor_event = find_cursor_event(&constants.cursor, time);
let last_click_time = constants
@@ -1064,8 +1099,9 @@ fn draw_cursor(
screen_bounds: uniforms.display.target_bounds,
cursor_size: cursor_size_percentage,
last_click_time: last_click_time.min(0.5),
- padding: [0.0; 2],
- _alignment: [0.0; 8],
+ velocity,
+ motion_blur_amount,
+ _alignment: [0.0; 7],
};
let cursor_uniform_buffer =
@@ -1533,8 +1569,9 @@ struct CursorUniforms {
screen_bounds: [f32; 4],
cursor_size: f32,
last_click_time: f32,
- padding: [f32; 2],
- _alignment: [f32; 8],
+ velocity: [f32; 2],
+ motion_blur_amount: f32,
+ _alignment: [f32; 7],
}
fn find_cursor_event(cursor: &CursorData, time: f32) -> &CursorMoveEvent {
diff --git a/crates/rendering/src/shaders/cursor.wgsl b/crates/rendering/src/shaders/cursor.wgsl
index 54bd56f11..f894adc7c 100644
--- a/crates/rendering/src/shaders/cursor.wgsl
+++ b/crates/rendering/src/shaders/cursor.wgsl
@@ -10,7 +10,8 @@ struct Uniforms {
screen_bounds: vec4<f32>,
cursor_size: f32,
last_click_time: f32,
- padding: vec2<f32>,
+ velocity: vec2<f32>,
+ motion_blur_amount: f32,
_alignment: vec4<f32>,
};
@@ -65,5 +66,40 @@ fn vs_main(@builtin(vertex_index) vertex_index: u32) -> VertexOutput {
@fragment
fn fs_main(input: VertexOutput) -> @location(0) vec4<f32> {
- return textureSample(t_cursor, s_cursor, input.uv);
+ // Increase number of samples for smoother blur
+ let num_samples = 12;
+ var color = vec4<f32>(0.0);
+
+ // Calculate blur direction from velocity
+ let velocity_dir = normalize(uniforms.velocity);
+
+ // Increase the blur trail length
+ let blur_strength = uniforms.motion_blur_amount * 2.0;
+
+ // Track total weight for normalization
+ var total_weight = 0.0;
+
+ // Sample in both directions from the center
+ for (var i = 0; i < num_samples; i++) {
+ // Adjusted sampling pattern for longer trails
+ let t = (f32(i) / f32(num_samples - 1)) * 2.0 - 1.0; // Range from -1 to 1
+ let weight = 1.0 - abs(t); // Higher weight in the center
+ total_weight += weight;
+
+ // Calculate sample offset with increased range
+ let offset = velocity_dir * blur_strength * t;
+ let sample_uv = input.uv + offset * uniforms.velocity / uniforms.output_size.xy;
+
+ // Apply weighted sample
+ color += textureSample(t_cursor, s_cursor, sample_uv) * weight;
+ }
+
+ // Normalize by total weight
+ color = color / total_weight;
+
+ // Adjust alpha falloff for stronger trails
+ let alpha_scale = 1.0 - uniforms.motion_blur_amount * 0.2;
+ color.a *= alpha_scale;
+
+ return color;
}