diff --git a/ATTRIBUTION.md b/ATTRIBUTION.md index 985861ac..a136498a 100644 --- a/ATTRIBUTION.md +++ b/ATTRIBUTION.md @@ -23,7 +23,7 @@ licensed and keep their license file next to them. | `docs/images/texturecraft-light.png` | README screenshot: the light brightness level with the blue accent | TextureCraft contributors | original screenshot of TextureCraft | MIT OR Apache-2.0 | | `docs/images/texturecraft-lantern.png` | README render: a storm lantern (original procedural mesh of lathes and swept wires, eight texture sets) in chipped red enamel, rust, soot, tarnished brass and glass with an emissive flame (`texturecraft-cli render --camera Hero --samples 2048`, 1200×900) | TextureCraft contributors | original model and render by TextureCraft | MIT OR Apache-2.0 | | `docs/images/texturecraft-camera.png` | README render: a rangefinder camera (original procedural mesh) in black enamel worn to brass, leatherette, chrome and coated glass; the lens distance scale is an original image drawn in code (`texturecraft-cli render --camera Hero --samples 2048`, 1200×900) | TextureCraft contributors | original model and render by TextureCraft | MIT OR Apache-2.0 | -| `assets/hdr/studio_small_09_512.hdr` | Studio Small 09: a small photo studio with octaboxes on a white infinity cyc, equirect HDR reduced to 512×256 (2×2 box filter, Radiance RLE); lights the Properties panel's material orbs | Sergej Majboroda (Poly Haven) | https://polyhaven.com/a/studio_small_09 (1K .hdr) | CC0-1.0 | +| `assets/hdr/studio_small_09_512.hdr` | Studio Small 09: a small photo studio with octaboxes on a white infinity cyc, equirect HDR reduced to 512×256 (2×2 box filter, Radiance RLE); lights the Properties panel's material orbs | Sergej Majboroda (Poly Haven) | [Poly Haven release](https://polyhaven.com/a/studio_small_09), [1K Radiance HDR](https://dl.polyhaven.org/file/ph-assets/HDRIs/hdr/1k/studio_small_09_1k.hdr) (MD5 `d5d7eb9d26d341d6aa4d11c1a54fd97c`) | [CC0 1.0 Universal](https://creativecommons.org/publicdomain/zero/1.0/) | | `docs/brand/artcraft-*.svg`, `docs/brand/artcraft-*.png` | ArtCraft logo and mark | ArtCraft Team | storytold/craftrules `assets/brand/` | ArtCraft brand terms, not open source ([`docs/brand/LICENSE-brand.txt`](docs/brand/LICENSE-brand.txt)) | | `crates/formats/src/mesh_import/usd/fixtures/crafted-references.usdc` | Synthetic USDC class/reference/time-sample acceptance fixture | ArtCraft Team and craft-libs contributors | [Pinned generator and provenance](crates/formats/src/mesh_import/usd/fixtures/README.md) | MIT (`crates/formats/src/mesh_import/usd/fixtures/LICENSE-MIT`) | diff --git a/apps/texturecraft/src/main.rs b/apps/texturecraft/src/main.rs index 0ebd5e94..0ebfaa86 100644 --- a/apps/texturecraft/src/main.rs +++ b/apps/texturecraft/src/main.rs @@ -443,6 +443,7 @@ mod tests { } let moved = window_frame(&mut harness, moves); let put_back = moved.iter().any(|command| matches!(command, egui::ViewportCommand::CursorPosition(to) if to.distance(pad) <= PUT_BACK_REACH)); + assert!(locked || put_back, "the window puts the pointer back where the press began, so it never leaves: {moved:?}"); let seen = harness.ctx.input(|input| input.pointer.latest_pos()); assert!(seen.is_some_and(|seen| seen.distance(pad + DRAG_STEP) <= PUT_BACK_REACH), "the app reads the whole move: {seen:?}"); diff --git a/crates/compose/src/axis_frame.rs b/crates/compose/src/axis_frame.rs index b63be023..80f465fe 100644 --- a/crates/compose/src/axis_frame.rs +++ b/crates/compose/src/axis_frame.rs @@ -6,7 +6,8 @@ use texturecraft_geom::glam::{EulerRot, Mat3, Vec3}; use crate::frame_placement::culling_folds; use crate::pattern::{DEPTH_FADE_START, frame_uv_from_corner, mesh_frame, nonzero_stretch, projector_stretch}; -/// The placed planar projection that reads images exactly as axis planar `proj` does on a mesh within `bounds` (None for other projections, placed ones included, and while backface culling cannot keep its facing in a frame: see [`culling_folds`]) +/// Place an axis planar on a mesh within `bounds` while keeping its sampling and culling. +/// See [`culling_folds`] for when culling prevents placement. pub fn placed_from_axis(proj: &Projection, bounds: (Vec3, Vec3)) -> Option { let Projection::Planar { scale, axis, offset, uv, projector, placed: None } = proj else { return None }; @@ -16,8 +17,8 @@ pub fn placed_from_axis(proj: &Projection, bounds: (Vec3, Vec3)) -> Option, + borrowed_mesh_key: Option, hot: Option, key: Option, /// Tiles with the stamp of their last use. @@ -52,6 +56,8 @@ pub struct BelowCache { impl Default for BelowCache { fn default() -> Self { BelowCache { + mesh: Weak::new(), + borrowed_mesh_key: None, hot: None, key: None, tiles: HashMap::new(), @@ -266,6 +272,48 @@ fn render_view(l: &Layer) -> Layer { } impl BelowCache { + pub(crate) fn bind_mesh(&mut self, mesh: &Arc) { + if !std::ptr::eq(self.mesh.as_ptr(), mesh.as_ref()) { + self.clear(); + self.borrowed_mesh_key = None; + self.mesh = Arc::downgrade(mesh); + } + } + + pub(crate) fn bind_borrowed_mesh(&mut self, mesh: &Mesh) { + if std::ptr::eq(self.mesh.as_ptr(), mesh) { + return; + } + + // A borrow alone cannot distinguish in-place edits or reuse of the same address + let mut key = DefaultHasher::new(); + for attribute in [&mesh.positions, &mesh.normals] { + attribute.len().hash(&mut key); + for value in attribute { + value.to_array().map(f32::to_bits).hash(&mut key); + } + } + mesh.tangents.len().hash(&mut key); + for value in &mesh.tangents { + value.to_array().map(f32::to_bits).hash(&mut key); + } + mesh.uvs.len().hash(&mut key); + for value in &mesh.uvs { + value.to_array().map(f32::to_bits).hash(&mut key); + } + mesh.indices.hash(&mut key); + for part in &mesh.submeshes { + (&part.name, part.start, part.count, part.material).hash(&mut key); + } + + let key = key.finish(); + if self.borrowed_mesh_key != Some(key) { + self.clear(); + self.mesh = Weak::new(); + self.borrowed_mesh_key = Some(key); + } + } + /// Cache the stack around `hot` from now on (a different layer empties the cache). pub fn set_hot(&mut self, hot: Option) { if self.hot != hot { diff --git a/crates/compose/src/eval.rs b/crates/compose/src/eval.rs index d0cdb0f2..b09a8ec7 100644 --- a/crates/compose/src/eval.rs +++ b/crates/compose/src/eval.rs @@ -2,6 +2,7 @@ //! tile by tile in parallel. This is the reference implementation (the oracle) for the viewport //! and for export. +mod draw_placement; mod evaluation_inputs; pub(crate) mod thumbnail; @@ -13,7 +14,7 @@ use rayon::prelude::*; use texturecraft_core::{ BakedMap, BlendMode, BlockScales, Channel, ChannelKind, CompareSource, ContentsOffset, CurvatureDetail, CurvatureMode, Effect, EffectKind, Fill, Filter, Filtering, Generator, GeneratorKind, HeightMask, Layer, LayerId, LayerKind, Mask, MaskBackground, MicroDetail, NormalFormat, Project, Projection, Sampling, - ShapeCrop, Source, TextureSet, TileGrid, blend1, blend3, lum, mix3, per_unit, + ShapeCrop, Source, TextureSet, TileGrid, blend1, blend3, lum, mix3, per_unit, udim_at, }; use texturecraft_geom::glam::{Vec2, Vec3}; use texturecraft_geom::{Mesh, NO_TRI, Surface, UvGBuffer}; @@ -25,14 +26,15 @@ use crate::curvature_sizes::CurvatureSizes; use crate::effect_histogram::EffectHistogram; use crate::fill_copies::FillCopies; use crate::fill_copy::FillCopy; +use crate::fill_depth::FillDepth; use crate::fill_place::FillPlace; use crate::held_fields::HeldFields; use crate::mask_gray::MaskGray; -use crate::pattern::{Coords, image_samples, mesh_frame, pattern_pixels, procedural_in, world_noise}; +use crate::pattern::{Coords, image_samples, mesh_frame, pattern_pixels, placement, procedural_in, world_noise}; use crate::pattern_context::PatternContext; use crate::projector_cover::{framed_cover, projector_cover, projector_covers_all}; -use crate::projector_depth::ProjectorDepth; use crate::store::{BakedMaps, ImageRes, ImageStore, PixelStore, decode}; +use draw_placement::DrawPlacement; use evaluation_inputs::EvaluationInputs; const NCH: usize = Channel::ALL.len(); @@ -40,7 +42,7 @@ const NCH: usize = Channel::ALL.len(); /// Coverage past which a symmetric fill's remaining copies would not show under the ones above const COVERED: f32 = 0.9999; -/// Share of an image's longer side a step to the next texel may jump before it counts as a UV seam +/// Largest projected step as a share of the image's longer side for non-UV projections const SEAM_JUMP_SHARE: f32 = 0.25; /// Stack values being composited, per channel. @@ -148,6 +150,23 @@ impl Inputs<'_> { fn tile_res_at(&self, x: u32, y: u32) -> u32 { ((self.tile_res() as f32 * self.block_scales.at(x, y)).round() as u32).max(1) } + + /// Mesh UV units per atlas texel along each axis, within the tile containing `(x, y)`. + fn mesh_uv_step(&self, x: u32, y: u32) -> Vec2 { + let atlas_step = Vec2::new(self.gbuf.width.max(1) as f32, self.gbuf.height.max(1) as f32).recip(); + let Ok(set) = self.project.texture_set(self.ts) else { return atlas_step }; + let Some(grid) = set.tile_grid() else { return atlas_step }; + + let grid_step = atlas_step * Vec2::new(grid.cols as f32, grid.rows as f32); + if set.tile_resolutions.is_empty() { + return grid_step; + } + + // Locate the atlas cell before undoing the tile scale + let atlas_uv = Vec2::new(x as f32 + 0.5, y as f32 + 0.5) * atlas_step; + let tile_scale = udim_at(grid.from_atlas(atlas_uv.to_array())).map_or(1.0, |tile| set.tile_scale(tile)); + grid_step / tile_scale + } } /// The composited channels of one texture set. @@ -234,9 +253,10 @@ enum Content<'a> { }, /// A fill (with the Scale and Rotation of the folders around it laid on) Fill { - fill: Box>, + fill: &'a Fill, + projection: Option>, /// Its projector's depth map when it culls by depth - depth: Option>, + depth: Option>, /// Whether it covers every texel (see [`covers_every_texel`]), so no texel asks covers_all: bool, }, @@ -246,8 +266,9 @@ enum Content<'a> { struct EffectPlan<'a> { /// The effect id (an anchor point records under it). id: LayerId, - /// The effect, a fill's with the Scale and Rotation of the folders around its layer laid on - kind: Cow<'a, EffectKind>, + kind: &'a EffectKind, + /// The source projection after applying an enclosing folder's transform + projection: Option, blend: BlendMode, opacity: f32, data: Option>, @@ -257,7 +278,7 @@ struct EffectPlan<'a> { /// A filtered mask stage retained because an anchor above it records that stage. filtered_mask: Option<&'a Field>, /// The projector's depth map of a fill or material effect that culls by depth - depth: Option>, + depth: Option>, /// Whether a fill or material effect covers every texel (see [`covers_every_texel`]), so no texel asks covers_all: bool, } @@ -301,9 +322,29 @@ impl Field { pub enum FieldKey { Mask(LayerId, [u32; 2]), Content(LayerId, Channel, [u32; 2]), + InstanceMask(LayerId, [u32; 2], usize), + InstanceContent(LayerId, Channel, [u32; 2], usize), } impl FieldKey { + fn in_instance(self, instance: usize) -> Self { + match self { + Self::Mask(id, offset) if instance != 0 => Self::InstanceMask(id, offset, instance), + Self::Content(id, channel, offset) if instance != 0 => Self::InstanceContent(id, channel, offset, instance), + key => key, + } + } + + fn field(self, fields: &Fields, instance: usize) -> Option<&Field> { + if instance != 0 + && let Some(field) = fields.get(&self.in_instance(instance)) + { + return Some(field); + } + + fields.get(&self) + } + /// The key of layer `id`'s mask field under the folders' offset `around` pub fn mask(id: LayerId, around: ContentsOffset) -> FieldKey { FieldKey::Mask(id, [around.scale.to_bits(), around.rotation.to_bits()]) @@ -342,7 +383,7 @@ enum Op { /// The last neighbourhood filter of an effect stack (see [`neighbourhood_filters`]). fn neighbourhood(effects: &[Effect], res: u32) -> Option<(usize, f32, Op)> { - neighbourhood_filters(effects, res).last() + neighbourhood_filters(effects, res, None).last() } /// Below this a coverage weight counts as no coverage at all. @@ -356,35 +397,40 @@ const SHARPEN_RADIUS: f32 = 1.5; const MIN_SHARPEN_RADIUS: f32 = 0.75; /// The neighbourhood filters of an effect stack, bottom → top: index among the visible effects, radius in texels (`res` texels per UV tile across) and what it does. -fn neighbourhood_filters(effects: &[Effect], res: u32) -> impl Iterator + '_ { +fn neighbourhood_filters(effects: &[Effect], res: u32, channel: Option) -> impl Iterator + '_ { let texels = move |size: f32| (size * res as f32 / FILTER_SIZE_RESOLUTION).max(MIN_FILTER_RADIUS); - effects.iter().filter(|effect| effect.visible).enumerate().filter_map(move |(index, effect)| match &effect.kind { - EffectKind::Filter(Filter::Blur { radius }) if *radius > 0.0 => Some((index, texels(*radius), Op::Blur(None))), - EffectKind::Filter(Filter::Sharpen { amount }) => { - Some((index, (SHARPEN_RADIUS * res as f32 / FILTER_SIZE_RESOLUTION).max(MIN_SHARPEN_RADIUS), Op::Blur(Some(*amount)))) - } - EffectKind::Filter(Filter::DirectionalBlur { radius, angle }) if *radius > 0.0 => Some((index, texels(*radius), Op::Line(direction(*angle)))), - EffectKind::Filter(Filter::Warp { intensity, scale, seed }) if *intensity > 0.0 => { - Some((index, texels(*intensity), Op::Warp { scale: *scale, seed: *seed, dir: None })) - } - EffectKind::Filter(Filter::DirectionalWarp { intensity, angle, scale, seed }) if *intensity > 0.0 => { - Some((index, texels(*intensity), Op::Warp { scale: *scale, seed: *seed, dir: Some(direction(*angle)) })) - } - EffectKind::Filter(Filter::HighPass { radius }) => Some((index, texels(*radius), Op::HighPass)), - EffectKind::Filter(Filter::EdgeDetect { width }) => Some((index, texels(*width), Op::Edge)), - // Three box passes ramp an edge over about twice their radius - EffectKind::Filter(Filter::Bevel { width }) => Some((index, texels(*width * 0.5), Op::Bevel)), - EffectKind::Filter(Filter::Glow { radius, amount }) => Some((index, texels(*radius), Op::Glow(*amount))), - EffectKind::Filter(Filter::Mosaic { size }) => Some((index, texels(*size), Op::Mosaic)), - // Use reference-resolution reach so all callers classify the same filters as stages - EffectKind::Generator(generator) if generator.global.blur > 0.0 || generator.resolution.can_reduce() => { - Some((index, texels(generator.global.blur_radius()) + generator.resolution.largest_cell(res) as f32, Op::Blur(None))) - } - EffectKind::Filter(Filter::SlopeBlur { radius, scale, seed }) if *radius > 0.0 => { - Some((index, texels(*radius), Op::Slope { scale: *scale, seed: *seed })) - } - _ => None, - }) + effects + .iter() + .filter(|effect| effect.visible) + .enumerate() + .filter(move |(_, effect)| channel.is_none_or(|channel| effect.blend_of(Some(channel)).mode != BlendMode::Disable)) + .filter_map(move |(index, effect)| match &effect.kind { + EffectKind::Filter(Filter::Blur { radius }) if *radius > 0.0 => Some((index, texels(*radius), Op::Blur(None))), + EffectKind::Filter(Filter::Sharpen { amount }) => { + Some((index, (SHARPEN_RADIUS * res as f32 / FILTER_SIZE_RESOLUTION).max(MIN_SHARPEN_RADIUS), Op::Blur(Some(*amount)))) + } + EffectKind::Filter(Filter::DirectionalBlur { radius, angle }) if *radius > 0.0 => Some((index, texels(*radius), Op::Line(direction(*angle)))), + EffectKind::Filter(Filter::Warp { intensity, scale, seed }) if *intensity > 0.0 => { + Some((index, texels(*intensity), Op::Warp { scale: *scale, seed: *seed, dir: None })) + } + EffectKind::Filter(Filter::DirectionalWarp { intensity, angle, scale, seed }) if *intensity > 0.0 => { + Some((index, texels(*intensity), Op::Warp { scale: *scale, seed: *seed, dir: Some(direction(*angle)) })) + } + EffectKind::Filter(Filter::HighPass { radius }) => Some((index, texels(*radius), Op::HighPass)), + EffectKind::Filter(Filter::EdgeDetect { width }) => Some((index, texels(*width), Op::Edge)), + // Three box passes ramp an edge over about twice their radius + EffectKind::Filter(Filter::Bevel { width }) => Some((index, texels(*width * 0.5), Op::Bevel)), + EffectKind::Filter(Filter::Glow { radius, amount }) => Some((index, texels(*radius), Op::Glow(*amount))), + EffectKind::Filter(Filter::Mosaic { size }) => Some((index, texels(*size), Op::Mosaic)), + // Use reference-resolution reach so all callers classify the same filters as stages + EffectKind::Generator(generator) if generator.global.blur > 0.0 || generator.resolution.can_reduce() => { + Some((index, texels(generator.global.blur_radius()) + generator.resolution.largest_cell(res) as f32, Op::Blur(None))) + } + EffectKind::Filter(Filter::SlopeBlur { radius, scale, seed }) if *radius > 0.0 => { + Some((index, texels(*radius), Op::Slope { scale: *scale, seed: *seed })) + } + _ => None, + }) } /// Whether any mask or content effect in a texture set reads neighbouring texels. Includes @@ -624,7 +670,14 @@ fn stroke_at(preview: Option<&[u16]>, o: usize) -> f32 { } /// The full stack of tile (tx, ty) in `channels` and the channels the layer's mask compares, when the layer reads the stack below it (else empty) -fn anchor_plan<'a>(inp: &EvaluationInputs<'a>, id: LayerId, channels: &[Channel], tx: u32, ty: u32, fields: Option<&'a Fields>) -> Vec> { +fn anchor_plan<'a>( + inp: &EvaluationInputs<'a>, + (id, instance): (LayerId, usize), + channels: &[Channel], + tx: u32, + ty: u32, + fields: Option<&'a Fields>, +) -> Vec> { let Ok(set) = inp.project.texture_set(inp.ts) else { return Vec::new() }; if !reads_stack(inp.project, id) { return Vec::new(); @@ -632,7 +685,7 @@ fn anchor_plan<'a>(inp: &EvaluationInputs<'a>, id: LayerId, channels: &[Channel] let compare_effects = layer_mask(inp.project, id).into_iter().flat_map(|mask| mask.effects.iter()); let planned = compared_channels(compare_effects, channels.to_vec()); - plan(inp, &set.stack, &planned, tx, ty, 0, fields) + plan_in(inp, &set.stack, &planned, tx, ty, 0, fields, DrawPlacement::default(), Some((id, instance))) } /// `channels` with every channel the Compare effects among `effects` compare added once @@ -647,6 +700,37 @@ fn compared_channels<'e>(effects: impl IntoIterator, mut chan channels } +/// Include material channels that masks read even when the set no longer exports them. +fn evaluation_channels(inp: &Inputs, mut channels: Vec) -> Vec { + fn include_masks(project: &Project, layers: &[LayerId], depth: usize, channels: &mut Vec) { + if depth > texturecraft_core::project::MAX_DEPTH { + return; + } + + for &id in layers { + if let Some(mask) = layer_mask(project, id).filter(|mask| mask.enabled) { + for effect in mask.effects.iter().filter(|effect| effect.visible && effect.kind.reads_stack()) { + if let EffectKind::Compare { channel, .. } = effect.kind + && !channels.contains(&channel) + { + channels.push(channel); + } + } + } + + if let Some(layer) = project.content_layer(id).filter(|layer| !layer.children().is_empty()) { + include_masks(project, layer.children(), depth + 1, channels); + } + } + } + + if let Ok(set) = inp.project.texture_set(inp.ts) { + include_masks(inp.project, &set.stack, 0, &mut channels); + } + + channels +} + /// Whether layer `id` (its own mask, or the content it draws) reads the stack below it: an anchor point, or a compare mask's layer sides pub(crate) fn reads_stack(p: &Project, id: LayerId) -> bool { p.layers.get(&id).is_some_and(Layer::reads_stack) || p.content_layer(id).is_some_and(Layer::reads_stack) @@ -659,14 +743,15 @@ fn layer_mask(p: &Project, id: LayerId) -> Option<&Mask> { /// Layers of `list` in drawing order (bottom → top, folder and instanced folder contents after /// their folder). -fn draw_order(p: &Project, list: &[LayerId], depth: usize, around: ContentsOffset, out: &mut Vec<(LayerId, ContentsOffset)>) { +fn draw_order(inp: &EvaluationInputs, list: &[LayerId], depth: usize, place: DrawPlacement, out: &mut Vec<(LayerId, DrawPlacement)>) { if depth > texturecraft_core::project::MAX_DEPTH { return; } + for id in list { - out.push((*id, around)); - if let Some(l) = p.content_layer(*id) { - draw_order(p, l.children(), depth + 1, around.then(p.contents_offset(l.id)), out); + out.push((*id, place)); + if let Some(layer) = inp.project.content_layer(*id).filter(|layer| !layer.children().is_empty()) { + draw_order(inp, layer.children(), depth + 1, place.children(inp, *id, layer), out); } } } @@ -683,29 +768,30 @@ fn field( inp: &EvaluationInputs, channels: &[Channel], below: &Fields, - (id, around): (LayerId, ContentsOffset), + (id, place): (LayerId, DrawPlacement), job: Job, tiles: &[(u32, u32)], + reader_margin: u32, ) -> Option { - let effects = match job { - Job::Mask(mask) => &mask.effects, - Job::Content(_) => &inp.project.content_layer(id)?.content_effects, + let (effects, channel) = match job { + Job::Mask(mask) => (&mask.effects, None), + Job::Content(channel) => (&inp.project.content_layer(id)?.content_effects, Some(channel)), }; - let filters: Vec<(usize, f32, Op)> = neighbourhood_filters(effects, inp.tile_res()).collect(); + let filters: Vec<(usize, f32, Op)> = neighbourhood_filters(effects, inp.tile_res(), channel).collect(); let longest_side = inp.gbuf.width.max(inp.gbuf.height); // Each filter's region also holds what every filter above it reads around the tiles let mut margins: Vec = filters.iter().map(|&(_, radius, op)| filter_extent(radius, op, longest_side).1.div_ceil(TILE)).collect(); for index in (0..margins.len().saturating_sub(1)).rev() { - margins[index] += margins[index + 1]; + margins[index] = margins[index].saturating_add(margins[index + 1]); } let mut previous: Option<(usize, Field)> = None; let mut anchor_stages = Vec::new(); for (&filter, &margin) in filters.iter().zip(&margins) { - let region = region_around(inp, tiles, margin)?; + let region = region_around(inp, tiles, reader_margin.saturating_add(margin))?; let start = previous.as_ref().map(|(index, field)| (*index, field)); - let filtered = filter_region(inp, channels, below, (id, around), job, effects, filter, region, start)?; + let filtered = filter_region(inp, channels, below, (id, place), job, effects, filter, region, start)?; // Preserve only stages with anchors before the next filter overwrites their value if let Some((previous_index, previous_field)) = previous.take() @@ -732,8 +818,11 @@ fn field( fn region_around(inp: &Inputs, tiles: &[(u32, u32)], margin: u32) -> Option<(u32, u32, u32, u32)> { let (first_x, first_y) = tiles.iter().fold((u32::MAX, u32::MAX), |(min_x, min_y), tile| (min_x.min(tile.0), min_y.min(tile.1))); let (last_x, last_y) = tiles.iter().fold((0, 0), |(max_x, max_y), tile| (max_x.max(tile.0), max_y.max(tile.1))); - let (x0, y0) = (first_x.saturating_sub(margin) * TILE, first_y.saturating_sub(margin) * TILE); - let (x1, y1) = (((last_x + 1 + margin) * TILE).min(inp.gbuf.width), ((last_y + 1 + margin) * TILE).min(inp.gbuf.height)); + let (x0, y0) = (first_x.saturating_sub(margin).saturating_mul(TILE), first_y.saturating_sub(margin).saturating_mul(TILE)); + let (x1, y1) = ( + last_x.saturating_add(1).saturating_add(margin).saturating_mul(TILE).min(inp.gbuf.width), + last_y.saturating_add(1).saturating_add(margin).saturating_mul(TILE).min(inp.gbuf.height), + ); let (w, h) = (x1.saturating_sub(x0), y1.saturating_sub(y0)); (w > 0 && h > 0).then_some((x0, y0, w, h)) } @@ -759,7 +848,7 @@ fn filter_region( inputs: &EvaluationInputs, channels: &[Channel], below: &Fields, - (id, around): (LayerId, ContentsOffset), + (id, place): (LayerId, DrawPlacement), job: Job, effects: &[Effect], (index, radius, op): (usize, f32, Op), @@ -788,12 +877,15 @@ fn filter_region( // Evaluate the stack up to the filter, tile by tile (content premultiplied by coverage) let (region_right, region_bottom) = (region_x + width, region_y + height); - let region_tiles: Vec<(u32, u32)> = - (region_y / TILE..region_bottom.div_ceil(TILE)).flat_map(|y| (region_x / TILE..region_right.div_ceil(TILE)).map(move |x| (x, y))).collect(); - let parts: Vec> = region_tiles - .par_iter() - .map(|&(tile_x, tile_y)| { - let anchor_nodes = anchor_plan(inputs, id, channels, tile_x, tile_y, Some(below)); + let texel_count = width as usize * height as usize; + let mut stack_values = vec![0.0f32; texel_count * components]; + let mut cover = vec![0.0f32; texel_count]; + let band = TILE as usize * width as usize; + + stack_values.par_chunks_mut(band * components).zip(cover.par_chunks_mut(band)).enumerate().for_each(|(row, (values, coverage))| { + let tile_y = region_y / TILE + row as u32; + for tile_x in region_x / TILE..region_right.div_ceil(TILE) { + let anchor_nodes = anchor_plan(inputs, (id, place.instance), channels, tile_x, tile_y, Some(below)); let preview_tile = inputs.preview.and_then(|preview| preview.alpha.tile(tile_x, tile_y)); let mut mask = None; let mut nodes = Vec::new(); @@ -801,8 +893,8 @@ fn filter_region( match job { Job::Mask(layer_mask) => { // The layer's own filtered content, for a compare of it (this mask's field is not built yet) - let Some(mut mask_stack) = mask_plan(inputs, id, layer_mask, tile_x, tile_y, Some(below), around) else { - return Vec::new(); + let Some(mut mask_stack) = mask_plan(inputs, id, layer_mask, tile_x, tile_y, Some(below), place) else { + continue; }; generator_sizes = mask_stack.effects.get(index).and_then(|effect| effect.curvature_sizes.clone()); @@ -811,56 +903,37 @@ fn filter_region( mask = Some(mask_stack); } Job::Content(channel) => { - nodes = plan_in(inputs, &[id], &[channel], tile_x, tile_y, 0, Some(below), around); + nodes = plan_in(inputs, &[id], &[channel], tile_x, tile_y, 0, Some(below), place, None); if let Some(channel_plan) = nodes.first_mut().and_then(|node| node.chans.first_mut()) { channel_plan.effects.truncate(index); channel_plan.start = start; } } } - tile_texels(inputs.gbuf, tile_x, tile_y) - .map(|(x, y, offset)| { - let mut texel = Texel::new(inputs, x, y, offset, stroke_at(preview_tile, offset)); - if !anchor_nodes.is_empty() { - texel.anchors_below(&anchor_nodes, id); + for (x, y, offset) in tile_texels(inputs.gbuf, tile_x, tile_y) { + let mut texel = Texel::new(inputs, x, y, offset, stroke_at(preview_tile, offset)); + if !anchor_nodes.is_empty() { + texel.anchors_below(&anchor_nodes, (id, place.instance)); + } + + let value = match (&mask, nodes.first()) { + (Some(mask_stack), _) => { + let ramp = generator.map_or(0.0, |(generator, _)| texel.generator_ramp(generator, generator_sizes.as_deref())); + [texel.mask(mask_stack), ramp, 0.0, 0.0] } - - let value = match (&mask, nodes.first()) { - (Some(mask_stack), _) => { - let ramp = generator.map_or(0.0, |(generator, _)| texel.generator_ramp(generator, generator_sizes.as_deref())); - [texel.mask(mask_stack), ramp, 0.0, 0.0] - } - (None, Some(node)) => match node.chans.first().and_then(|channel_plan| texel.content(&node.content, channel_plan)) { - Some((color, coverage)) => [color[0] * coverage, color[1] * coverage, color[2] * coverage, coverage], - None => [0.0; 4], - }, - (None, None) => [0.0; 4], - }; - (x, y, value) - }) - .collect() - }) - .collect(); - - // Scatter into the region, a row of tiles at a time (the region is tile aligned) - let texel_count = (width * height) as usize; - let mut stack_values = vec![0.0f32; texel_count * components]; - let mut cover = vec![0.0f32; texel_count]; - let row_tiles = (region_right.div_ceil(TILE) - region_x / TILE).max(1) as usize; - let band = (TILE * width) as usize; - stack_values.par_chunks_mut(band * components).zip(cover.par_chunks_mut(band)).zip(parts.par_chunks(row_tiles)).for_each(|((stack_values, cover), row)| { - for &(x, y, value) in row.iter().flatten() { - let texel = (((y - region_y) % TILE) * width + (x - region_x)) as usize; - if let (Some(covered), Some(pixel)) = (cover.get_mut(texel), stack_values.get_mut(texel * components..(texel + 1) * components)) { - *covered = 1.0; - pixel.copy_from_slice(&value[..components]); + (None, Some(node)) => match node.chans.first().and_then(|channel_plan| texel.content(&node.content, channel_plan)) { + Some((color, coverage)) => [color[0] * coverage, color[1] * coverage, color[2] * coverage, coverage], + None => [0.0; 4], + }, + (None, None) => [0.0; 4], + }; + let texel = ((y % TILE) * width + x - region_x) as usize; + coverage[texel] = 1.0; + values[texel * components..(texel + 1) * components].copy_from_slice(&value[..components]); } } }); - // Release tile scatter data before allocating filter buffers - drop(parts); - // High pass centers on the channel's middle value (0 for signed channels like height) let middle = match job { Job::Content(channel) if channel.kind() == ChannelKind::Signed => 0.0, @@ -875,7 +948,7 @@ fn filter_region( return generator_region(generator, blend, opacity, &stack_values, &cover, (region_x, region_y, width, height), (tile_resolution, texture_set)); } - let scaled_radius = neighbourhood_filters(effects, tile_resolution) + let scaled_radius = neighbourhood_filters(effects, tile_resolution, channel) .find(|filter| filter.0 == index) .map_or(radius_texels, |filter| filter.1.round().clamp(1.0, radius_texels as f32) as u32); if !is_box_blur(op) { @@ -1079,7 +1152,7 @@ fn unpremultiply(data: &mut [f32], comps: usize) { pub fn neighbourhood_fields(inputs: &Inputs, channels: &[Channel], tiles: &[(u32, u32)]) -> Fields { let projectors = ProjectorDepthCache::default(); let inputs = EvaluationInputs::new(inputs, &projectors); - evaluation_fields(&inputs, channels, tiles) + evaluation_fields(&inputs, &evaluation_channels(&inputs, channels.to_vec()), tiles) } fn evaluation_fields(inp: &EvaluationInputs, channels: &[Channel], tiles: &[(u32, u32)]) -> Fields { @@ -1096,49 +1169,87 @@ fn fields_of(inp: &EvaluationInputs, channels: &[Channel], (list, around): (&[La let working_width = inp.gbuf.width; let mut order = Vec::new(); - draw_order(inp.project, list, 0, around, &mut order); + draw_order(inp, list, 0, around.into(), &mut order); let ids: Vec = order.iter().map(|(id, _)| *id).collect(); prepare_curvature_sizes(inp, &ids); - for (id, around) in order { + // Walk backwards to find the region each Compare needs below its position in the stack + let mut below_margin = 0u32; + let margins: Vec<_> = order + .iter() + .rev() + .map(|&(id, _)| { + let mask_margin = below_margin; + let effects = layer_mask(inp.project, id).filter(|mask| mask.enabled).map(|mask| mask.effects.as_slice()).unwrap_or_default(); + let first_reader = effects.iter().filter(|effect| effect.visible).position(|effect| effect.kind.reads_stack()); + if let Some(first_reader) = first_reader { + for (_, radius, op) in neighbourhood_filters(effects, inp.tile_res(), None).filter(|(index, _, _)| *index > first_reader) { + let reach = filter_extent(radius, op, inp.gbuf.width.max(inp.gbuf.height)).1; + below_margin = below_margin.saturating_add(reach.div_ceil(TILE)); + } + } + + (mask_margin, below_margin) + }) + .collect(); + + for ((id, place), (mask_margin, content_margin)) in order.into_iter().zip(margins.into_iter().rev()) { let Some(layer) = inp.project.content_layer(id) else { continue }; let mask = layer_mask(inp.project, id).filter(|mask| mask.enabled && neighbourhood(&mask.effects, working_width).is_some()); - // A mask comparing the layer's own content reads it filtered, so its field comes after the content's + // A mask comparing its own layer needs that layer's filtered content first let compares_content = mask.is_some_and(|mask| mask.effects.iter().any(|effect| effect.visible && compares_this_layer(&effect.kind))); if !compares_content { - insert_mask_field(inp, channels, &mut out, (id, around), mask, tiles); + insert_mask_field(inp, channels, &mut out, (id, place), mask, tiles, mask_margin); } if !layer.is_group() && neighbourhood(&layer.content_effects, working_width).is_some() { for channel in channels.iter().filter(|channel| layer.channels.contains_key(channel)) { - if let Some(filtered) = field(inp, channels, &out, (id, around), Job::Content(*channel), tiles) { - out.insert(FieldKey::content(id, *channel, around), filtered); + let mut key = FieldKey::content(id, *channel, place.offset); + if place.instance != 0 { + let reads_anchor = matches!(&layer.kind, LayerKind::Fill(fill) if fill.sources.get(channel).is_some_and(|source| source.reads_anchor(None))) + || layer.content_effects.iter().any(|effect| effect.visible && effect.kind.reads(None)); + if reads_anchor { + key = key.in_instance(place.instance); + } + } + + if !out.contains_key(&key) + && let Some(filtered) = field(inp, channels, &out, (id, place), Job::Content(*channel), tiles, content_margin) + { + out.insert(key, filtered); } } } if compares_content { - insert_mask_field(inp, channels, &mut out, (id, around), mask, tiles); + insert_mask_field(inp, channels, &mut out, (id, place), mask, tiles, mask_margin); } } out } -/// Layer `id`'s filtered `mask` field put into `fields` (nothing without a mask or a field) +/// Store a filtered mask once per transform, or per draw when it reads the stack. fn insert_mask_field( inp: &EvaluationInputs, channels: &[Channel], fields: &mut Fields, - (id, around): (LayerId, ContentsOffset), + (id, place): (LayerId, DrawPlacement), mask: Option<&Mask>, tiles: &[(u32, u32)], + margin: u32, ) { - if let Some(mask) = mask - && let Some(filtered) = field(inp, channels, fields, (id, around), Job::Mask(mask), tiles) + let Some(mask) = mask else { return }; + let mut key = FieldKey::mask(id, place.offset); + if place.instance != 0 && mask.effects.iter().any(|effect| effect.visible && (effect.kind.reads_stack() || effect.kind.reads(None))) { + key = key.in_instance(place.instance); + } + + if !fields.contains_key(&key) + && let Some(filtered) = field(inp, channels, fields, (id, place), Job::Mask(mask), tiles, margin) { - fields.insert(FieldKey::mask(id, around), filtered); + fields.insert(key, filtered); } } @@ -1168,7 +1279,7 @@ fn prepare_mask_curvature_sizes<'a>(inp: &Inputs, masks: impl Iterator { - id: LayerId, + draw: (LayerId, usize), content: Content<'a>, chans: Vec>, mask: Option>, @@ -1203,16 +1314,18 @@ fn effect_plans<'a>( EffectKind::Generator(Generator { detail: Some(detail), .. }) => CurvatureSizes::of(inp, &detail.blurred_sizes_in_use()), _ => None, }; - let (depth, covers_all) = match &effect.kind { + let (depth, covers_all, projection) = match &effect.kind { EffectKind::Fill { projection, sampling, .. } | EffectKind::Material(Fill { projection, sampling, .. }) => { - fill_coverage(inp, projection, *sampling) + let (depth, covers_all) = fill_coverage(inp, projection, *sampling); + (depth, covers_all, (!around.is_none()).then(|| around.apply(projection))) } - _ => (None, false), + _ => (None, false, None), }; let blend = effect.blend_of(channel); EffectPlan { id: effect.id, - kind: offset_effect(&effect.kind, around), + kind: &effect.kind, + projection, blend: blend.mode, opacity: blend.opacity, data: if effect.kind.painted() { tile_of(inp, image, tile_x, tile_y, channel) } else { None }, @@ -1226,26 +1339,6 @@ fn effect_plans<'a>( .collect() } -/// `kind` with the folders' Scale and Rotation `around` laid on its projection (borrowed where that changes nothing) -fn offset_effect(kind: &EffectKind, around: ContentsOffset) -> Cow<'_, EffectKind> { - match kind { - EffectKind::Fill { source, projection, sampling } if !around.is_none() => { - Cow::Owned(EffectKind::Fill { source: source.clone(), projection: around.apply(projection), sampling: *sampling }) - } - EffectKind::Material(fill) if !around.is_none() => Cow::Owned(EffectKind::Material(offset_fill(fill, around).into_owned())), - _ => Cow::Borrowed(kind), - } -} - -/// `fill` with the folders' Scale and Rotation `around` laid on its projection (borrowed where that changes nothing) -fn offset_fill(fill: &Fill, around: ContentsOffset) -> Cow<'_, Fill> { - if around.is_none() { - return Cow::Borrowed(fill); - } - - Cow::Owned(Fill { projection: around.apply(&fill.projection), ..fill.clone() }) -} - /// Whether the live stroke paints `target` in this composite (a stroke on a layer instanced in a /// set of another size does not show there). fn previews(inp: &Inputs, target: PaintTarget) -> bool { @@ -1278,15 +1371,15 @@ fn mask_plan<'a>( tx: u32, ty: u32, fields: Option<&'a Fields>, - around: ContentsOffset, + place: DrawPlacement, ) -> Option> { if !mask.enabled { return None; } let background = if mask.background == MaskBackground::White { 1.0 } else { 0.0 }; - let mut effects = effect_plans(inp, &mask.effects, tx, ty, None, around); - let filtered = fields.and_then(|fields| fields.get(&FieldKey::mask(id, around))); + let mut effects = effect_plans(inp, &mask.effects, tx, ty, None, place.offset); + let filtered = fields.and_then(|fields| FieldKey::mask(id, place.offset).field(fields, place.instance)); for effect in &mut effects { effect.filtered_mask = filtered.and_then(|field| field.anchor_stages.iter().find(|(id, _)| *id == effect.id).map(|(_, field)| field)); } @@ -1298,7 +1391,7 @@ fn mask_plan<'a>( let layer = if compared.is_empty() { None } else { - inp.project.content_layer(id).and_then(|l| plan_content(inp, id, l, &compared, tx, ty, 0, fields, false, around)) + inp.project.content_layer(id).and_then(|l| plan_content(inp, id, l, &compared, tx, ty, 0, fields, false, place, None)) }; Some(MaskPlan { background, effects, layer, start }) } @@ -1306,10 +1399,10 @@ fn mask_plan<'a>( /// The plans of sibling layers `list` (under the Scale and Rotation of the folders holding them) fn plan<'a>(inp: &EvaluationInputs<'a>, list: &[LayerId], channels: &[Channel], tx: u32, ty: u32, depth: usize, fields: Option<&'a Fields>) -> Vec> { let around = list.first().map_or(ContentsOffset::NONE, |id| inp.project.contents_around(*id)); - plan_in(inp, list, channels, tx, ty, depth, fields, around) + plan_in(inp, list, channels, tx, ty, depth, fields, around.into(), None) } -/// [`plan`] of sibling layers held by folders whose Scale and Rotation make `around` +/// [`plan`] of sibling layers under `around`, with an optional marker for a stack probe #[allow(clippy::too_many_arguments)] fn plan_in<'a>( inp: &EvaluationInputs<'a>, @@ -1319,13 +1412,14 @@ fn plan_in<'a>( ty: u32, depth: usize, fields: Option<&'a Fields>, - around: ContentsOffset, + place: DrawPlacement, + stop: Option<(LayerId, usize)>, ) -> Vec> { if depth > texturecraft_core::project::MAX_DEPTH { return Vec::new(); } - list.iter().filter_map(|id| plan_node(inp, *id, channels, tx, ty, depth, fields, true, around)).collect() + list.iter().filter_map(|id| plan_node(inp, *id, channels, tx, ty, depth, fields, true, place, stop)).collect() } /// The plan of layer `id` at `depth` (None where it draws nothing), its fills under the Scale and Rotation `around` of the folders holding it; a folder's children are planned when `kids` @@ -1339,18 +1433,33 @@ fn plan_node<'a>( depth: usize, fields: Option<&'a Fields>, kids: bool, - around: ContentsOffset, + place: DrawPlacement, + stop: Option<(LayerId, usize)>, ) -> Option> { let own: &'a Layer = inp.project.layers.get(&id)?; + // A stack probe stops here even when this layer draws nothing + if stop == Some((id, place.instance)) { + return Some(Node { + draw: (id, place.instance), + content: Content::Paint { preview: false }, + chans: Vec::new(), + mask: None, + anchors: Vec::new(), + has_anchor: false, + height_mask: HeightMask::default(), + parts: None, + }); + } + // Instances draw their source's content (a missing source draws nothing) let layer: &'a Layer = inp.project.content_layer(id)?; if !own.visible { return None; } - let (content, chans) = plan_content(inp, id, layer, channels, tx, ty, depth, fields, kids, around)?; - let mask = layer_mask(inp.project, id).and_then(|m| mask_plan(inp, id, m, tx, ty, fields, around)); + let (content, chans) = plan_content(inp, id, layer, channels, tx, ty, depth, fields, kids, place, stop)?; + let mask = layer_mask(inp.project, id).and_then(|m| mask_plan(inp, id, m, tx, ty, fields, place)); // Anchors in the mask record even where the layer draws nothing let mask_anchor = mask.as_ref().is_some_and(|m| m.effects.iter().any(|e| matches!(*e.kind, EffectKind::Anchor))); @@ -1363,17 +1472,18 @@ fn plan_node<'a>( return None; } - if chans.is_empty() && !mask_anchor { + let probe_group = stop.is_some() && matches!(&content, Content::Group(children) if !children.is_empty()); + if chans.is_empty() && !mask_anchor && !probe_group { return None; } - let fx = !layer.is_group() && layer.content_effects.iter().any(|e| e.visible); - let anchors = if fx { anchor_cuts(&layer.content_effects) } else { Vec::new() }; + let has_content_effects = !layer.is_group() && layer.content_effects.iter().any(|e| e.visible); + let anchors = if has_content_effects { anchor_cuts(&layer.content_effects) } else { Vec::new() }; let has_anchor = !anchors.is_empty() || mask_anchor || matches!(&content, Content::Group(nodes) if nodes.iter().any(|n| n.has_anchor)); // The geometry mask is the layer's own (an instance in another set has other parts) let parts = own.geometry_mask.as_ref().map(|names| inp.mesh.submeshes.iter().map(|s| names.contains(&s.name)).collect()); - Some(Node { id, content, chans, mask, anchors, has_anchor, height_mask: layer.height_mask, parts }) + Some(Node { draw: (id, place.instance), content, chans, mask, anchors, has_anchor, height_mask: layer.height_mask, parts }) } /// The content of `layer` (layer `id`'s own, or its instance source's; None for an unfollowed instance) and its plan per drawn channel of `channels`, its fills under the Scale and Rotation `around` of the folders holding `id`; a folder's children are planned when `kids` @@ -1388,11 +1498,11 @@ fn plan_content<'a>( depth: usize, fields: Option<&'a Fields>, kids: bool, - around: ContentsOffset, + place: DrawPlacement, + stop: Option<(LayerId, usize)>, ) -> Option<(Content<'a>, Vec>)> { let paint = matches!(layer.kind, LayerKind::Paint); - let fx = !layer.is_group() && layer.content_effects.iter().any(|e| e.visible); - let fx_start = if fx { neighbourhood(&layer.content_effects, inp.gbuf.width).map(|n| n.0) } else { None }; + let has_content_effects = !layer.is_group() && layer.content_effects.iter().any(|e| e.visible); let chans = channels .iter() .filter_map(|c| { @@ -1402,19 +1512,22 @@ fn plan_content<'a>( } let data = if paint { tile_of(inp, inp.pixels.layer(layer.id, *c), tx, ty, Some(*c)) } else { None }; - let effects = if fx { effect_plans(inp, &layer.content_effects, tx, ty, Some(*c), around) } else { Vec::new() }; - let start = fx_start.zip(fields.and_then(|f| f.get(&FieldKey::content(id, *c, around)))); + let effects = if has_content_effects { effect_plans(inp, &layer.content_effects, tx, ty, Some(*c), place.offset) } else { Vec::new() }; + let start = fields + .and_then(|fields| FieldKey::content(id, *c, place.offset).field(fields, place.instance)) + .and_then(|field| neighbourhood_filters(&layer.content_effects, inp.tile_res(), Some(*c)).last().map(|(index, _, _)| (index, field))); Some(ChanPlan { ch: c.index(), kind: c.kind(), comps: c.components(), blend: b.mode, opacity: b.opacity.clamp(0.0, 1.0), data, effects, start }) }) .collect::>(); let content = match &layer.kind { LayerKind::Paint => Content::Paint { preview: previews(inp, PaintTarget::Layer(layer.id)) }, - LayerKind::Fill(f) => { - let (depth, covers_all) = fill_coverage(inp, &f.projection, f.sampling); - Content::Fill { fill: Box::new(offset_fill(f, around)), depth, covers_all } + LayerKind::Fill(fill) => { + let (depth, covers_all) = fill_coverage(inp, &fill.projection, fill.sampling); + let projection = (!place.offset.is_none()).then(|| Box::new(place.offset.apply(&fill.projection))); + Content::Fill { fill, projection, depth, covers_all } } - LayerKind::Group { children, contents, .. } => { - Content::Group(if kids { plan_in(inp, children, channels, tx, ty, depth + 1, fields, around.then(*contents)) } else { Vec::new() }) + LayerKind::Group { children, .. } => { + Content::Group(if kids { plan_in(inp, children, channels, tx, ty, depth + 1, fields, place.children(inp, id, layer), stop) } else { Vec::new() }) } // `content_layer` already followed instance links @@ -1449,9 +1562,9 @@ fn plan_levels<'a>(inp: &EvaluationInputs<'a>, levels: &[Level], channels: &[Cha .zip(level_offsets(inp.project, levels)) .enumerate() .map(|(d, (l, around))| LevelPlan { - below: if warm { Vec::new() } else { plan_in(inp, &l.below, channels, tx, ty, d, Some(fields), around) }, - at: plan_node(inp, l.at, channels, tx, ty, d, Some(fields), d == last, around), - above: plan_in(inp, &l.above, channels, tx, ty, d, Some(fields), around), + below: if warm { Vec::new() } else { plan_in(inp, &l.below, channels, tx, ty, d, Some(fields), around.into(), None) }, + at: plan_node(inp, l.at, channels, tx, ty, d, Some(fields), d == last, around.into(), None), + above: plan_in(inp, &l.above, channels, tx, ty, d, Some(fields), around.into(), None), }) .collect() } @@ -1491,15 +1604,15 @@ fn repeats_everywhere(proj: &Projection, sampling: Sampling) -> bool { } /// Whether a fill placed by `proj` covers every texel: it repeats, nothing crops or culls it and it is not framed on the surface -fn covers_every_texel(proj: &Projection, sampling: Sampling, depth: Option<&ProjectorDepth>) -> bool { +fn covers_every_texel(proj: &Projection, sampling: Sampling, depth: Option<&FillDepth>) -> bool { let framed = matches!(proj, Projection::Planar { placed: Some(_), .. } | Projection::Warp { .. }); let depth_culled = depth.is_some() && proj.depth_culling().is_some(); !framed && !depth_culled && repeats_everywhere(proj, sampling) && projector_covers_all(proj) } /// A fill's projector depth (None: not culled by depth) and whether it covers every texel -fn fill_coverage(inp: &EvaluationInputs, projection: &Projection, sampling: Sampling) -> (Option>, bool) { - let depth = inp.projectors.get(inp.mesh, inp.bounds, projection); +fn fill_coverage(inp: &EvaluationInputs, projection: &Projection, sampling: Sampling) -> (Option>, bool) { + let depth = inp.projector_depth(projection, sampling); let covers_all = covers_every_texel(projection, sampling, depth.as_deref()); (depth, covers_all) } @@ -1520,7 +1633,7 @@ struct Texel<'a, 'b> { coords: Option, stroke: f32, /// `eval` stops when it reaches this layer. - stop: Option, + stop: Option<(LayerId, usize)>, /// Stack values recorded by the anchor points evaluated so far; true marks a mask anchor (gray, not channel values). anchors: Vec<(LayerId, Acc, bool)>, /// The stack below the layer whose mask compares its channels (recorded by `eval` there, or where it stops) @@ -1528,7 +1641,7 @@ struct Texel<'a, 'b> { /// Where `eval` takes layer masks and content from. tape: Tape<'b>, /// The copy of a symmetric fill being sampled: the surface point and normal it sees, and its image's flip - copy: Option, + copy: Option<(usize, FillCopy)>, } /// What a layer contributes (its mask, its content value and coverage per channel): evaluated @@ -1665,17 +1778,33 @@ impl<'a, 'b> Texel<'a, 'b> { framed_cover(proj, s.pos, s.nrm, center).map(|(uv, _)| Coords { uv, ..c }) } - /// Image texels one surface texel spans at each of `samples`, from the next texel across and down (1 at a seam) + /// Image texels spanned by one surface texel in each projection plane. fn footprints(&self, proj: &Projection, samples: &[(Vec2, f32); 3], image: &ImageRes) -> [f32; 3] { let size = Vec2::new(image.width as f32, image.height as f32); + if matches!(proj, Projection::Uv { .. } | Projection::UvTile) { + // Use the current tile's affine mapping even where a neighbor wraps or is uncovered + let step = self.inp.mesh_uv_step(self.x, self.y); + let span = if let Projection::Uv { scale, rotation, .. } = proj { + let transform = placement(Vec2::from(*scale), *rotation, Vec2::ZERO); + let across = (transform(Vec2::new(step.x, 0.0)) * size).length(); + let down = (transform(Vec2::new(0.0, step.y)) * size).length(); + across.max(down) + } else { + (step * size).max_element() + }; + return [if span.is_finite() { span.max(1.0) } else { 1.0 }, 1.0, 1.0]; + } + let mut out = [1.0f32; 3]; + let seam_limit = size.max_element() * SEAM_JUMP_SHARE; for (dx, dy) in [(1, 0), (0, 1)] { let Some(next) = self.projected_at(proj, self.x + dx, self.y + dy) else { continue }; + for ((footprint, (uv, _)), (next_uv, _)) in out.iter_mut().zip(samples).zip(self.image_uvs(proj, &next)) { let span = ((next_uv - *uv) * size).length(); - // A jump across more of the image than this is a UV seam, not the texel's size - if span.is_finite() && span < size.max_element() * SEAM_JUMP_SHARE { + // Projected neighbors can land on disconnected surfaces at a UV seam + if span.is_finite() && span < seam_limit { *footprint = footprint.max(span); } } @@ -1692,7 +1821,7 @@ impl<'a, 'b> Texel<'a, 'b> { #[inline(always)] fn surface(&self, i: usize) -> Option { let mut s = self.inp.gbuf.surface(self.inp.mesh, i)?; - if let Some(copy) = self.copy { + if let Some((_, copy)) = self.copy { s.pos = copy.point(s.pos); s.nrm = copy.normal(s.nrm); s.geo_nrm = copy.normal(s.geo_nrm); @@ -1704,7 +1833,7 @@ impl<'a, 'b> Texel<'a, 'b> { fn image_uvs(&self, proj: &Projection, coords: &Coords) -> [(Vec2, f32); 3] { let samples = image_samples(proj, coords); match self.copy { - Some(copy) => samples.map(|(uv, weight)| (copy.uv(uv), weight)), + Some((_, copy)) => samples.map(|(uv, weight)| (copy.uv(uv), weight)), None => samples, } } @@ -1729,8 +1858,9 @@ impl<'a, 'b> Texel<'a, 'b> { let cached = self.coords.take(); let mut value = [0.0f32; 3]; let mut cover = 0.0f32; - for copy in FillCopies::new(&sampling.symmetry, world, center, radius) { - self.copy = Some(copy); + let mut copies = FillCopies::new(&sampling.symmetry, world, center, radius); + while let Some((index, copy)) = copies.next_indexed() { + self.copy = Some((index, copy)); self.coords = None; let (copy_value, copy_cover) = one(self); let weight = copy_cover.clamp(0.0, 1.0) * (1.0 - cover); @@ -1787,8 +1917,8 @@ impl<'a, 'b> Texel<'a, 'b> { #[inline(always)] fn fill_place_texel(&mut self, place: FillPlace, source: Option<&Source>, ch: Channel) -> ([f32; 3], f32) { // Sample directly without symmetry to keep the common path free of the copy search - if takes_symmetry(&place.fill.projection, place.fill.sampling) { - self.symmetric(&place.fill.projection, place.fill.sampling, |texel| texel.fill_texel(place, source, ch)) + if takes_symmetry(place.projection, place.fill.sampling) { + self.symmetric(place.projection, place.fill.sampling, |texel| texel.fill_texel(place, source, ch)) } else { self.fill_texel(place, source, ch) } @@ -1797,23 +1927,26 @@ impl<'a, 'b> Texel<'a, 'b> { /// `place`'s fill sampled once at this texel: its value in channel `ch` (`source`, else the channel's default) and its coverage #[inline(always)] fn fill_texel(&mut self, place: FillPlace, source: Option<&Source>, ch: Channel) -> ([f32; 3], f32) { - let FillPlace { fill, depth, covers_all } = place; + let FillPlace { fill, projection, depth, covers_all } = place; let value = match source { - Some(source) => self.source(source, &fill.projection, fill.sampling, ch.kind()), + Some(source) => self.source(source, projection, fill.sampling, ch.kind()), None => ch.default_value(), }; - let cover = if covers_all { 1.0 } else { self.cover(fill.sources.values(), &fill.projection, fill.sampling, depth) }; + let cover = if covers_all { 1.0 } else { self.cover(fill.sources.values(), projection, fill.sampling, depth) }; (value, cover) } /// How much a fill projected by `proj` covers this texel: [`Texel::shape_cover`], then depth culling through the projector's `depth` map - fn cover<'s>(&mut self, sources: impl Iterator, proj: &Projection, sampling: Sampling, depth: Option<&ProjectorDepth>) -> f32 { + fn cover<'s>(&mut self, sources: impl Iterator, proj: &Projection, sampling: Sampling, depth: Option<&FillDepth>) -> f32 { #[cfg(test)] tests::COVER_CALLS.with(|count| count.set(count.get() + 1)); let cover = self.shape_cover(sources, proj, sampling); match depth.zip(proj.depth_culling()) { - Some((depth, culling)) if cover > 0.0 => cover * self.world().map_or(1.0, |p| depth.cover(p, culling.hardness)), + Some((depth, culling)) if cover > 0.0 => { + let copy_index = self.copy.map_or(0, |(index, _)| index); + cover * self.world().map_or(1.0, |point| depth.cover(copy_index, point, culling.hardness)) + } _ => cover, } } @@ -1830,28 +1963,28 @@ impl<'a, 'b> Texel<'a, 'b> { return self.tile_cover(proj, &coords, sampling) * projector_cover(proj, &coords); }; - let (c, cover) = self.projected(proj); - if projector.crop == ShapeCrop::ExtendsOutside { - return cover * self.tile_cover(proj, &c, sampling); + let (coords, cover) = self.projected(proj); + if projector.crop == ShapeCrop::ExtendsOutside || projector.ignore_image_alpha { + return cover * self.tile_cover(proj, &coords, sampling); } // Cropped to its shape, a framed projection takes the shape of its image too - let image = sources.find_map(|s| match s { + let image = sources.find_map(|source| match source { Source::Image { name, .. } => self.inp.images.get(name), _ => None, }); - let samples = self.image_uvs(proj, &c); + let samples = self.image_uvs(proj, &coords); let [(uv, _), ..] = samples; // Use the image's sampling footprint so minified color and coverage agree - let alpha = image.map_or(1.0, |img| { + let alpha = image.map_or(1.0, |image| { let [footprint, ..] = match sampling.filtering { - Filtering::BilinearHq => self.footprints(proj, &samples, img), + Filtering::BilinearHq => self.footprints(proj, &samples, image), Filtering::BilinearSharp | Filtering::Nearest => [1.0; 3], }; - img.sample_filtered(uv.x, uv.y, sampling, footprint)[3].clamp(0.0, 1.0) + image.sample_alpha(uv.x, uv.y, sampling, footprint).clamp(0.0, 1.0) }); - cover * alpha * self.tile_cover(proj, &c, sampling) + cover * alpha * self.tile_cover(proj, &coords, sampling) } /// The stack value anchor point `anchor` recorded for `channel` (the channel default for an @@ -1917,16 +2050,26 @@ impl<'a, 'b> Texel<'a, 'b> { Filtering::BilinearHq => self.footprints(projection, &samples, image), Filtering::BilinearSharp | Filtering::Nearest => [1.0; 3], }; - let mut sum = [0.0f32; 4]; - for ((uv, weight), footprint) in samples.into_iter().zip(footprints).filter(|((_, weight), _)| *weight > 0.0) { - for (total, value) in sum.iter_mut().zip(image.sample_filtered(uv.x, uv.y, sampling, footprint)) { + + // Blend projected planes in the same space when any of them reads a linear mip + let is_srgb_color = kind == ChannelKind::Color && image.srgb; + let planes = samples.into_iter().zip(footprints).filter(|((_, weight), _)| *weight > 0.0); + let blend_linear = is_srgb_color && planes.clone().any(|(_, footprint)| crate::store::uses_mips(footprint)); + let mut rgb = [0.0; 3]; + for ((uv, weight), footprint) in planes { + let sampled = if blend_linear { + image.sample_srgb_color(uv.x, uv.y, sampling, footprint) + } else { + image.sample_filtered(uv.x, uv.y, sampling, footprint) + }; + + for (total, value) in rgb.iter_mut().zip(sampled) { *total += value * weight; } } - let rgb = [sum[0], sum[1], sum[2]]; match kind { - ChannelKind::Color if image.srgb => rgb.map(texturecraft_texel::srgb_to_linear), + ChannelKind::Color if is_srgb_color && !blend_linear => rgb.map(texturecraft_texel::srgb_to_linear), // Normal channels are OpenGL (+Y up the image): a DirectX image's green flips ChannelKind::NormalMap if *normal_format == NormalFormat::DirectX => [rgb[0], 1.0 - rgb[1], rgb[2]], @@ -2088,7 +2231,7 @@ impl<'a, 'b> Texel<'a, 'b> { } let opacity = effect.opacity.clamp(0.0, 1.0); - match &*effect.kind { + match effect.kind { EffectKind::Paint | EffectKind::Path(_) => { let (mut painted, mut coverage) = match effect.data.as_deref() { Some(data) => (from_u16(data.get(self.o * 2).copied().unwrap_or(0)), from_u16(data.get(self.o * 2 + 1).copied().unwrap_or(0))), @@ -2117,11 +2260,13 @@ impl<'a, 'b> Texel<'a, 'b> { } } EffectKind::Fill { source, projection, sampling } => { + let projection = effect.projection.as_ref().unwrap_or(projection); let once = |texel: &mut Self| { let fill = texel.source(source, projection, *sampling, ChannelKind::Scalar); let cover = if effect.covers_all { 1.0 } else { texel.cover(std::iter::once(source), projection, *sampling, effect.depth.as_deref()) }; (fill, cover) }; + // Sampled directly without symmetry, as `Texel::fill_place_texel` is let ([fill, ..], cover) = if takes_symmetry(projection, *sampling) { self.symmetric(projection, *sampling, once) } else { once(self) }; value += (blend1(effect.blend, value, fill) - value) * opacity * cover; @@ -2132,7 +2277,7 @@ impl<'a, 'b> Texel<'a, 'b> { } EffectKind::Levels(levels) => value += (levels.apply(value) - value) * opacity, EffectKind::Filter(filter) => { - // A mask is gray (HSL only changes its lightness); neighbourhood filters come precomputed through `MaskPlan::start` + // A gray mask uses HSL lightness and reads neighbourhoods from the prepared mask plan let filtered = filter.point(ChannelKind::Scalar, [value; 3]).map_or(value, |gray| gray[0]); value += (filtered - value) * opacity; } @@ -2186,7 +2331,7 @@ impl<'a, 'b> Texel<'a, 'b> { /// Composite `nodes` over `acc`, recording anchors; true when it reached the `stop` layer (`acc` then holds the stack below it) fn eval(&mut self, nodes: &[Node], acc: &mut Acc) -> bool { for node in nodes { - if self.stop == Some(node.id) { + if self.stop == Some(node.draw) { self.below = Some(*acc); return true; } @@ -2279,12 +2424,14 @@ impl<'a, 'b> Texel<'a, 'b> { reach = d; break; } + let mut acc = accs.get(reach).copied().unwrap_or(acc); if reach == last && let Some(hot) = levels.get(last).and_then(|l| l.at.as_ref()) { self.eval(std::slice::from_ref(hot), &mut acc); } + // Back up: the layers after the path, then each folder's mix over the stack outside it for d in (0..=reach).rev() { if let Some(lv) = levels.get(d) { @@ -2331,15 +2478,16 @@ impl<'a, 'b> Texel<'a, 'b> { let first = tri.saturating_mul(3); let subs = &self.inp.mesh.submeshes; let holds = |k: usize| subs.get(k).is_some_and(|s| s.start <= first && first < s.start.saturating_add(s.count)); + // Submeshes are in index order; anything else is searched let k = subs.partition_point(|s| s.start <= first).checked_sub(1).filter(|k| holds(*k)).or_else(|| (0..subs.len()).find(|k| holds(*k))); k.and_then(|k| allowed.get(k).copied()).unwrap_or(true) } /// Record the anchors of the stack below layer `id` (`full` is the planned stack), to evaluate that layer on its own - fn anchors_below(&mut self, full: &[Node], id: LayerId) { + fn anchors_below(&mut self, full: &[Node], draw: (LayerId, usize)) { self.anchors.clear(); - self.stop = Some(id); + self.stop = Some(draw); let mut acc = Channel::ALL.map(Channel::default_value); self.eval(full, &mut acc); self.stop = None; @@ -2360,10 +2508,11 @@ impl<'a, 'b> Texel<'a, 'b> { } None => { let (value, coverage) = match content { - Content::Fill { fill, depth, covers_all } => { + Content::Fill { fill, projection, depth, covers_all } => { let ch = Channel::ALL.get(chan_plan.ch).copied()?; let source = fill.sources.get(&ch); - self.fill_place_texel(FillPlace { fill, depth: depth.as_deref(), covers_all: *covers_all }, source, ch) + let projection = projection.as_deref().unwrap_or(&fill.projection); + self.fill_place_texel(FillPlace { fill, projection, depth: depth.as_deref(), covers_all: *covers_all }, source, ch) } Content::Paint { preview } => self.painted(chan_plan.data.as_deref(), chan_plan, *preview), Content::Group(_) => return None, @@ -2436,15 +2585,20 @@ impl<'a, 'b> Texel<'a, 'b> { /// Apply one content effect to a channel's straight value and coverage fn content_effect(&mut self, effect: &EffectPlan, chan_plan: &ChanPlan, value: [f32; 3], coverage: f32) -> ([f32; 3], f32) { + if effect.blend == BlendMode::Disable && effect.kind.blends() { + return (value, coverage); + } + let opacity = effect.opacity.clamp(0.0, 1.0); - match &*effect.kind { + match effect.kind { EffectKind::Paint | EffectKind::Path(_) => { let (painted, painted_coverage) = self.painted(effect.data.as_deref(), chan_plan, effect.preview); over(chan_plan, effect.blend, value, coverage, painted, painted_coverage * opacity) } EffectKind::Material(fill) => match Channel::ALL.get(chan_plan.ch).and_then(|ch| fill.sources.get(ch).map(|source| (*ch, source))) { Some((ch, source)) => { - let place = FillPlace { fill, depth: effect.depth.as_deref(), covers_all: effect.covers_all }; + let projection = effect.projection.as_ref().unwrap_or(&fill.projection); + let place = FillPlace { fill, projection, depth: effect.depth.as_deref(), covers_all: effect.covers_all }; let (material_value, weight) = self.fill_place_texel(place, Some(source), ch); over(chan_plan, effect.blend, value, coverage, material_value, weight * opacity) } @@ -2503,8 +2657,13 @@ pub fn composite_tiles(inp: &Inputs, out: &mut Composite, tiles: &[(u32, u32)]) pub const BLOCK: u32 = 16; /// [`composite_tiles`], serving everything but the hot layer from `below` where it can (and -/// filling it). Results are identical to [`composite_tiles`]. -pub fn composite_tiles_cached(inputs: &Inputs, out: &mut Composite, tiles: &[(u32, u32)], below: Option<&mut BelowCache>) { +/// filling it). The borrowed mesh is fingerprinted once per batch. Callers with an owned mesh +/// can use [`composite_tiles_with_projectors`] for constant-time identity checks. +pub fn composite_tiles_cached(inputs: &Inputs, out: &mut Composite, tiles: &[(u32, u32)], mut below: Option<&mut BelowCache>) { + if let Some(cache) = below.as_deref_mut() { + cache.bind_borrowed_mesh(inputs.mesh); + } + let projectors = ProjectorDepthCache::default(); let inputs = EvaluationInputs::new(inputs, &projectors); composite_evaluation_tiles(&inputs, out, tiles, below); @@ -2524,10 +2683,9 @@ pub fn composite_tiles_with_projectors( return; } - if projectors.bind(mesh) - && let Some(cache) = below.as_deref_mut() - { - cache.clear(); + projectors.bind(mesh); + if let Some(cache) = below.as_deref_mut() { + cache.bind_mesh(mesh); } let inputs = EvaluationInputs::new(inputs, projectors); @@ -2552,7 +2710,7 @@ fn composite_evaluation_tiles(inp: &EvaluationInputs, out: &mut Composite, tiles blocks.entry((t.1 / BLOCK, t.0 / BLOCK)).or_default().push(*t); } - let channels = set.channel_list(); + let channels = evaluation_channels(inp, set.channel_list()); let hot = split.as_deref().and_then(<[Level]>::last); // A stroke preview is absent from StackKey, so it disables field retention @@ -2610,7 +2768,7 @@ fn composite_evaluation_tiles(inp: &EvaluationInputs, out: &mut Composite, tiles }; let cached = below.as_deref().zip(split.as_deref()); - let records = composite_block(inp, &set.stack, out, block, cached, quota, &fields); + let records = composite_block(inp, (&set.stack, &channels), out, block, cached, quota, &fields); if let Some(b) = below.as_deref_mut() { for t in block { b.touch(*t); @@ -2628,10 +2786,10 @@ fn composite_evaluation_tiles(inp: &EvaluationInputs, out: &mut Composite, tiles } /// Whether a layer drawn by `stack` has a neighbourhood filter in its mask or content effects. -fn has_neighbourhood(inp: &Inputs, stack: &[LayerId]) -> bool { +fn has_neighbourhood(inp: &EvaluationInputs, stack: &[LayerId]) -> bool { let working_width = inp.gbuf.width; let mut order = Vec::new(); - draw_order(inp.project, stack, 0, ContentsOffset::NONE, &mut order); + draw_order(inp, stack, 0, DrawPlacement::default(), &mut order); order.into_iter().any(|(id, _)| { let masked = layer_mask(inp.project, id).is_some_and(|mask| mask.enabled && neighbourhood(&mask.effects, working_width).is_some()); masked || inp.project.content_layer(id).is_some_and(|layer| !layer.is_group() && neighbourhood(&layer.content_effects, working_width).is_some()) @@ -2673,7 +2831,7 @@ type Joined = (Vec>>>, bool); /// returns what to cache (for at most `quota` tiles). fn composite_block( inp: &EvaluationInputs, - stack: &[LayerId], + (stack, planned_channels): (&[LayerId], &[Channel]), out: &mut Composite, tiles: &[(u32, u32)], below: Option<(&BelowCache, &[Level])>, @@ -2699,8 +2857,8 @@ fn composite_block( .map(|&((tx, ty), band)| { let warm = cached((tx, ty)).and_then(|b| b.get(band as usize)); let record = warm.is_none() && recorded.contains(&(tx, ty)); - let levels = split.map(|l| plan_levels(inp, l, &channels, tx, ty, fields, warm.is_some())); - let nodes = if levels.is_none() { plan(inp, stack, &channels, tx, ty, 0, Some(fields)) } else { Vec::new() }; + let levels = split.map(|l| plan_levels(inp, l, planned_channels, tx, ty, fields, warm.is_some())); + let nodes = if levels.is_none() { plan(inp, stack, planned_channels, tx, ty, 0, Some(fields)) } else { Vec::new() }; let rows = (BAND * TILE) as usize; let mut level_values = vec![defaults; level_count]; let mut masks = vec![0.0f32; level_count]; @@ -2951,7 +3109,7 @@ pub fn mask_texels(inputs: &Inputs, id: LayerId) -> Option> { let projectors = ProjectorDepthCache::default(); let inputs = &EvaluationInputs::new(inputs, &projectors); let mask = layer_mask(inputs.project, id).filter(|mask| mask.enabled)?; - let channels = inputs.project.texture_set(inputs.ts).map(|set| set.channel_list()).unwrap_or_default(); + let channels = evaluation_channels(inputs, inputs.project.texture_set(inputs.ts).map(|set| set.channel_list()).unwrap_or_default()); let (width, height) = (inputs.gbuf.width, inputs.gbuf.height); let coordinates = all_tiles(width, height); @@ -2981,12 +3139,14 @@ pub fn mask_texels(inputs: &Inputs, id: LayerId) -> Option> { /// The layer mask as a square grayscale image, using nearest texels and black outside the mesh /// Keep preview tiles at 8 bits instead of retaining the export's full float atlas -/// Returns None without an enabled mask +/// Returns None without an enabled mask or when the pixel count exceeds the supported range pub fn mask_image(inputs: &Inputs, id: LayerId, size: u32) -> Option> { + let size = size.max(1); + let pixel_count = usize::try_from(size.checked_mul(size)?).ok()?; let projectors = ProjectorDepthCache::default(); let inputs = &EvaluationInputs::new(inputs, &projectors); let mask = layer_mask(inputs.project, id).filter(|mask| mask.enabled)?; - let channels = inputs.project.texture_set(inputs.ts).map(|set| set.channel_list()).unwrap_or_default(); + let channels = evaluation_channels(inputs, inputs.project.texture_set(inputs.ts).map(|set| set.channel_list()).unwrap_or_default()); let (width, height) = (inputs.gbuf.width, inputs.gbuf.height); let coordinates = all_tiles(width, height); @@ -2994,7 +3154,6 @@ pub fn mask_image(inputs: &Inputs, id: LayerId, size: u32) -> Option> { prepare_mask_curvature_sizes(inputs, std::iter::once(mask)); let fields = evaluation_fields(inputs, &channels, &coordinates); - let size = size.max(1); if size <= width.min(height) && (width != size || height != size) { return Some(downsample_mask(inputs, id, mask, &channels, &fields, size)); } @@ -3021,7 +3180,9 @@ pub fn mask_image(inputs: &Inputs, id: LayerId, size: u32) -> Option> { return Some(atlas); } - let mut output = vec![0u8; (size * size) as usize]; + let mut output = Vec::new(); + output.try_reserve_exact(pixel_count).ok()?; + output.resize(pixel_count, 0); for y in 0..size { for x in 0..size { let sample_x = (u64::from(x) * u64::from(width) / u64::from(size)) as u32; @@ -3093,7 +3254,7 @@ pub fn mask_values_into(inputs: &Inputs, id: LayerId, tiles: &[(u32, u32)], imag let projectors = ProjectorDepthCache::default(); let inputs = &EvaluationInputs::new(inputs, &projectors); let mask = layer_mask(inputs.project, id)?; - let channels = inputs.project.texture_set(inputs.ts).ok()?.channel_list(); + let channels = evaluation_channels(inputs, inputs.project.texture_set(inputs.ts).ok()?.channel_list()); prepare_mask_curvature_sizes(inputs, std::iter::once(mask)); let fields = evaluation_fields(inputs, &channels, tiles); @@ -3139,7 +3300,7 @@ pub fn mask_at(inputs: &Inputs, id: LayerId, texels: &[(u32, u32)]) -> Option