From 0fbc09eabd1933fa4dbbb8623b317c4af4954d91 Mon Sep 17 00:00:00 2001 From: Keavon Chambers Date: Sat, 5 Dec 2026 02:45:25 -0800 Subject: [PATCH] Fix fill and stroke paints' own blend modes blending with what lies beneath the shape in Vello --- .../libraries/rendering/src/renderer.rs | 6 ++- .../wgpu-executor/src/vello_render/tests.rs | 40 +++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/node-graph/libraries/rendering/src/renderer.rs b/node-graph/libraries/rendering/src/renderer.rs index 8feec3996e..8692ab986c 100644 --- a/node-graph/libraries/rendering/src/renderer.rs +++ b/node-graph/libraries/rendering/src/renderer.rs @@ -5372,7 +5372,8 @@ fn render_vector_item_to_vello( | Graphic::GraphicList(_) | Graphic::TextList(_) | Graphic::StrokeList(_) => { - scene.push_clip_layer(fill_rule, kurbo::Affine::new(element_transform.to_cols_array()), path); + // The paint composites within its own layer, as in its SVG pattern, so its blend modes act on nothing beneath the shape + scene.push_layer(fill_rule, peniko::Mix::Normal, 1., kurbo::Affine::new(element_transform.to_cols_array()), path); paint.render_to_vello(scene, multiplied_transform, &painting_within(layer_bounds)); scene.pop_layer(); } @@ -5471,7 +5472,8 @@ fn render_vector_item_to_vello( | Graphic::StrokeList(_) => { let stroked = placed.stroke_outline(&stroke, 0.01); - scene.push_clip_layer(peniko::Fill::NonZero, element_affine, &*stroked); + // The paint composites within its own layer, as for the fill + scene.push_layer(peniko::Fill::NonZero, peniko::Mix::Normal, 1., element_affine, &*stroked); paint.render_to_vello(scene, multiplied_transform, &painting_within(stroke_bounds())); scene.pop_layer(); } diff --git a/node-graph/libraries/wgpu-executor/src/vello_render/tests.rs b/node-graph/libraries/wgpu-executor/src/vello_render/tests.rs index 7d53ffe830..5a5b2623ec 100644 --- a/node-graph/libraries/wgpu-executor/src/vello_render/tests.rs +++ b/node-graph/libraries/wgpu-executor/src/vello_render/tests.rs @@ -1919,6 +1919,46 @@ fn a_half_filled_paint_made_opaque_looks_the_same_whether_drawn_by_its_color_or_ } } +#[test] +fn a_paints_own_blend_mode_composites_within_the_paint_rather_than_onto_what_lies_beneath_the_shape() { + use core_types::list::{ATTR_APPEARANCE, ATTR_EFFECTS, Item, List}; + use core_types::{ATTR_BLEND_MODE, Color as GraphicColor}; + use graphic_types::vector_types::vector::style::Stroke; + use graphic_types::{Appearance, Coverage, EffectOperation, Effects, Graphic, Vector}; + use rendering::{Render, RenderParams}; + use vello_gpu::kurbo::Shape; + + let size = UVec2::new(140, 140); + let shape = |rect: Rect, coverage: Coverage, paint: Graphic| { + let mut vector = Vector::item_from_bezpath(&rect.to_path(0.1)); + vector.set_attribute(ATTR_APPEARANCE, Appearance::new_single(coverage, paint)); + Graphic::VectorList(List::new_from_item(vector)) + }; + let background = shape(Rect::new(0., 0., 140., 140.), Coverage::new_fill(), Graphic::ColorList(List::new_from_element(GraphicColor::RED))); + + // Green multiplied with nothing beneath it in its paint stays green, whatever lies beneath the shape, as in SVG's pattern, though a blur of it draws it as content + let blur = EffectOperation::Blur { + radius_mask: Graphic::default(), + radius: 4., + box_blur: false, + gamma: false, + }; + let green = Item::new_from_element(GraphicColor::GREEN) + .with_attribute(ATTR_BLEND_MODE, BlendMode::Multiply) + .with_attribute(ATTR_EFFECTS, Effects::from_operations([blur])); + for (coverage, inside) in [(Coverage::new_fill(), (70, 70)), (Coverage::new_stroke(&Stroke::new(10.)), (20, 70))] { + let square = shape(Rect::new(20., 20., 120., 120.), coverage, Graphic::Color(green.clone())); + let Some(pixels) = render(size, |scene| { + background.render_to_vello(scene, DAffine2::IDENTITY, &RenderParams::default()); + square.render_to_vello(scene, DAffine2::IDENTITY, &RenderParams::default()); + }) else { + return; + }; + let (x, y) = inside; + assert_eq!(pixel(&pixels, size, x, y), [0, 255, 0, 255], "green at ({x}, {y})"); + } +} + #[test] fn feathers_fade_the_content_to_nothing_at_its_edges() { use graphic_types::EffectOperation;