Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
finally fix
neo7738ad2d8e2c3ef
diff --git a/crates/rendering/src/lib.rs b/crates/rendering/src/lib.rsindex 661817372..eb8fbe21a 100644--- a/crates/rendering/src/lib.rs+++ b/crates/rendering/src/lib.rs@@ -973,16 +973,14 @@ pub async fn produce_frame(// First, handle the backgroundmatch background {Background::Image { path } => {- let img = image::open(&path)- .map_err(|e| RenderingError::ImageLoadError(e.to_string()))?;-// Use entry API to handle texture cachinglet mut textures = constants.background_textures.write().await;let texture = match textures.entry(path.clone()) {std::collections::hash_map::Entry::Occupied(e) => e.into_mut(),std::collections::hash_map::Entry::Vacant(e) => {// Load image with error propagation-+ let img = image::open(&path)+ .map_err(|e| RenderingError::ImageLoadError(e.to_string()))?;let rgba = img.to_rgba8();let dimensions = img.dimensions();@@ -1030,7 +1028,6 @@ pub async fn produce_frame(// Create uniforms and bind grouplet image_uniforms = ImageBackgroundUniforms {output_size: [uniforms.output_size.0 as f32, uniforms.output_size.1 as f32],- image_size: [img.dimensions().0 as f32, img.dimensions().1 as f32],padding: uniforms.project.background.padding as f32,_padding: 0.0,};@@ -2413,7 +2410,6 @@ struct ImageBackgroundPipeline {#[derive(Copy, Clone, Pod, Zeroable)]struct ImageBackgroundUniforms {output_size: [f32; 2],- image_size: [f32; 2],padding: f32,_padding: f32, // For alignment}diff --git a/crates/rendering/src/shaders/image-background.wgsl b/crates/rendering/src/shaders/image-background.wgslindex 869165363..fd92b4ffe 100644--- a/crates/rendering/src/shaders/image-background.wgsl+++ b/crates/rendering/src/shaders/image-background.wgsl@@ -1,6 +1,5 @@struct Uniforms {output_size: vec2<f32>,- image_size: vec2<f32>,padding: f32,_padding: f32, // Matches the Rust struct alignment padding};@@ -23,18 +22,34 @@ fn vs_main(@builtin(vertex_index) in_vertex_index: u32) -> VertexOutput {out.clip_position = vec4<f32>(x, y, 0.0, 1.0);return out;}-@fragmentfn fs_main(@location(0) tex_coords: vec2<f32>) -> @location(0) vec4<f32> {- // Calculate scaling factors for width and height- let scale_x = u.output_size.x / u.image_size.x;- let scale_y = u.output_size.y / u.image_size.y;+ // Calculate the padding in UV space+ let padding_uv = u.padding / max(u.output_size.x, u.output_size.y);- // Use the larger scale factor to ensure coverage- let scale = max(scale_x, scale_y);+ // Adjust UV coordinates to account for padding+ let adjusted_coords = tex_coords * (1.0 - 2.0 * padding_uv) + padding_uv;- // Transform coordinates to sample from the center of the scaled image- let adjusted_coords = (tex_coords - 0.5) * (u.output_size / (u.image_size * scale)) + 0.5;+ // Calculate aspect ratios+ let container_ratio = u.output_size.x / u.output_size.y;+ let texture_dims = vec2<f32>(textureDimensions(t_image));+ let texture_ratio = texture_dims.x / texture_dims.y;- return textureSample(t_image, s_image, adjusted_coords);-}+ // Calculate scale factors to achieve 'cover' behavior+ var scale = vec2<f32>(1.0);+ if (container_ratio > texture_ratio) {+ // Container is wider than texture - scale based on height+ scale.x = texture_ratio / container_ratio;+ scale.y = 1.0;+ } else {+ // Container is taller than texture - scale based on width+ scale.x = 1.0;+ scale.y = container_ratio / texture_ratio;+ }++ // Transform coordinates to center and scale the image+ let transformed_coords = (adjusted_coords - 0.5) * scale + 0.5;++ // Let the sampler handle the edge clamping+ return textureSample(t_image, s_image, transformed_coords);+}\ No newline at end of file