Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
chore: trim narration comments in color grade rendering
Richie McIlroycdfd20a7f8a8
diff --git a/crates/rendering/src/composite_frame.rs b/crates/rendering/src/composite_frame.rsindex 559eef503..c6510b784 100644--- a/crates/rendering/src/composite_frame.rs+++ b/crates/rendering/src/composite_frame.rs@@ -92,13 +92,13 @@ pub struct CompositeVideoFrameUniforms {/// squares its top corners against decorative frame chrome with/// `[0, 0, 1, 1]`.pub corner_radii: [f32; 4],- /// Color grade: (exposure in stops, contrast, saturation, temperature).+ /// (exposure stops, contrast, saturation, temperature).pub color_adjust_a: [f32; 4],- /// Color grade: (tint, fade, split_tone, vignette).+ /// (tint, fade, split_tone, vignette).pub color_adjust_b: [f32; 4],- /// (grain amount, per-frame grain seed, grade-active flag, full-frame- /// vignette flag). The active flag lets the shader skip the whole color- /// pass in one uniform branch when the layer has no grade.+ /// (grain amount, grain seed, grade-active flag, full-frame vignette+ /// flag). The active flag gates the shader's whole color pass in one+ /// uniform branch, keeping ungraded layers bit-identical to before.pub grain_params: [f32; 4],}@@ -134,10 +134,9 @@ impl Default for CompositeVideoFrameUniforms {}}-/// The three uniform vec4s that drive the shader's color pass, derived from a-/// layer's [`cap_project::ColorCorrection`]. Intensity scaling happens here so-/// the shader never needs to know about it, and every field is clamped so a-/// hand-edited config can't push the shader outside its designed ranges.+/// Intensity scaling and range clamping happen here, Rust-side, so the+/// shader never sees unscaled values and a hand-edited config can't push it+/// outside its designed ranges.#[derive(Debug, Clone, Copy)]pub struct ColorGradeUniformParams {pub color_adjust_a: [f32; 4],@@ -152,17 +151,14 @@ impl ColorGradeUniformParams {grain_params: [0.0; 4],};- /// Mirrors the shader's own gate: `grain_params.z` is the active flag- /// `from_config` sets when any adjustment survives clamping and intensity- /// scaling.+ /// Must mirror the shader's own gate on `grain_params.z`.pub fn is_active(&self) -> bool {self.grain_params[2] > 0.5}- /// `full_frame_vignette` selects the vignette's coordinate space:- /// the screen uses the full output frame (so the display card and the- /// graded background share one continuous vignette field), while the- /// camera vignettes within its own card.+ /// `full_frame_vignette` selects the vignette's coordinate space: full+ /// output frame for the screen (one continuous field across card and+ /// backdrop), card-local for the camera.pub fn from_config(config: &cap_project::ColorCorrection,frame_number: u32,@@ -193,8 +189,7 @@ impl ColorGradeUniformParams {.iter().any(|v| v.abs() > 1e-4);- // Cycling seed keeps grain animated while staying deterministic per- // frame number, so preview and export always match.+ // Seed is deterministic per frame number so preview and export match.let grain_seed = (frame_number % 600) as f32;Self {diff --git a/crates/rendering/src/layers/color_grade.rs b/crates/rendering/src/layers/color_grade.rsindex f23bb69b7..5ef1942f4 100644--- a/crates/rendering/src/layers/color_grade.rs+++ b/crates/rendering/src/layers/color_grade.rs@@ -3,11 +3,8 @@ use wgpu::util::DeviceExt;use crate::ProjectUniforms;-/// Full-frame pass that applies the screen's color grade (including grain)-/// to the background canvas, so the backdrop and the display card read as one-/// graded scene. Runs between the background (+ its blur) and the display-/// layer, and only when the screen grade is active — an ungraded project-/// skips the pass entirely.+/// Full-frame pass applying the screen grade to the background canvas so the+/// backdrop and display card read as one graded scene.pub struct ColorGradeLayer {active: bool,uniforms_buffer: wgpu::Buffer,@@ -32,9 +29,8 @@ impl ColorGradeLayer {}pub fn prepare(&mut self, queue: &wgpu::Queue, uniforms: &ProjectUniforms) {- // Reuses the exact params the display card was given: grain and- // vignette only stay continuous across the card edge if both passes- // grade with identical values.+ // Must reuse the display card's exact params: grain/vignette only+ // stay continuous across the card edge with identical values.let params = uniforms.screen_color_grade;self.active = params.is_active();if !self.active {diff --git a/crates/rendering/src/layers/cursor.rs b/crates/rendering/src/layers/cursor.rsindex 4e4664f90..db479d057 100644--- a/crates/rendering/src/layers/cursor.rs+++ b/crates/rendering/src/layers/cursor.rs@@ -594,9 +594,6 @@ impl CursorLayer {],};- // The cursor wears the screen's grade so it reads as part of the- // graded footage; the same shared params keep its grain and vignette- // continuous with the card and backdrop underneath.let cursor_grade = if uniforms.project.color_correction.grade_cursor {uniforms.screen_color_grade} else {@@ -726,8 +723,8 @@ pub struct CursorUniforms {screen_bounds: [f32; 4],motion_vector_strength: [f32; 4],rotation_params: [f32; 4],- /// Screen color grade (see `ColorGradeUniformParams`); identity when the- /// user opts the cursor out of the grade.+ /// Screen grade (see `ColorGradeUniformParams`); identity when the+ /// cursor opts out.color_adjust_a: [f32; 4],color_adjust_b: [f32; 4],grain_params: [f32; 4],diff --git a/crates/rendering/src/lib.rs b/crates/rendering/src/lib.rsindex eb625d23a..fe56996e6 100644--- a/crates/rendering/src/lib.rs+++ b/crates/rendering/src/lib.rs@@ -2251,9 +2251,8 @@ pub struct ProjectUniforms {/// The recording device's physical notch, redrawn over the capture;/// `None` when the overlay is off or the recording has no notch.pub notch: Option<layers::NotchUniforms>,- /// The screen grade's uniform params, shared verbatim by the display card- /// and the background grade pass so grain and vignette stay continuous- /// across the card edge.+ /// Shared verbatim by the display card, background grade pass, and+ /// cursor — grain/vignette continuity depends on identical params.screen_color_grade: ColorGradeUniformParams,/// Final placement of the outer display card (chrome included) in output/// px. Equals `display.target_bounds` when no frame is active.@@ -3800,8 +3799,7 @@ impl ProjectUniforms {border_color: [0.0; 4],frame_size: [1.0, 1.0],crop_bounds: [0.0, 0.0, 1.0, 1.0],- // The notch redraw is hardware, not video: never- // graded.+ // Hardware redraw, not video: never graded.color_adjust_a: [0.0; 4],color_adjust_b: [0.0; 4],grain_params: [0.0; 4],@@ -5802,11 +5800,9 @@ impl RendererLayers {session.swap_textures();}- // Grade the backdrop before any content layers draw, so the screen's- // color grade covers the whole scene (padding, wallpaper, blur) and- // not just the display card. Content layers apply their own grades.- // The pass overwrites every pixel (fullscreen triangle, no blending),- // so the target's old contents never need loading.+ // Runs before content layers so the screen grade covers the whole+ // backdrop; content layers grade themselves. The fullscreen triangle+ // overwrites every pixel, so the old target contents never load.if self.background_color_grade.is_active() {let mut pass = render_pass!(session.other_texture_view(),diff --git a/crates/rendering/src/shaders/color-grade.wgsl b/crates/rendering/src/shaders/color-grade.wgslindex 5e95150d0..d174c8ad7 100644--- a/crates/rendering/src/shaders/color-grade.wgsl+++ b/crates/rendering/src/shaders/color-grade.wgsl@@ -1,11 +1,7 @@-// Full-frame color grade for the background canvas. Runs between the-// background (+ its blur) and the display layer so the backdrop wears the-// same grade as the screen and the padded scene reads as one frame.-//-// The grade math MUST stay in sync with apply_color_grade in-// composite-video-frame.wgsl: the display card applies the same grade in its-// own shader, and grain + vignette are computed in the same output-pixel-// space so the two layers meet seamlessly at the card edge.+// Full-frame grade for the background canvas. The math MUST stay in sync+// with apply_color_grade in composite-video-frame.wgsl and cursor.wgsl:+// grain and vignette share one output-pixel space so the layers meet+// seamlessly at the card edge.struct Uniforms {// (exposure stops, contrast, saturation, temperature).@@ -52,8 +48,7 @@ fn fs_main(@builtin(position) frag_coord: vec4<f32>) -> @location(0) vec4<f32> {// Exposure in stops.var rgb = color.rgb * exp2(exposure);- // White balance: temperature trades red against blue, tint trades green- // against magenta. Multiplicative so black stays black.+ // White balance, multiplicative so black stays black.rgb = rgb * vec3<f32>(1.0 + 0.10 * temperature + 0.04 * tint,1.0 - 0.07 * tint,@@ -67,8 +62,7 @@ fn fs_main(@builtin(position) frag_coord: vec4<f32>) -> @location(0) vec4<f32> {let luma = dot(clamp(rgb, vec3<f32>(0.0), vec3<f32>(1.0)), vec3<f32>(0.2126, 0.7152, 0.0722));rgb = mix(vec3<f32>(luma), rgb, 1.0 + saturation);- // Split toning: teal into shadows, orange into highlights (reversed when- // the amount is negative), weighted by luma bands.+ // Split tone: teal shadows / orange highlights, luma-banded.let shadow_w = 1.0 - smoothstep(0.2, 0.65, luma);let highlight_w = smoothstep(0.35, 0.8, luma);rgb += split_tone * (@@ -79,17 +73,13 @@ fn fs_main(@builtin(position) frag_coord: vec4<f32>) -> @location(0) vec4<f32> {// Film fade: raised blacks, gently dulled highlights.rgb = rgb * (1.0 - 0.18 * fade) + vec3<f32>(0.09 * fade);- // Full-frame vignette (the display card computes its vignette in the- // same output space, so the field is continuous across the card edge).if vignette > 0.0 {let dims = vec2<f32>(textureDimensions(frame_texture));let r = length((frag_coord.xy / dims - vec2<f32>(0.5)) * 2.0);rgb = rgb * (1.0 - vignette * 0.65 * smoothstep(0.5, 1.5, r));}- // Animated monochrome grain, peaked in the midtones like scanned film.- // Same hash, coordinates, and seed as the display layer so the noise- // field is continuous across the card boundary.+ // Midtone-peaked monochrome grain.if grain > 0.0 {let seed = uniforms.grain_params.y;let noise = grain_hash(frag_coord.xy + vec2<f32>(seed * 17.0, seed * 29.0));diff --git a/crates/rendering/src/shaders/composite-video-frame.wgsl b/crates/rendering/src/shaders/composite-video-frame.wgslindex f68d02c61..f0adb5d6e 100644--- a/crates/rendering/src/shaders/composite-video-frame.wgsl+++ b/crates/rendering/src/shaders/composite-video-frame.wgsl@@ -26,12 +26,11 @@ struct Uniforms {// the uniform rounding; the display squares its top corners against// decorative frame chrome with (0, 0, 1, 1).corner_radii: vec4<f32>,- // Color grade: (exposure stops, contrast, saturation, temperature).+ // (exposure stops, contrast, saturation, temperature).color_adjust_a: vec4<f32>,- // Color grade: (tint, fade, split_tone, vignette).+ // (tint, fade, split_tone, vignette).color_adjust_b: vec4<f32>,- // (grain amount, per-frame grain seed, grade-active flag, full-frame- // vignette flag).+ // (grain amount, grain seed, grade-active flag, full-frame vignette flag).grain_params: vec4<f32>,};@@ -138,18 +137,16 @@ fn rounded_rect_coverage(p: vec2<f32>, b: vec2<f32>, r: f32, rounding_type: f32)return coverage * 0.25;}-// One-value hash with good distribution (same family as the background-// layer's gradient noise); sin-free so it stays stable across GPU drivers.+// Sin-free hash so grain stays stable across GPU drivers.fn grain_hash(p: vec2<f32>) -> f32 {var p3 = fract(vec3<f32>(p.x, p.y, p.x) * 0.1031);p3 += dot(p3, p3.yzx + 33.33);return fract((p3.x + p3.y) * p3.z);}-// Applies the layer's color grade + film grain to a resolved video color.-// Runs once per output pixel (after any motion-blur resolve), so its cost is-// independent of blur tap counts, and ungraded layers skip everything in a-// single coherent uniform branch.+// Must stay in sync with color-grade.wgsl and cursor.wgsl. Runs once per+// output pixel after motion-blur resolve; ungraded layers skip everything in+// a single coherent uniform branch.fn apply_color_grade(color: vec4<f32>, target_uv: vec2<f32>, frag_pos: vec2<f32>) -> vec4<f32> {if uniforms.grain_params.z < 0.5 {return color;@@ -168,8 +165,7 @@ fn apply_color_grade(color: vec4<f32>, target_uv: vec2<f32>, frag_pos: vec2<f32>// Exposure in stops.var rgb = color.rgb * exp2(exposure);- // White balance: temperature trades red against blue, tint trades green- // against magenta. Multiplicative so black stays black.+ // White balance, multiplicative so black stays black.rgb = rgb * vec3<f32>(1.0 + 0.10 * temperature + 0.04 * tint,1.0 - 0.07 * tint,@@ -183,8 +179,7 @@ fn apply_color_grade(color: vec4<f32>, target_uv: vec2<f32>, frag_pos: vec2<f32>let luma = dot(clamp(rgb, vec3<f32>(0.0), vec3<f32>(1.0)), vec3<f32>(0.2126, 0.7152, 0.0722));rgb = mix(vec3<f32>(luma), rgb, 1.0 + saturation);- // Split toning: teal into shadows, orange into highlights (reversed when- // the amount is negative), weighted by luma bands.+ // Split tone: teal shadows / orange highlights, luma-banded.let shadow_w = 1.0 - smoothstep(0.2, 0.65, luma);let highlight_w = smoothstep(0.35, 0.8, luma);rgb += split_tone * (@@ -195,9 +190,6 @@ fn apply_color_grade(color: vec4<f32>, target_uv: vec2<f32>, frag_pos: vec2<f32>// Film fade: raised blacks, gently dulled highlights.rgb = rgb * (1.0 - 0.18 * fade) + vec3<f32>(0.09 * fade);- // Vignette. The screen computes it over the full output frame so the- // card and the graded background share one continuous field; the camera- // vignettes within its own card.if vignette > 0.0 {var vig_uv = target_uv;if uniforms.grain_params.w > 0.5 {@@ -207,8 +199,7 @@ fn apply_color_grade(color: vec4<f32>, target_uv: vec2<f32>, frag_pos: vec2<f32>rgb = rgb * (1.0 - vignette * 0.65 * smoothstep(0.5, 1.5, r));}- // Animated monochrome grain, peaked in the midtones like scanned film.- // The per-frame seed decorrelates the hash every frame.+ // Midtone-peaked monochrome grain.if grain > 0.0 {let seed = uniforms.grain_params.y;let noise = grain_hash(frag_pos + vec2<f32>(seed * 17.0, seed * 29.0));diff --git a/crates/rendering/src/shaders/cursor.wgsl b/crates/rendering/src/shaders/cursor.wgslindex 6b0d95981..00cd67d17 100644--- a/crates/rendering/src/shaders/cursor.wgsl+++ b/crates/rendering/src/shaders/cursor.wgsl@@ -9,16 +9,12 @@ struct Uniforms {screen_bounds: vec4<f32>,motion_vector_strength: vec4<f32>,rotation_params: vec4<f32>,- // Screen color grade, identity when the cursor opts out. The math MUST- // stay in sync with apply_color_grade in composite-video-frame.wgsl and- // color-grade.wgsl: grain and vignette are computed in the same- // output-pixel space so the sprite blends seamlessly into the graded- // scene beneath it.+ // Screen grade, identity when the cursor opts out.// (exposure stops, contrast, saturation, temperature).color_adjust_a: vec4<f32>,// (tint, fade, split_tone, vignette).color_adjust_b: vec4<f32>,- // (grain amount, per-frame grain seed, grade-active flag, unused).+ // (grain amount, grain seed, grade-active flag, unused).grain_params: vec4<f32>,};@@ -133,11 +129,11 @@ fn grain_hash(p: vec2<f32>) -> f32 {return fract((p3.x + p3.y) * p3.z);}-// Applies the screen's color grade to the resolved sprite color. This-// pipeline blends premultiplied (One, OneMinusSrcAlpha), so the color is-// lifted to straight alpha before grading and re-premultiplied after —-// otherwise the grade's additive terms (fade lift, split tone, grain) would-// bleed into the transparent parts of the motion smear.+// Must stay in sync with composite-video-frame.wgsl and color-grade.wgsl.+// This pipeline blends premultiplied (One, OneMinusSrcAlpha), so the color+// is lifted to straight alpha before grading and re-premultiplied after —+// otherwise the grade's additive terms (fade, split tone, grain) bleed into+// the transparent parts of the motion smear.fn apply_color_grade(color: vec4<f32>, frag_pos: vec2<f32>) -> vec4<f32> {if uniforms.grain_params.z < 0.5 || color.a < 0.001 {return color;@@ -156,8 +152,7 @@ fn apply_color_grade(color: vec4<f32>, frag_pos: vec2<f32>) -> vec4<f32> {// Exposure in stops.var rgb = (color.rgb / color.a) * exp2(exposure);- // White balance: temperature trades red against blue, tint trades green- // against magenta. Multiplicative so black stays black.+ // White balance, multiplicative so black stays black.rgb = rgb * vec3<f32>(1.0 + 0.10 * temperature + 0.04 * tint,1.0 - 0.07 * tint,@@ -171,8 +166,7 @@ fn apply_color_grade(color: vec4<f32>, frag_pos: vec2<f32>) -> vec4<f32> {let luma = dot(clamp(rgb, vec3<f32>(0.0), vec3<f32>(1.0)), vec3<f32>(0.2126, 0.7152, 0.0722));rgb = mix(vec3<f32>(luma), rgb, 1.0 + saturation);- // Split toning: teal into shadows, orange into highlights (reversed when- // the amount is negative), weighted by luma bands.+ // Split tone: teal shadows / orange highlights, luma-banded.let shadow_w = 1.0 - smoothstep(0.2, 0.65, luma);let highlight_w = smoothstep(0.35, 0.8, luma);rgb += split_tone * (@@ -183,16 +177,13 @@ fn apply_color_grade(color: vec4<f32>, frag_pos: vec2<f32>) -> vec4<f32> {// Film fade: raised blacks, gently dulled highlights.rgb = rgb * (1.0 - 0.18 * fade) + vec3<f32>(0.09 * fade);- // The cursor lives in the full output frame, so its vignette always uses- // the frame-wide field the background and display card share.+ // Always the frame-wide vignette field, matching the layers underneath.if vignette > 0.0 {let r = length((frag_pos / uniforms.output_size.xy - vec2<f32>(0.5)) * 2.0);rgb = rgb * (1.0 - vignette * 0.65 * smoothstep(0.5, 1.5, r));}- // Animated monochrome grain, peaked in the midtones like scanned film.- // Same hash, coordinates, and seed as the layers underneath so the noise- // field stays continuous through the sprite's semi-transparent pixels.+ // Midtone-peaked monochrome grain.if grain > 0.0 {let seed = uniforms.grain_params.y;let noise = grain_hash(frag_pos + vec2<f32>(seed * 17.0, seed * 29.0));