Anchor the Motion Blur node's shear at the content's local origin instead of its bounds (#5046)

Anchor Motion Blur's shear at the content's local origin
This commit is contained in:
Keavon Chambers authored and GitHub committed 2026-11-29 17:04:43 -08:00
1 parent addba860d3
commit c75ebbd143
6 files changed
+63 -11

No files matched your search

@@ -240,7 +240,8 @@ impl EffectPasses {
fill: f32,
opacity: f32,
effect_to_pixels: DAffine2,
frame: Option<EffectFrame>,
// Used by the frame-taking effects in the next PRs
#[allow(unused_variables)] frame: Option<EffectFrame>,
paints: &[wgpu::Texture],
capture: Option<EffectCapture>,
) -> Vec<(wgpu::Texture, BlendMode)> {
@@ -718,8 +719,8 @@ impl EffectPasses {
});
}
EffectOperation::MotionBlur { angle, distance, gamma } => {
let anchor = frame.map_or(DVec2::ZERO, |frame| frame.to_pixels.translation);
let Some(shear) = MotionBlurShear::new(angle, distance, lengths_to_pixels, anchor) else {
// Anchored at the effect space's origin, which is the content's, so the shear moves with it
let Some(shear) = MotionBlurShear::new(angle, distance, lengths_to_pixels, effect_to_pixels.translation) else {
continue;
};
@@ -5113,6 +5113,57 @@ fn long_motion_blurs_spread_their_samples_alike_on_the_cpu_and_gpu() {
}
}
#[test]
fn skewed_motion_blurs_move_with_the_contents_origin() {
use core_types::ATTR_TRANSFORM;
use core_types::list::{ATTR_APPEARANCE, List};
use glam::{DMat2, DVec2, IVec2};
use graphic_types::{Appearance, Coverage, Effect, EffectOperation, Graphic, Vector, stamp_effect};
use rendering::{Render, RenderParams};
use vello_gpu::kurbo::Shape;
// A square around its origin, smeared along a slanted line, then skewed so its effects render along its skewed axes
let mut square = Vector::item_from_bezpath(&Rect::new(-16., -16., 16., 16.).to_path(0.1));
square.set_attribute(
ATTR_APPEARANCE,
Appearance::new_single(Coverage::new_fill(), Graphic::ColorList(List::new_from_element(core_types::Color::WHITE))),
);
stamp_effect(
&mut square,
Effect::new(&EffectOperation::MotionBlur {
angle: 30.,
distance: 12.,
gamma: false,
}),
);
// Stretching at most twofold, the skew moves those texels by whole texels when the square moves by whole pixels
let skew = DAffine2::from_mat2(DMat2::from_cols(DVec2::X, DVec2::new(1.5, 1.)));
let size = UVec2::new(256, 160);
let draw_at = |origin: DVec2| {
let graphic = Graphic::Vector(Box::new(square.clone().with_attribute(ATTR_TRANSFORM, DAffine2::from_translation(origin) * skew)));
render(size, |scene| graphic.render_to_vello(scene, DAffine2::IDENTITY, &RenderParams::default()))
};
let origin = DVec2::new(100., 70.);
let shift = IVec2::new(7, 3);
let (Some(before), Some(after)) = (draw_at(origin), draw_at(origin + shift.as_dvec2())) else {
return;
};
let smeared = before.iter().filter(|pixel| (8..248).contains(&pixel[3])).count();
assert!(smeared > 500, "the blur smears only {smeared} pixels");
// Its shears are measured from its origin, so the smear moves along with it
let mut worst = 0;
for y in 0..size.y - shift.y as u32 {
for x in 0..size.x - shift.x as u32 {
let (expected, actual) = (pixel(&before, size, x, y), pixel(&after, size, x + shift.x as u32, y + shift.y as u32));
worst = worst.max(expected.iter().zip(actual).map(|(&expected, actual)| expected.abs_diff(actual)).max().unwrap_or_default());
}
}
assert!(worst <= 1, "moved by {shift}, the smear differs by up to {worst} levels");
}
#[test]
fn radial_blurs_reach_as_far_inside_faded_groups_and_from_out_of_view() {
use core_types::list::{ATTR_APPEARANCE, ATTR_EFFECTS, Item, List};
@@ -42,7 +42,7 @@ fn clipped(color: vec4<f32>) -> vec4<f32> {
}
// A motion blur's passes measure texels along the major axis (x) and across it (y), which are the texture's y and x when `values.z` is 1.
// The line moves `values.x` across the minor axis per texel along the major axis, less the fraction `values.y` that measures it from the frame's edge, matching the CPU's `MotionBlurShear`.
// The line moves `values.x` across the minor axis per texel along the major axis, less the fraction `values.y` that measures it from the content's origin, matching the CPU's `MotionBlurShear`.
fn motion_axes(position: vec2<f32>) -> vec2<i32> {
let texel = vec2<i32>(position);
if parameters.values.z > 0.5 {