3D and Materials: test shadow plane images per ink and the raster work Check counts

With Shadows on, solids in the same opacity and blending mode share one
shadow plane image and solids in different ones get their own, and each
plane image casts only the shadows of the solids in its run. A new test
checks the image order and inks, the plane coverage, the layer plan and
the casters of each plane's scene.

Check counts raster work only for the triangles an image draws. A new
test finds the work limit of one solid's own image and shows that an
unseen duplicate in the scene does not raise it, that drawing both
solids does, and that the image draws within that limit.
This commit is contained in:
dotCooCoo committed 2026-12-05 16:46:29 -08:00
1 parent cb63a90ca3
commit 60c752ff25
1 file changed
+110
+110
View File
@@ -582,6 +582,77 @@ fn a_see_through_solid_draws_its_shadow_plane_behind_it() {
assert!(shadow > 0 && covered > 0, "{shadow} shadow pixels, {covered} solid pixels");
}
/// With Shadows on, solids in the same opacity and blending mode share one shadow plane image, and
/// solids in different ones each get their own, all before the solids' own images.
#[test]
fn solids_in_one_ink_share_a_shadow_plane_image() {
use vectorcraft_doc::color::BlendMode;
let mut n = Node::path(
NodeId(1),
square(100.0, 100.0, 100.0),
Appearance::basic(Paint::solid(Color::rgb(0.2, 0.5, 0.8)), Paint::solid(Color::rgb(0.8, 0.2, 0.2)), 8.0),
);
n.appearance
.effects
.push(crate::new_effect(super::super::EXTRUDE, &json!({"shadow": true, "render": {"mode": "rendered", "quality": "low"}})).unwrap());
let inked = |fill: (f32, BlendMode), stroke: (f32, BlendMode)| {
let mut n = n.clone();
// Appearance::basic holds the fill, then the stroke.
if let vectorcraft_doc::AppearanceItem::Fill(f) = &mut n.appearance.items[0] {
(f.opacity, f.blend) = fill;
}
if let vectorcraft_doc::AppearanceItem::Stroke(s) = &mut n.appearance.items[1] {
(s.opacity, s.blend) = stroke;
}
let (images, alpha) = image_nodes(&drawn(&n))
.into_iter()
.map(|(i, o, b)| {
let pixels = decoded(&i);
let pixels = pixels.as_chunks::<4>().0;
let plane = pixels.iter().any(|p| p[3] > 0) && pixels.iter().all(|p| p[3] == 0 || p[..3] == [0, 0, 0]);
(((o, b), plane), pixels.iter().map(|p| p[3]).collect::<Vec<_>>())
})
.unzip::<_, _, Vec<_>, Vec<_>>();
(n, images, alpha)
};
let core = |alpha: &[u8]| {
let full = *alpha.iter().max().unwrap();
alpha.iter().enumerate().filter_map(|(i, &a)| (a == full).then_some(i)).collect::<std::collections::BTreeSet<_>>()
};
let half = (0.5, BlendMode::Normal);
let (shared_node, shared, shared_alpha) = inked(half, half);
assert_eq!(shared, [(half, true), (half, false), (half, false)], "one plane image for both solids, then each solid");
// `scene_of` leaves out the shadow plane the drawn art places; a plane under the square stands in for it.
let plane = Some([[100.0, 100.0, 0.0], [200.0, 100.0, 0.0], [200.0, 200.0, 0.0], [100.0, 200.0, 0.0]]);
let (meshes, mut lighting) = scene_of(&shared_node);
lighting.receiver = plane;
assert_eq!(layers(&meshes, &lighting, false), [(Layer::Plane(0, 2), half), (Layer::Solid(0), half), (Layer::Solid(1), half)]);
let quarter = (0.25, BlendMode::Normal);
let (split_node, split, split_alpha) = inked(half, quarter);
assert_eq!(split, [(half, true), (quarter, true), (half, false), (quarter, false)], "one plane image for each ink, then each solid");
let (meshes, mut lighting) = scene_of(&split_node);
lighting.receiver = plane;
assert_eq!(
layers(&meshes, &lighting, false),
[(Layer::Plane(0, 1), half), (Layer::Plane(1, 2), quarter), (Layer::Solid(0), half), (Layer::Solid(1), quarter)]
);
let measured = measure(&meshes, &lighting, MEDIUM, 72.0, false, &Limits::default()).unwrap();
for (layer, casts) in [(Layer::Plane(0, 1), [true, false]), (Layer::Plane(1, 2), [false, true])] {
let plane = scene(&meshes, &lighting, layer, &measured).unwrap();
assert_eq!(plane.materials[..meshes.len()].iter().map(|m| m.casts_shadows).collect::<Vec<_>>(), casts, "{layer:?}");
}
// The stroke reaches 4 pt past the fill, so its shadow covers pixels outside the fill's shadow.
let (fill_core, stroke_core) = (core(&split_alpha[0]), core(&split_alpha[1]));
assert!(stroke_core.iter().any(|&i| split_alpha[0][i] == 0), "the stroke's plane shows the stroke's shadow");
assert!(fill_core.union(&stroke_core).all(|&i| shared_alpha[0][i] > 0), "the shared plane covers both solids' shadows");
let multiply = (0.5, BlendMode::Multiply);
assert_eq!(
inked(half, multiply).1,
[(half, true), (multiply, true), (half, false), (multiply, false)],
"a blending mode splits the plane image too"
);
}
/// With a fill and a stroke, each drawn on its own once either is see-through, in the order of the
/// appearance, each in its own ink; a fill at 0% opacity draws nothing and its stroke still draws.
#[test]
@@ -928,6 +999,45 @@ fn check_only_counts_shadow_work_and_lights() {
}
}
/// In a solid's own image the other solids stay in the scene unseen. Check counts no raster work
/// for their triangles, as drawing the image counts none, so a limit the solid's own image fits
/// is a limit it draws within.
#[test]
fn check_counts_raster_work_only_for_drawn_triangles() {
let n = solid_square(super::super::EXTRUDE, Color::BLACK, json!({"rotationX": 0, "rotationY": 0, "rotationZ": 0, "shadow": true}));
let (meshes, lighting) = scene_of(&n);
assert!(lighting.lights.iter().any(|l| lighting.casts(l)));
let two = vec![meshes[0].clone(), meshes[0].clone()];
// At 600 ppi the image's raster work outweighs the draft shadow maps' work.
let settings = RenderSettings { quality: 0, resolution: Some(600.0), white: false };
let limits = |max_work| {
let mut limits = Limits::default();
limits.max_work = max_work;
limits
};
let fits = |max_work| check(&meshes[..1], &lighting, Layer::Solid(0), settings, 72.0, &limits(max_work)).is_ok();
let (mut lo, mut hi) = (0, Limits::default().max_work);
assert!(fits(hi));
while lo + 1 < hi {
let mid = lo + (hi - lo) / 2;
if fits(mid) {
hi = mid;
} else {
lo = mid;
}
}
let one = hi;
assert!(check(&two, &lighting, Layer::Solid(0), settings, 72.0, &limits(one)).is_ok(), "the unseen duplicate adds no raster work");
assert!(
check(&two, &lighting, Layer::All, settings, 72.0, &limits(one)).is_err(),
"drawing both solids takes more raster work than the solid's own image"
);
assert!(
render_layer(&two, &lighting, Layer::Solid(0), settings, 72.0, false, &limits(one)).is_ok(),
"the image draws within the limit check accepts"
);
}
#[test]
fn check_only_art_reports_overlapping_faces_past_the_work_limit() {
let n = solid_square(super::super::ROTATE, Color::BLACK, json!({"rotationX": 0, "rotationY": 0, "rotationZ": 0, "shade": false}));