A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
feat(render): a sprite can be cut by another sprite's shape
esengine7bd704699b6b
diff --git a/.github/workflows/build.yml b/.github/workflows/build.ymlindex 85ea7107d..4845daa68 100644--- a/.github/workflows/build.yml+++ b/.github/workflows/build.yml@@ -29,7 +29,7 @@ env:test_registry_ondestroy test_view_api_matrixtest_shader_device test_draw_params test_texture_fb test_buffer_devicetest_compressed_format test_batch_builder test_boundary_span test_webgpu_device- test_clip_depth test_sort_key test_shadow_atlas test_particle_shapes test_lod_selection test_hdr_format+ test_clip_depth test_sort_key test_sprite_mask_range test_shadow_atlas test_particle_shapes test_lod_selection test_hdr_formattest_text_edit test_render_graph test_device_loss test_physics_interpolationtest_bitmap_font test_texture_cache test_mesh_recovery test_aot_host test_aot_conformancetest_frame_lifecyclediff --git a/CHANGELOG.md b/CHANGELOG.mdindex 1ee45ca77..ca124abf4 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -16,6 +16,49 @@ published separately; it ships inside the editor.### Added+- **A sprite can be cut by another sprite's shape.** 2D needed a hole and had no way to+ make one: a blood bar that fills, a torch clearing fog, a character seen through a+ window. `SpriteMask` turns an entity's OWN `Sprite` into the stencil — not a second+ texture field on a mask component, because everything a mask shape needs (texture,+ size, pivot, flips, 9-slice) the sprite already says, and a second one is a second+ thing to keep in step with what the author sees. While it is masking, the mask's+ sprite is not drawn; turning it off puts the picture back, which is what makes+ "is this masking?" answerable by looking.++ Cutting is opt-in per sprite (`Sprite.maskInteraction`: `VisibleInside` for a window,+ `VisibleOutside` for a hole), so a mask added to a scene can never make an unrelated+ sprite vanish.++ Reach is a RANGE, not a subtree. What a 2D mask cuts is rarely its own children — fog+ belongs to no part of the torch clearing it — so a mask reaches the sprites drawn+ after it, in the order the author already arranges by layer and order. That is also+ the order its stencil is written in, so nothing had to be added to the sort key to+ make the mask come first; a sprite at the mask's exact layer AND order is not cut at+ all, because those two have no order between them. `UIMask` keeps the subtree rule,+ because a UI tree IS its containment.++ `GfxStencilMode` gains `TestOutside` (compare NotEqual) on both backends — the engine+ could only ever test INSIDE a stencil, so a hole was not expressible. The state flags+ now resolve to a mode through one function rather than in each caller's words: the+ first version of that mapping had no criterion over it, and sabotage proved it —+ ignoring the outside bit entirely left every test green.++ The stencil clears on the same terms as depth, which it shares an attachment with. A+ frame keeping the last one's stencil cuts along a mask that has since moved.++ The reach rule is a pure header (`SpriteMaskRange.hpp`) held by `test_sprite_mask_range`,+ because a frame can show that SOME mask won and never which one the rule chose. Four+ sabotages, each reddening its own case: reaching backwards, choosing the farthest mask+ instead of the nearest, ignoring a stated range, and picking a mask that never got a+ stencil ref — which would test ref 0, every unmasked pixel in the frame.++ What a frame CAN show is held by the `sprite-mask` pixel scene: one mask, both its+ sides, and a bar that never asked to be cut. Dropping the resolver paints the frame+ red; mapping `TestOutside` to Equal leaves the right half black. And `space-shooter`+ now draws its hull as one, because a capability no game has called is a promise with+ nothing behind it — the fill is cut rather than scaled, so the art never stretches+ with the number, and the lost segment is the same mask's other side.+- **A subtree can sort as one unit.** `sprite.order` is a promise about one spriteagainst everything else in its layer, and that stops scaling the moment twoassembled characters overlap: raising a weapon over the other character raises itdiff --git a/desktop b/desktopindex 307ebb2ed..3b463c66c 160000--- a/desktop+++ b/desktop@@ -1 +1 @@-Subproject commit 307ebb2ed7fc4f310cd4adb06ea3383ecdb661c3+Subproject commit 3b463c66c6366db52eaa6b5c0f093e52c69a87a8diff --git a/docs/astro/src/content/docs/graphics/sprites.mdx b/docs/astro/src/content/docs/graphics/sprites.mdxindex 19005be8e..d4df9a068 100644--- a/docs/astro/src/content/docs/graphics/sprites.mdx+++ b/docs/astro/src/content/docs/graphics/sprites.mdx@@ -167,6 +167,45 @@ the block does not come apart around a sibling of the arm.is a promise about the group's own place, so give the group a place of its own.</Aside>+### Sprite masks++A `SpriteMask` turns an entity's **own sprite** into a stencil: sprites drawn after it+that ask to be masked are cut by its shape. Nothing else about the sprite changes — the+texture, size, pivot, flips and 9-slice are the ones you already authored — and while it+is masking, the mask's sprite is not drawn. It is the cut, not a picture.++```typescript+world.insert(hole, SpriteMask, { alphaCutoff: 0.5 });+world.update(fog, Sprite, (s) => {+ s.maskInteraction = SpriteMaskInteraction.VisibleOutside; // a hole in the fog+});+```++Masking is **opt-in per sprite** (`Sprite.maskInteraction`), so adding a mask to a scene+can never make an unrelated sprite vanish:++| `maskInteraction` | What survives |+|---|---|+| `None` (default) | The mask is ignored. |+| `VisibleInside` | Only the part over the mask — a window. |+| `VisibleOutside` | Only the part away from it — a hole. |++`alphaCutoff` above 0 cuts to the sprite's **shape** rather than its box: fragments below+that alpha do not mask, so a round mask cuts a circle.++A mask reaches **forward** — it cuts what is drawn after it, in the order you already+arrange by layer and order. That is the order its stencil is written in, so a sprite at+the same layer *and* order as the mask is not cut at all. Turn on `limitRange` to stop+the reach at a stated layer and order.++<Aside type="caution">+ Where two masks overlap, the **nearer** one decides — it wrote last, and that is what+ the stencil holds. A sprite cut by the farther mask would disappear exactly inside the+ nearer one, so only one mask cuts any given sprite.+</Aside>++A mask cuts the picture, not the scene: picking, physics and queries do not see it.+### Scene order breaks the tieSame layer, same z? Then **scene order** decides: the engine draws entities in thediff --git a/docs/astro/src/content/docs/zh-cn/graphics/sprites.mdx b/docs/astro/src/content/docs/zh-cn/graphics/sprites.mdxindex 1bf06eabe..7c85a8c3e 100644--- a/docs/astro/src/content/docs/zh-cn/graphics/sprites.mdx+++ b/docs/astro/src/content/docs/zh-cn/graphics/sprites.mdx@@ -146,6 +146,41 @@ world.update(arm, Sprite, (s) => { s.order = 1; });"没有东西落在成员之间"是关于这个组自己那个位置的承诺,所以请给组一个属于它自己的位置。</Aside>+### 精灵遮罩++`SpriteMask` 把一个实体**自己的精灵**变成模板(stencil):在它之后绘制、并且主动要求被遮罩的精灵,+会被它的形状裁切。精灵本身什么都不用改 —— 纹理、尺寸、轴心、翻转、9 宫格都是你已经创作好的那些 ——+而在它正在遮罩期间,遮罩自己的精灵不会被画出来。它是那道裁切,不是一张图。++```typescript+world.insert(hole, SpriteMask, { alphaCutoff: 0.5 });+world.update(fog, Sprite, (s) => {+ s.maskInteraction = SpriteMaskInteraction.VisibleOutside; // 在迷雾上挖一个洞+});+```++遮罩是**逐精灵主动加入**的(`Sprite.maskInteraction`),所以往场景里加一个遮罩,永远不会让无关的精灵消失:++| `maskInteraction` | 保留哪一部分 |+|---|---|+| `None`(默认) | 忽略遮罩。 |+| `VisibleInside` | 只保留盖在遮罩上的部分 —— 一扇窗。 |+| `VisibleOutside` | 只保留避开遮罩的部分 —— 一个洞。 |++`alphaCutoff` 大于 0 时按精灵的**形状**裁切而不是它的方框:低于该 alpha 的片元不参与遮罩,+所以圆形遮罩裁出的是圆。++遮罩**向前生效** —— 它裁切在它之后绘制的东西,也就是你已经用层和层内次序安排好的那个顺序。+那正是它的模板被写入的时刻,所以与遮罩处在**同层同次序**的精灵完全不会被裁。打开 `limitRange`+可以让它的作用范围停在指定的层与次序上。++<Aside type="caution">+ 两个遮罩重叠的地方,由**更近的那个**说了算 —— 它写在后面,模板里留下的是它。被更远那个遮罩裁切的+ 精灵会恰好在更近的遮罩内部消失,所以任何一个精灵都只由一个遮罩来裁。+</Aside>++遮罩裁的是画面,不是场景:拾取、物理和空间查询都看不见它。+### 场景顺序决定平局同一层、同一 z 怎么办?那就由**场景顺序**决定:引擎按场景列出实体的顺序绘制,所以在大纲diff --git a/docs/astro/src/data/apiStability.generated.json b/docs/astro/src/data/apiStability.generated.jsonindex 5917ba884..03f67f577 100644--- a/docs/astro/src/data/apiStability.generated.json+++ b/docs/astro/src/data/apiStability.generated.json@@ -1,12 +1,12 @@{"note": "Generated by tools/api-stability.mjs from sdk/etc/*.api.md — do not edit.","counts": {- "public": 113,- "beta": 100,- "experimental": 1838,+ "public": 114,+ "beta": 101,+ "experimental": 1839,"deprecated": 3},- "total": 2051,+ "total": 2054,"subsystems": [{"id": "ecs",@@ -1331,6 +1331,18 @@"minigame"]},+ {+ "name": "SpriteMaskInteraction",+ "kind": "enum",+ "deprecated": false,+ "entries": [+ "index",+ "index.node",+ "index.native",+ "wechat",+ "minigame"+ ]+ },{"name": "Stick","kind": "const",@@ -2475,6 +2487,18 @@"minigame"]},+ {+ "name": "SpriteMaskData",+ "kind": "interface",+ "deprecated": false,+ "entries": [+ "index",+ "index.node",+ "index.native",+ "wechat",+ "minigame"+ ]+ },{"name": "SubEmitterTrigger","kind": "enum",diff --git a/docs/astro/src/data/componentDocs.ts b/docs/astro/src/data/componentDocs.tsindex 748554a1d..2b4fc6fc8 100644--- a/docs/astro/src/data/componentDocs.ts+++ b/docs/astro/src/data/componentDocs.ts@@ -78,6 +78,7 @@ export const COMPONENT_DOCS: Record<string, ComponentDoc> = {StreamedWorld: { category: 'world', summary: 'Declares the scene a streamed world and how big the cook cuts its cells.', doc: 'world/streaming', anchor: 'declaring-a-streamed-world', anchorZh: '声明一个流送世界' },WorldPersistent: { category: 'world', summary: 'Keeps an entity\'s whole subtree out of the partition — it belongs to the persistent world.', doc: 'world/streaming', anchor: 'declaring-a-streamed-world', anchorZh: '声明一个流送世界' },WorldStreamingSource: { category: 'world', summary: 'Asks for the places near it to exist; several sources are unioned.', doc: 'world/streaming', anchor: 'asking-for-places-streaming-sources', anchorZh: '请求地方存在流送源' },+ SpriteMask: { category: 'graphics', summary: "Turns this entity's Sprite into a stencil that cuts the sprites drawn after it — a window, or a hole.", doc: 'graphics/sprites', anchor: 'sprite-masks', anchorZh: '精灵遮罩' },SortingGroup: { category: 'graphics', summary: 'Makes an entity and its whole subtree sort as one unit — the group states the layer and order, members state their place inside it.', doc: 'graphics/sprites', anchor: 'sorting-groups', anchorZh: '排序组' },LODGroup: { category: 'graphics', summary: 'Cheaper stand-in meshes for a MeshRenderer, chosen by how much of the screen the object covers.', doc: 'performance/level-of-detail', anchor: 'the-lodgroup-component', anchorZh: 'lodgroup-组件' },Video: { category: 'graphics', summary: 'Plays a video stream onto a surface in the world or the UI.', doc: 'graphics/video', anchor: 'the-video-component', anchorZh: 'video-组件' },diff --git a/docs/astro/src/data/components.generated.json b/docs/astro/src/data/components.generated.jsonindex ef4f54926..71fb4e462 100644--- a/docs/astro/src/data/components.generated.json+++ b/docs/astro/src/data/components.generated.json@@ -3927,6 +3927,17 @@"doc": "Draw order inside the sorting layer — higher draws on top. Overrides the layer's Y-sort or depth ordering; leave 0 to keep it.","range": "-128–127, step 1"},+ {+ "key": "maskInteraction",+ "type": "enum",+ "default": "None",+ "doc": "Whether a SpriteMask drawn before this sprite clips it, and which side survives.",+ "values": [+ "None",+ "VisibleInside",+ "VisibleOutside"+ ]+ },{"key": "lit","type": "boolean",@@ -4034,6 +4045,44 @@"frameTimer"]},+ {+ "name": "SpriteMask",+ "source": "cpp",+ "fields": [+ {+ "key": "alphaCutoff",+ "type": "number",+ "default": "0",+ "doc": "Cut to the sprite's shape instead of its box: fragments below this alpha do not mask.",+ "range": "0–1"+ },+ {+ "key": "limitRange",+ "type": "boolean",+ "default": "false",+ "doc": "Limit how far this mask reaches; off = every sprite drawn after it."+ },+ {+ "key": "rangeEndLayer",+ "type": "enum (sortingLayers)",+ "default": "0",+ "doc": "Last sorting layer this mask reaches.",+ "range": "step 1"+ },+ {+ "key": "rangeEndOrder",+ "type": "number",+ "default": "0",+ "doc": "Last order inside that layer this mask reaches, inclusive.",+ "range": "-128–127, step 1"+ },+ {+ "key": "enabled",+ "type": "boolean",+ "default": "true"+ }+ ]+ },{"name": "StateMachineAgent","source": "ts",diff --git a/examples/space-shooter/src/components.ts b/examples/space-shooter/src/components.tsindex b0e6c473b..69aa6d981 100644--- a/examples/space-shooter/src/components.ts+++ b/examples/space-shooter/src/components.ts@@ -32,4 +32,6 @@ export const Hull = defineComponent('Hull', {export const ScoreDisplay = defineTag('ScoreDisplay');export const HealthHeart = defineTag('HealthHeart');+/** The mask whose width IS the hull bar's fill — see the HUD system. */+export const HullBarMask = defineTag('HullBarMask');export const GameOverScreen = defineTag('GameOverScreen');diff --git a/examples/space-shooter/src/resources.ts b/examples/space-shooter/src/resources.tsindex 34640ca53..6411f6e7e 100644--- a/examples/space-shooter/src/resources.ts+++ b/examples/space-shooter/src/resources.ts@@ -3,6 +3,8 @@ import { defineResource, type SpawnOverride } from 'esengine';export const HALF_HEIGHT = 540;export const HALF_WIDTH = 300;export const PLAYER_START_Y = -420;+/** Full extent of the hull bar, in world units — setup draws it, the HUD cuts it. */+export const HULL_BAR_WIDTH = 220;export const SPAWN_Y = HALF_HEIGHT + 60;export const DESTROY_Y = -(HALF_HEIGHT + 60);diff --git a/examples/space-shooter/src/systems/hud.ts b/examples/space-shooter/src/systems/hud.tsindex a764d8126..a7ae47da4 100644--- a/examples/space-shooter/src/systems/hud.ts+++ b/examples/space-shooter/src/systems/hud.ts@@ -1,18 +1,33 @@import {defineSystem, Query, Mut, Res, ResMut, Commands,- Input, Text, UIVisual, Transform,+ Input, Text, UIVisual, Transform, Sprite,} from 'esengine';-import { Player, Hull, ScoreDisplay, HealthHeart, GameOverScreen, Enemy, Bullet, Explosion } from '../components';-import { GameState, PLAYER_START_Y } from '../resources';+import {+ Player, Hull, ScoreDisplay, HealthHeart, HullBarMask,+ GameOverScreen, Enemy, Bullet, Explosion,+} from '../components';+import { GameState, PLAYER_START_Y, HULL_BAR_WIDTH } from '../resources';export const hudSystem = defineSystem(- [Res(GameState), Query(Mut(Text), ScoreDisplay), Query(Hull, Player), Query(Mut(UIVisual), HealthHeart)],- (state, scoreQuery, playerQuery, heartQuery) => {+ [+ Res(GameState), Query(Mut(Text), ScoreDisplay), Query(Hull, Player),+ Query(Mut(UIVisual), HealthHeart), Query(Mut(Sprite), HullBarMask),+ ],+ (state, scoreQuery, playerQuery, heartQuery, barMaskQuery) => {for (const [_entity, text] of scoreQuery) {text.content = `SCORE: ${state.score}`;}for (const [_entity, health] of playerQuery) {+ // The bar's reading is the MASK's width: the fill keeps its own size and is+ // cut to this, so the artwork never stretches with the number.+ const fraction = health.maxValue > 0+ ? Math.max(0, Math.min(1, health.value / health.maxValue))+ : 0;+ for (const [_mEntity, maskSprite] of barMaskQuery) {+ maskSprite.size = { x: HULL_BAR_WIDTH * fraction, y: maskSprite.size.y };+ }+let heartIndex = 0;for (const [_hEntity, visual] of heartQuery) {visual.color = heartIndex < health.valuediff --git a/examples/space-shooter/src/systems/setup.ts b/examples/space-shooter/src/systems/setup.tsindex e666014cc..c0747d258 100644--- a/examples/space-shooter/src/systems/setup.ts+++ b/examples/space-shooter/src/systems/setup.ts@@ -1,13 +1,22 @@import {defineSystem, Commands, Res, Prefabs,+ Transform, Sprite, SpriteMask, SpriteMaskInteraction,} from 'esengine';import {GameState, HALF_WIDTH, HALF_HEIGHT,- PREFAB_STAR, positionOverride, propOverride,+ PREFAB_STAR, positionOverride, propOverride, HULL_BAR_WIDTH,} from '../resources';+import { HullBarMask } from '../components';const INITIAL_STAR_COUNT = 40;+/** The hull bar, in world units. Its WIDTH is shared with the HUD that cuts it. */+const BAR_X = -110;+const BAR_Y = -500;+const BAR_H = 14;+/** Above every gameplay sprite, so the bar is never flown over. */+const BAR_LAYER = 10;+export const setupSystem = defineSystem([Commands(), Res(Prefabs)],(cmds, prefabServer) => {@@ -19,6 +28,55 @@ export const setupSystem = defineSystem(shootCooldown: 0,});+ // The fill is CUT, not resized: scaling stretches the art, a mask takes a bite+ // out of it. The mask's width is the reading (hudSystem). Left-pivoted, and+ // ordered back < mask < fill — the order a mask has to be written in.+ cmds.spawn('HullBarBack')+ .insert(Transform, { position: { x: BAR_X, y: BAR_Y, z: 0 } })+ .insert(Sprite, {+ size: { x: HULL_BAR_WIDTH, y: BAR_H },+ pivot: { x: 0, y: 0.5 },+ color: { r: 0.10, g: 0.12, b: 0.18, a: 0.85 },+ layer: BAR_LAYER,+ order: 0,+ });++ cmds.spawn('HullBarMask')+ .insert(Transform, { position: { x: BAR_X, y: BAR_Y, z: 0 } })+ .insert(Sprite, {+ size: { x: HULL_BAR_WIDTH, y: BAR_H },+ pivot: { x: 0, y: 0.5 },+ layer: BAR_LAYER,+ order: 1,+ })+ .insert(SpriteMask, {})+ .insert(HullBarMask, {});++ cmds.spawn('HullBarFill')+ .insert(Transform, { position: { x: BAR_X, y: BAR_Y, z: 0 } })+ .insert(Sprite, {+ size: { x: HULL_BAR_WIDTH, y: BAR_H },+ pivot: { x: 0, y: 0.5 },+ color: { r: 0.35, g: 0.95, b: 0.6, a: 1 },+ layer: BAR_LAYER,+ order: 2,+ maskInteraction: SpriteMaskInteraction.VisibleInside,+ });++ // The same mask's other side: what the hull has LOST. One mask cuts both, so+ // the halves cannot disagree about the boundary — and at full hull this one has+ // nowhere to show, which is what makes a broken outside-test visible.+ cmds.spawn('HullBarLost')+ .insert(Transform, { position: { x: BAR_X, y: BAR_Y, z: 0 } })+ .insert(Sprite, {+ size: { x: HULL_BAR_WIDTH, y: BAR_H },+ pivot: { x: 0, y: 0.5 },+ color: { r: 0.85, g: 0.22, b: 0.28, a: 1 },+ layer: BAR_LAYER,+ order: 3,+ maskInteraction: SpriteMaskInteraction.VisibleOutside,+ });+for (let i = 0; i < INITIAL_STAR_COUNT; i++) {const layer = i % 3;const speed = 20 + layer * 30;diff --git a/fixtures/scenes/sprite-mask.esscene b/fixtures/scenes/sprite-mask.esscenenew file mode 100644index 000000000..62a39925f--- /dev/null+++ b/fixtures/scenes/sprite-mask.esscene@@ -0,0 +1,62 @@+{+ "version": 4,+ "name": "SpriteMask",+ "entities": [+ {+ "id": 0,+ "name": "Camera",+ "parent": null,+ "children": [],+ "components": [+ { "type": "Transform", "data": { "position": { "x": 0, "y": 0, "z": 10 } } },+ { "type": "Camera", "data": { "projectionType": 1, "orthoSize": 128, "isActive": true, "priority": 0 } }+ ],+ "visible": true+ },+ {+ "id": 1,+ "name": "Mask",+ "parent": null,+ "children": [],+ "components": [+ { "type": "Transform", "data": { "position": { "x": -64, "y": 0, "z": 0 } } },+ { "type": "Sprite", "data": { "size": { "x": 128, "y": 256 }, "color": { "r": 1, "g": 1, "b": 1, "a": 1 }, "layer": 0, "order": 0, "enabled": true } },+ { "type": "SpriteMask", "data": { "alphaCutoff": 0, "limitRange": false, "rangeEndLayer": 0, "rangeEndOrder": 0, "enabled": true } }+ ],+ "visible": true+ },+ {+ "id": 2,+ "name": "Inside",+ "parent": null,+ "children": [],+ "components": [+ { "type": "Transform", "data": { "position": { "x": 0, "y": 0, "z": 0 } } },+ { "type": "Sprite", "data": { "size": { "x": 256, "y": 256 }, "color": { "r": 0, "g": 1, "b": 0, "a": 1 }, "layer": 0, "order": 1, "maskInteraction": 1, "enabled": true } }+ ],+ "visible": true+ },+ {+ "id": 3,+ "name": "Outside",+ "parent": null,+ "children": [],+ "components": [+ { "type": "Transform", "data": { "position": { "x": 0, "y": 0, "z": 0 } } },+ { "type": "Sprite", "data": { "size": { "x": 256, "y": 256 }, "color": { "r": 1, "g": 0, "b": 0, "a": 1 }, "layer": 0, "order": 2, "maskInteraction": 2, "enabled": true } }+ ],+ "visible": true+ },+ {+ "id": 4,+ "name": "Unmasked",+ "parent": null,+ "children": [],+ "components": [+ { "type": "Transform", "data": { "position": { "x": 0, "y": -112, "z": 0 } } },+ { "type": "Sprite", "data": { "size": { "x": 256, "y": 24 }, "color": { "r": 0, "g": 0, "b": 1, "a": 1 }, "layer": 0, "order": 3, "enabled": true } }+ ],+ "visible": true+ }+ ]+}diff --git a/sdk/etc/index.api.md b/sdk/etc/index.api.mdindex 0f0dea0a8..b4d57ac33 100644--- a/sdk/etc/index.api.md+++ b/sdk/etc/index.api.md@@ -1,11 +1,11 @@# API surface — esengine/index<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->-Symbols: 113 public · 93 beta · 1677 experimental · 3 deprecated+Symbols: 114 public · 94 beta · 1678 experimental · 3 deprecated## ABI_LAYOUT_HASH — const @experimental```-"a30e798cbaa98d41"+"73a4e6e098cc7a9b"```## ANCHOR_AXES — const @experimental@@ -8241,6 +8241,7 @@ flipX: booleanflipY: booleanlayer: numberlit: boolean+maskInteraction: SpriteMaskInteraction | undefinedmaterial: numberorder: number | undefinedparallax: Vec2@@ -8258,6 +8259,27 @@ uvScale: Vec2{ createOutline(options?: OutlineFilterOptions): MaterialHandle; createGlow(options?: OutlineFilterOptions): MaterialHandle; createDropShadow(options?: DropShadowFilterOptions): MaterialHandle; setOutlineColor(material: MaterialHandle, color: { r: number; g: number; b: number; a: number; }): void; setOutlineWidth(material: MaterialHandle, width: number): void; setShadowOffset(material: MaterialHandle, x: number, y: number): void; setShadowBlur(material: MaterialHandle, blur: number): void; }```+## SpriteMask — const @experimental+```+BuiltinComponentDef<SpriteMaskData>+```++## SpriteMaskData — interface @beta+```+alphaCutoff: number+enabled: boolean+limitRange: boolean+rangeEndLayer: number+rangeEndOrder: number+```++## SpriteMaskInteraction — enum @public+```+None = 0+VisibleInside = 1+VisibleOutside = 2+```+## StaleOverride — interface @experimental```nestedAt: string | undefineddiff --git a/sdk/etc/index.native.api.md b/sdk/etc/index.native.api.mdindex a078aa5ac..5ea5428ad 100644--- a/sdk/etc/index.native.api.md+++ b/sdk/etc/index.native.api.md@@ -1,11 +1,11 @@# API surface — esengine/index.native<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->-Symbols: 113 public · 98 beta · 1696 experimental · 3 deprecated+Symbols: 114 public · 99 beta · 1697 experimental · 3 deprecated## ABI_LAYOUT_HASH — const @experimental```-"a30e798cbaa98d41"+"73a4e6e098cc7a9b"```## ANCHOR_AXES — const @experimental@@ -8434,6 +8434,7 @@ flipX: booleanflipY: booleanlayer: numberlit: boolean+maskInteraction: SpriteMaskInteraction | undefinedmaterial: numberorder: number | undefinedparallax: Vec2@@ -8451,6 +8452,27 @@ uvScale: Vec2{ createOutline(options?: OutlineFilterOptions): MaterialHandle; createGlow(options?: OutlineFilterOptions): MaterialHandle; createDropShadow(options?: DropShadowFilterOptions): MaterialHandle; setOutlineColor(material: MaterialHandle, color: { r: number; g: number; b: number; a: number; }): void; setOutlineWidth(material: MaterialHandle, width: number): void; setShadowOffset(material: MaterialHandle, x: number, y: number): void; setShadowBlur(material: MaterialHandle, blur: number): void; }```+## SpriteMask — const @experimental+```+BuiltinComponentDef<SpriteMaskData>+```++## SpriteMaskData — interface @beta+```+alphaCutoff: number+enabled: boolean+limitRange: boolean+rangeEndLayer: number+rangeEndOrder: number+```++## SpriteMaskInteraction — enum @public+```+None = 0+VisibleInside = 1+VisibleOutside = 2+```+## StaleOverride — interface @experimental```nestedAt: string | undefineddiff --git a/sdk/etc/index.node.api.md b/sdk/etc/index.node.api.mdindex 28c15ade1..fc8969e56 100644--- a/sdk/etc/index.node.api.md+++ b/sdk/etc/index.node.api.md@@ -1,7 +1,7 @@# API surface — esengine/index.node<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->-Symbols: 113 public · 95 beta · 1676 experimental · 3 deprecated+Symbols: 114 public · 96 beta · 1677 experimental · 3 deprecated## ANCHOR_AXES — const @experimental```@@ -8236,6 +8236,7 @@ flipX: booleanflipY: booleanlayer: numberlit: boolean+maskInteraction: SpriteMaskInteraction | undefinedmaterial: numberorder: number | undefinedparallax: Vec2@@ -8253,6 +8254,27 @@ uvScale: Vec2{ createOutline(options?: OutlineFilterOptions): MaterialHandle; createGlow(options?: OutlineFilterOptions): MaterialHandle; createDropShadow(options?: DropShadowFilterOptions): MaterialHandle; setOutlineColor(material: MaterialHandle, color: { r: number; g: number; b: number; a: number; }): void; setOutlineWidth(material: MaterialHandle, width: number): void; setShadowOffset(material: MaterialHandle, x: number, y: number): void; setShadowBlur(material: MaterialHandle, blur: number): void; }```+## SpriteMask — const @experimental+```+BuiltinComponentDef<SpriteMaskData>+```++## SpriteMaskData — interface @beta+```+alphaCutoff: number+enabled: boolean+limitRange: boolean+rangeEndLayer: number+rangeEndOrder: number+```++## SpriteMaskInteraction — enum @public+```+None = 0+VisibleInside = 1+VisibleOutside = 2+```+## StaleOverride — interface @experimental```nestedAt: string | undefineddiff --git a/sdk/etc/minigame.api.md b/sdk/etc/minigame.api.mdindex e4dd24be7..562f7af56 100644--- a/sdk/etc/minigame.api.md+++ b/sdk/etc/minigame.api.md@@ -1,7 +1,7 @@# API surface — esengine/minigame<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->-Symbols: 113 public · 93 beta · 1698 experimental · 3 deprecated+Symbols: 114 public · 94 beta · 1699 experimental · 3 deprecated## ANCHOR_AXES — const @experimental```@@ -8482,6 +8482,7 @@ flipX: booleanflipY: booleanlayer: numberlit: boolean+maskInteraction: SpriteMaskInteraction | undefinedmaterial: numberorder: number | undefinedparallax: Vec2@@ -8499,6 +8500,27 @@ uvScale: Vec2{ createOutline(options?: OutlineFilterOptions): MaterialHandle; createGlow(options?: OutlineFilterOptions): MaterialHandle; createDropShadow(options?: DropShadowFilterOptions): MaterialHandle; setOutlineColor(material: MaterialHandle, color: { r: number; g: number; b: number; a: number; }): void; setOutlineWidth(material: MaterialHandle, width: number): void; setShadowOffset(material: MaterialHandle, x: number, y: number): void; setShadowBlur(material: MaterialHandle, blur: number): void; }```+## SpriteMask — const @experimental+```+BuiltinComponentDef<SpriteMaskData>+```++## SpriteMaskData — interface @beta+```+alphaCutoff: number+enabled: boolean+limitRange: boolean+rangeEndLayer: number+rangeEndOrder: number+```++## SpriteMaskInteraction — enum @public+```+None = 0+VisibleInside = 1+VisibleOutside = 2+```+## StaleOverride — interface @experimental```nestedAt: string | undefineddiff --git a/sdk/etc/wasm.api.md b/sdk/etc/wasm.api.mdindex e2bea2d8f..7832d9101 100644--- a/sdk/etc/wasm.api.md+++ b/sdk/etc/wasm.api.md@@ -45,6 +45,7 @@ addSortingGroup: (entity: Entity, component: SortingGroup) => voidaddSphereCollider3D: (entity: Entity, component: SphereCollider3D) => voidaddSpineAnimation: (entity: Entity, component: SpineAnimation) => voidaddSprite: (entity: Entity, component: Sprite) => void+addSpriteMask: (entity: Entity, component: SpriteMask) => voidaddTilemapLayer: (entity: Entity, component: TilemapLayer) => voidaddTrailRenderer: (entity: Entity, component: TrailRenderer) => voidaddTransform: (entity: Entity, component: Transform) => void@@ -90,6 +91,7 @@ getSortingGroup: (entity: Entity) => SortingGroupgetSphereCollider3D: (entity: Entity) => SphereCollider3DgetSpineAnimation: (entity: Entity) => SpineAnimationgetSprite: (entity: Entity) => Sprite+getSpriteMask: (entity: Entity) => SpriteMaskgetTilemapLayer: (entity: Entity) => TilemapLayergetTrailRenderer: (entity: Entity) => TrailRenderergetTransform: (entity: Entity) => Transform@@ -131,6 +133,7 @@ hasSortingGroup: (entity: Entity) => booleanhasSphereCollider3D: (entity: Entity) => booleanhasSpineAnimation: (entity: Entity) => booleanhasSprite: (entity: Entity) => boolean+hasSpriteMask: (entity: Entity) => booleanhasTilemapLayer: (entity: Entity) => booleanhasTrailRenderer: (entity: Entity) => booleanhasTransform: (entity: Entity) => boolean@@ -173,6 +176,7 @@ removeSortingGroup: (entity: Entity) => voidremoveSphereCollider3D: (entity: Entity) => voidremoveSpineAnimation: (entity: Entity) => voidremoveSprite: (entity: Entity) => void+removeSpriteMask: (entity: Entity) => voidremoveTilemapLayer: (entity: Entity) => voidremoveTrailRenderer: (entity: Entity) => voidremoveTransform: (entity: Entity) => voiddiff --git a/sdk/etc/wechat.api.md b/sdk/etc/wechat.api.mdindex f63ac7dc3..ce6e57b44 100644--- a/sdk/etc/wechat.api.md+++ b/sdk/etc/wechat.api.md@@ -1,7 +1,7 @@# API surface — esengine/wechat<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->-Symbols: 113 public · 93 beta · 1688 experimental · 3 deprecated+Symbols: 114 public · 94 beta · 1689 experimental · 3 deprecated## ANCHOR_AXES — const @experimental```@@ -8243,6 +8243,7 @@ flipX: booleanflipY: booleanlayer: numberlit: boolean+maskInteraction: SpriteMaskInteraction | undefinedmaterial: numberorder: number | undefinedparallax: Vec2@@ -8260,6 +8261,27 @@ uvScale: Vec2{ createOutline(options?: OutlineFilterOptions): MaterialHandle; createGlow(options?: OutlineFilterOptions): MaterialHandle; createDropShadow(options?: DropShadowFilterOptions): MaterialHandle; setOutlineColor(material: MaterialHandle, color: { r: number; g: number; b: number; a: number; }): void; setOutlineWidth(material: MaterialHandle, width: number): void; setShadowOffset(material: MaterialHandle, x: number, y: number): void; setShadowBlur(material: MaterialHandle, blur: number): void; }```+## SpriteMask — const @experimental+```+BuiltinComponentDef<SpriteMaskData>+```++## SpriteMaskData — interface @beta+```+alphaCutoff: number+enabled: boolean+limitRange: boolean+rangeEndLayer: number+rangeEndOrder: number+```++## SpriteMaskInteraction — enum @public+```+None = 0+VisibleInside = 1+VisibleOutside = 2+```+## StaleOverride — interface @experimental```nestedAt: string | undefineddiff --git a/sdk/src/core-runtime.ts b/sdk/src/core-runtime.tsindex 30837fb54..4671ab637 100644--- a/sdk/src/core-runtime.ts+++ b/sdk/src/core-runtime.ts@@ -93,8 +93,10 @@ export {ShapeType,Light,LightType,+ SpriteMaskInteraction,ShadowCaster2D,SortingGroup,+ SpriteMask,TrailRenderer,MeshRenderer,type MeshRendererData,@@ -123,6 +125,7 @@ export {type LightData,type ShadowCaster2DData,type SortingGroupData,+ type SpriteMaskData,type CameraData,type CanvasData,type VelocityData,diff --git a/sdk/src/ecs/bridge/ptrAccessors.generated.ts b/sdk/src/ecs/bridge/ptrAccessors.generated.tsindex fdadcc771..a6365f47f 100644--- a/sdk/src/ecs/bridge/ptrAccessors.generated.ts+++ b/sdk/src/ecs/bridge/ptrAccessors.generated.ts@@ -1650,6 +1650,7 @@ export interface SpritePtrData {uvScale: Vec2;layer: number;order: number;+ maskInteraction: number;lit: boolean;flipX: boolean;flipY: boolean;@@ -1672,14 +1673,15 @@ export function fillSprite(const uvScale_ = out.uvScale; uvScale_.x = f32[(ptr + 44) >> 2]; uvScale_.y = f32[((ptr + 44) >> 2) + 1];out.layer = u32[(ptr + 52) >> 2] | 0;out.order = u32[(ptr + 56) >> 2] | 0;- out.lit = u8[ptr + 60] !== 0;- out.flipX = u8[ptr + 61] !== 0;- out.flipY = u8[ptr + 62] !== 0;- const tileSize_ = out.tileSize; tileSize_.x = f32[(ptr + 64) >> 2]; tileSize_.y = f32[((ptr + 64) >> 2) + 1];- const tileSpacing_ = out.tileSpacing; tileSpacing_.x = f32[(ptr + 72) >> 2]; tileSpacing_.y = f32[((ptr + 72) >> 2) + 1];- const parallax_ = out.parallax; parallax_.x = f32[(ptr + 80) >> 2]; parallax_.y = f32[((ptr + 80) >> 2) + 1];- out.material = u32[(ptr + 88) >> 2];- out.enabled = u8[ptr + 92] !== 0;+ out.maskInteraction = u32[(ptr + 60) >> 2] | 0;+ out.lit = u8[ptr + 64] !== 0;+ out.flipX = u8[ptr + 65] !== 0;+ out.flipY = u8[ptr + 66] !== 0;+ const tileSize_ = out.tileSize; tileSize_.x = f32[(ptr + 68) >> 2]; tileSize_.y = f32[((ptr + 68) >> 2) + 1];+ const tileSpacing_ = out.tileSpacing; tileSpacing_.x = f32[(ptr + 76) >> 2]; tileSpacing_.y = f32[((ptr + 76) >> 2) + 1];+ const parallax_ = out.parallax; parallax_.x = f32[(ptr + 84) >> 2]; parallax_.y = f32[((ptr + 84) >> 2) + 1];+ out.material = u32[(ptr + 92) >> 2];+ out.enabled = u8[ptr + 96] !== 0;}export function writeSprite(@@ -1694,14 +1696,15 @@ export function writeSprite(f32[(ptr + 44) >> 2] = data.uvScale.x; f32[((ptr + 44) >> 2) + 1] = data.uvScale.y;u32[(ptr + 52) >> 2] = data.layer | 0;u32[(ptr + 56) >> 2] = data.order | 0;- u8[ptr + 60] = data.lit ? 1 : 0;- u8[ptr + 61] = data.flipX ? 1 : 0;- u8[ptr + 62] = data.flipY ? 1 : 0;- f32[(ptr + 64) >> 2] = data.tileSize.x; f32[((ptr + 64) >> 2) + 1] = data.tileSize.y;- f32[(ptr + 72) >> 2] = data.tileSpacing.x; f32[((ptr + 72) >> 2) + 1] = data.tileSpacing.y;- f32[(ptr + 80) >> 2] = data.parallax.x; f32[((ptr + 80) >> 2) + 1] = data.parallax.y;- u32[(ptr + 88) >> 2] = data.material;- u8[ptr + 92] = data.enabled ? 1 : 0;+ u32[(ptr + 60) >> 2] = data.maskInteraction | 0;+ u8[ptr + 64] = data.lit ? 1 : 0;+ u8[ptr + 65] = data.flipX ? 1 : 0;+ u8[ptr + 66] = data.flipY ? 1 : 0;+ f32[(ptr + 68) >> 2] = data.tileSize.x; f32[((ptr + 68) >> 2) + 1] = data.tileSize.y;+ f32[(ptr + 76) >> 2] = data.tileSpacing.x; f32[((ptr + 76) >> 2) + 1] = data.tileSpacing.y;+ f32[(ptr + 84) >> 2] = data.parallax.x; f32[((ptr + 84) >> 2) + 1] = data.parallax.y;+ u32[(ptr + 92) >> 2] = data.material;+ u8[ptr + 96] = data.enabled ? 1 : 0;}export function createSpriteData(): SpritePtrData {@@ -1714,6 +1717,7 @@ export function createSpriteData(): SpritePtrData {uvScale: { x: 0, y: 0 },layer: 0,order: 0,+ maskInteraction: 0,lit: false,flipX: false,flipY: false,@@ -1725,6 +1729,46 @@ export function createSpriteData(): SpritePtrData {};}+export interface SpriteMaskPtrData {+ alphaCutoff: number;+ limitRange: boolean;+ rangeEndLayer: number;+ rangeEndOrder: number;+ enabled: boolean;+}++export function fillSpriteMask(+ f32: Float32Array, u32: Uint32Array, u8: Uint8Array,+ ptr: number, out: SpriteMaskPtrData,+): void {+ out.alphaCutoff = f32[ptr >> 2];+ out.limitRange = u8[ptr + 4] !== 0;+ out.rangeEndLayer = u32[(ptr + 8) >> 2] | 0;+ out.rangeEndOrder = u32[(ptr + 12) >> 2] | 0;+ out.enabled = u8[ptr + 16] !== 0;+}++export function writeSpriteMask(+ f32: Float32Array, u32: Uint32Array, u8: Uint8Array,+ ptr: number, data: SpriteMaskPtrData,+): void {+ f32[ptr >> 2] = data.alphaCutoff;+ u8[ptr + 4] = data.limitRange ? 1 : 0;+ u32[(ptr + 8) >> 2] = data.rangeEndLayer | 0;+ u32[(ptr + 12) >> 2] = data.rangeEndOrder | 0;+ u8[ptr + 16] = data.enabled ? 1 : 0;+}++export function createSpriteMaskData(): SpriteMaskPtrData {+ return {+ alphaCutoff: 0,+ limitRange: false,+ rangeEndLayer: 0,+ rangeEndOrder: 0,+ enabled: false,+ };+}+export interface TilemapLayerPtrData {cellSize: Vec2;orientation: number;@@ -2273,6 +2317,7 @@ export const PTR_ACCESSORS: Record<string, PtrAccessor<any>> = {SphereCollider3D: { fill: fillSphereCollider3D, write: writeSphereCollider3D, create: createSphereCollider3DData },SpineAnimation: { fill: fillSpineAnimation, write: writeSpineAnimation, create: createSpineAnimationData },Sprite: { fill: fillSprite, write: writeSprite, create: createSpriteData },+ SpriteMask: { fill: fillSpriteMask, write: writeSpriteMask, create: createSpriteMaskData },TilemapLayer: { fill: fillTilemapLayer, write: writeTilemapLayer, create: createTilemapLayerData },TrailRenderer: { fill: fillTrailRenderer, write: writeTrailRenderer, create: createTrailRendererData },Transform: { fill: fillTransform, write: writeTransform, create: createTransformData },diff --git a/sdk/src/ecs/component.generated.ts b/sdk/src/ecs/component.generated.tsindex 5568be438..3e80c4079 100644--- a/sdk/src/ecs/component.generated.ts+++ b/sdk/src/ecs/component.generated.ts@@ -7,7 +7,7 @@import type { AssetFieldType } from '../scene/scene';import type { FieldMeta } from './component';import type { Color, Entity, Quat, Vec2, Vec3, Vec4 } from '../types';-import type { AlignContent, AlignItems, AlignSelf, BodyType, CanvasScaleMode, ClearFlags, Dimension, EmitterShape, FlexDirection, FlexWrap, ForceFieldType, JustifyContent, LightType, MaskMode, Padding, ParticleEasing, ProjectionType, ScrollMovement, ShapeType, SimulationSpace, SubEmitterTrigger, TextAlign, TilemapOrientation, TilemapStaggerAxis, TilemapStaggerIndex, UIDisplay, UIFillMethod, UIFillOrigin, UIPointerEvents, UIPositionType, UIVisualFit, UIVisualType } from '../wasm/wasm.generated';+import type { AlignContent, AlignItems, AlignSelf, BodyType, CanvasScaleMode, ClearFlags, Dimension, EmitterShape, FlexDirection, FlexWrap, ForceFieldType, JustifyContent, LightType, MaskMode, Padding, ParticleEasing, ProjectionType, ScrollMovement, ShapeType, SimulationSpace, SpriteMaskInteraction, SubEmitterTrigger, TextAlign, TilemapOrientation, TilemapStaggerAxis, TilemapStaggerIndex, UIDisplay, UIFillMethod, UIFillOrigin, UIPointerEvents, UIPositionType, UIVisualFit, UIVisualType } from '../wasm/wasm.generated';/*** Single-source-of-truth hash of the C++/TS boundary ABI (component@@ -15,7 +15,7 @@ import type { AlignContent, AlignItems, AlignSelf, BodyType, CanvasScaleMode, Cl* getAbiLayoutHash(); BuiltinBridge.connect() compares them and refuses to* run on mismatch, because mismatched offsets read the wrong heap bytes.*/-export const ABI_LAYOUT_HASH = 'a30e798cbaa98d41';+export const ABI_LAYOUT_HASH = '73a4e6e098cc7a9b';/*** One asset-valued field of a component: which field, and what kind of@@ -867,6 +867,7 @@ export const COMPONENT_META: Record<string, ComponentMetaEntry> = {uvScale: { x: 1, y: 1 },layer: 0,order: 0,+ maskInteraction: 0,lit: false,flipX: false,flipY: false,@@ -891,6 +892,7 @@ export const COMPONENT_META: Record<string, ComponentMetaEntry> = {uvScale: { advanced: true },layer: { step: 1, tooltip: "Sorting layer — controls draw order across sprites.", enumSource: "sortingLayers" },order: { min: -128, max: 127, step: 1, tooltip: "Draw order inside the sorting layer — higher draws on top. Overrides the layer's Y-sort or depth ordering; leave 0 to keep it." },+ maskInteraction: { enum: [{ label: 'None', value: 0 }, { label: 'VisibleInside', value: 1 }, { label: 'VisibleOutside', value: 2 }], tooltip: "Whether a SpriteMask drawn before this sprite clips it, and which side survives." },lit: { tooltip: "Receive 2D lights: Light entities light this sprite (flat normal). A custom material overrides this." },tileSize: { advanced: true },tileSpacing: { advanced: true },@@ -898,6 +900,26 @@ export const COMPONENT_META: Record<string, ComponentMetaEntry> = {material: { advanced: true },},},+ SpriteMask: {+ defaults: {+ alphaCutoff: 0,+ limitRange: false,+ rangeEndLayer: 0,+ rangeEndOrder: 0,+ enabled: true,+ },+ renderableField: 'enabled',+ assetFields: [],+ entityFields: [],+ colorFields: [],+ animatableFields: [],+ fields: {+ alphaCutoff: { min: 0, max: 1, slider: true, tooltip: "Cut to the sprite's shape instead of its box: fragments below this alpha do not mask." },+ limitRange: { tooltip: "Limit how far this mask reaches; off = every sprite drawn after it." },+ rangeEndLayer: { step: 1, tooltip: "Last sorting layer this mask reaches.", enumSource: "sortingLayers", shownWhen: { field: "limitRange", values: [1] } },+ rangeEndOrder: { min: -128, max: 127, step: 1, tooltip: "Last order inside that layer this mask reaches, inclusive.", shownWhen: { field: "limitRange", values: [1] } },+ },+ },TilemapLayer: {defaults: {cellSize: { x: 32, y: 32 },@@ -1540,6 +1562,7 @@ export interface SpriteData {uvScale: Vec2;layer: number;order?: number;+ maskInteraction?: SpriteMaskInteraction;lit: boolean;flipX: boolean;flipY: boolean;@@ -1550,6 +1573,20 @@ export interface SpriteData {enabled: boolean;}+/**+ * The fields of the engine's `SpriteMask` component, generated from+ * the C++ struct so the two shapes cannot drift.+ *+ * @beta+ */+export interface SpriteMaskData {+ alphaCutoff: number;+ limitRange: boolean;+ rangeEndLayer: number;+ rangeEndOrder: number;+ enabled: boolean;+}+/*** The fields of the engine's `TilemapLayer` component, generated from* the C++ struct so the two shapes cannot drift.diff --git a/sdk/src/ecs/component.ts b/sdk/src/ecs/component.tsindex f0dd4d960..5600f5c4d 100644--- a/sdk/src/ecs/component.ts+++ b/sdk/src/ecs/component.ts@@ -15,7 +15,7 @@ export type { AssetFieldMeta, SkeletalFieldMeta };// extending the generated base.import type {TransformData, SpriteData, ShapeRendererData, LightData, ShadowCaster2DData, DraggableData,- SortingGroupData,+ SortingGroupData, SpriteMaskData,CanvasData, VelocityData, ParentData, ChildrenData, SpineAnimationData, DragonBonesAnimationData,TilemapLayerData, BitmapTextData, TrailRendererData, ParticleForceFieldData,CameraData as CameraDataCpp, ParticleEmitterData as ParticleEmitterDataCpp,@@ -26,7 +26,7 @@ import type {// C++ enum and the editor dropdowns derive from the same values. ScaleMode's// canonical values come from CanvasScaleMode (only its Cocos-compat aliases// ShowAll/NoBorder are TS-side).-import { ProjectionType, ClearFlags, EmitterShape, SimulationSpace, SubEmitterTrigger, ForceFieldType, LightType, CanvasScaleMode, ShapeType, ParticleEasing } from '../wasm/wasm.generated';+import { ProjectionType, ClearFlags, EmitterShape, SimulationSpace, SubEmitterTrigger, ForceFieldType, LightType, CanvasScaleMode, ShapeType, ParticleEasing, SpriteMaskInteraction } from '../wasm/wasm.generated';import { BlendMode } from '../render/blend';import { getDefaultContext } from './context';import type {@@ -773,7 +773,7 @@ export function ensureBuiltinComponentsRegistered(): void {// EmitterShape, SimulationSpace, LightType and ShapeType are re-exported from the// generated module; their values and the editor dropdowns built from them now have// one source.-export { ProjectionType, ClearFlags, EmitterShape, SimulationSpace, SubEmitterTrigger, ForceFieldType, LightType, ShapeType };+export { ProjectionType, ClearFlags, EmitterShape, SimulationSpace, SubEmitterTrigger, ForceFieldType, LightType, ShapeType, SpriteMaskInteraction };// Canonical values single-sourced from the C++ CanvasScaleMode enum (generated);// ShowAll/NoBorder are Cocos-compat aliases with no C++ member.@@ -798,7 +798,7 @@ export type ScaleMode = (typeof ScaleMode)[keyof typeof ScaleMode];// automatically; tsc then enforces every consumer matches.export type {TransformData, SpriteData, ShapeRendererData, LightData, ShadowCaster2DData, DraggableData,- SortingGroupData,+ SortingGroupData, SpriteMaskData,CanvasData, VelocityData, ParentData, ChildrenData, SpineAnimationData, DragonBonesAnimationData,TilemapLayerData, BitmapTextData, TrailRendererData, ParticleForceFieldData,};@@ -914,6 +914,15 @@ export const ShadowCaster2D = defineBuiltin<ShadowCaster2DData>('ShadowCaster2D'metaDefaults<ShadowCaster2DData>('ShadowCaster2D'));+/**+ * Turns this entity's `Sprite` into a stencil: the sprites drawn AFTER it that ask to be+ * masked (`Sprite.maskInteraction`) are cut by its shape. The mask's own sprite is not+ * drawn while it is masking — it is the cut, not a picture.+ */+export const SpriteMask = defineBuiltin<SpriteMaskData>('SpriteMask',+ metaDefaults<SpriteMaskData>('SpriteMask')+);+/*** Makes this entity and everything under it sort as ONE unit: the group states the* layer and order the whole subtree presents outward, and each member's owndiff --git a/sdk/src/wasm/ptrLayouts.generated.ts b/sdk/src/wasm/ptrLayouts.generated.tsindex 4930ae38d..ec73c3403 100644--- a/sdk/src/wasm/ptrLayouts.generated.ts+++ b/sdk/src/wasm/ptrLayouts.generated.ts@@ -446,14 +446,25 @@ export const PTR_LAYOUTS: Record<string, PtrLayout> = {{ name: 'uvScale', type: 'vec2', offset: 44 },{ name: 'layer', type: 'i32', offset: 52 },{ name: 'order', type: 'i32', offset: 56 },- { name: 'lit', type: 'bool', offset: 60 },- { name: 'flipX', type: 'bool', offset: 61 },- { name: 'flipY', type: 'bool', offset: 62 },- { name: 'tileSize', type: 'vec2', offset: 64 },- { name: 'tileSpacing', type: 'vec2', offset: 72 },- { name: 'parallax', type: 'vec2', offset: 80 },- { name: 'material', type: 'u32', offset: 88 },- { name: 'enabled', type: 'bool', offset: 92 },+ { name: 'maskInteraction', type: 'i32', offset: 60 },+ { name: 'lit', type: 'bool', offset: 64 },+ { name: 'flipX', type: 'bool', offset: 65 },+ { name: 'flipY', type: 'bool', offset: 66 },+ { name: 'tileSize', type: 'vec2', offset: 68 },+ { name: 'tileSpacing', type: 'vec2', offset: 76 },+ { name: 'parallax', type: 'vec2', offset: 84 },+ { name: 'material', type: 'u32', offset: 92 },+ { name: 'enabled', type: 'bool', offset: 96 },+ ],+ },+ SpriteMask: {+ ptrFn: 'getSpriteMaskPtr',+ fields: [+ { name: 'alphaCutoff', type: 'f32', offset: 0 },+ { name: 'limitRange', type: 'bool', offset: 4 },+ { name: 'rangeEndLayer', type: 'i32', offset: 8 },+ { name: 'rangeEndOrder', type: 'i32', offset: 12 },+ { name: 'enabled', type: 'bool', offset: 16 },],},TilemapLayer: {diff --git a/sdk/src/wasm/wasm.generated.ts b/sdk/src/wasm/wasm.generated.tsindex f340cf3e5..6d982ccb1 100644--- a/sdk/src/wasm/wasm.generated.ts+++ b/sdk/src/wasm/wasm.generated.ts@@ -205,6 +205,17 @@ export enum SimulationSpace {Local = 1,}+/**+ * The engine's `SpriteMaskInteraction`, generated from the C++ enum.+ *+ * @public+ */+export enum SpriteMaskInteraction {+ None = 0,+ VisibleInside = 1,+ VisibleOutside = 2,+}+/*** The engine's `SubEmitterTrigger`, generated from the C++ enum.*@@ -735,6 +746,7 @@ export interface Sprite {uvScale: Vec2;layer: number;order: number;+ maskInteraction: number;lit: boolean;flipX: boolean;flipY: boolean;@@ -745,6 +757,14 @@ export interface Sprite {enabled: boolean;}+export interface SpriteMask {+ alphaCutoff: number;+ limitRange: boolean;+ rangeEndLayer: number;+ rangeEndOrder: number;+ enabled: boolean;+}+export interface TilemapLayer {cellSize: Vec2;orientation: number;@@ -990,6 +1010,10 @@ export interface Registry {getSprite(entity: Entity): Sprite;addSprite(entity: Entity, component: Sprite): void;removeSprite(entity: Entity): void;+ hasSpriteMask(entity: Entity): boolean;+ getSpriteMask(entity: Entity): SpriteMask;+ addSpriteMask(entity: Entity, component: SpriteMask): void;+ removeSpriteMask(entity: Entity): void;hasTilemapLayer(entity: Entity): boolean;getTilemapLayer(entity: Entity): TilemapLayer;addTilemapLayer(entity: Entity, component: TilemapLayer): void;@@ -1072,6 +1096,7 @@ export interface ESEngineModule {SphereCollider3D: new () => SphereCollider3D;SpineAnimation: new () => SpineAnimation;Sprite: new () => Sprite;+ SpriteMask: new () => SpriteMask;TilemapLayer: new () => TilemapLayer;TrailRenderer: new () => TrailRenderer;Transform: new () => Transform;diff --git a/sdk/tests/__snapshots__/component-fieldmeta-golden.test.ts.snap b/sdk/tests/__snapshots__/component-fieldmeta-golden.test.ts.snapindex ab6836412..cac384822 100644--- a/sdk/tests/__snapshots__/component-fieldmeta-golden.test.ts.snap+++ b/sdk/tests/__snapshots__/component-fieldmeta-golden.test.ts.snap@@ -946,6 +946,23 @@ exports[`builtin FieldMeta (RC9-1 equivalence gate) > matches the golden snapsho"lit": {"tooltip": "Receive 2D lights: Light entities light this sprite (flat normal). A custom material overrides this.",},+ "maskInteraction": {+ "enum": [+ {+ "label": "None",+ "value": 0,+ },+ {+ "label": "VisibleInside",+ "value": 1,+ },+ {+ "label": "VisibleOutside",+ "value": 2,+ },+ ],+ "tooltip": "Whether a SpriteMask drawn before this sprite clips it, and which side survives.",+ },"material": {"advanced": true,},@@ -976,6 +993,40 @@ exports[`builtin FieldMeta (RC9-1 equivalence gate) > matches the golden snapsho"advanced": true,},},+ "SpriteMask": {+ "alphaCutoff": {+ "max": 1,+ "min": 0,+ "slider": true,+ "tooltip": "Cut to the sprite's shape instead of its box: fragments below this alpha do not mask.",+ },+ "limitRange": {+ "tooltip": "Limit how far this mask reaches; off = every sprite drawn after it.",+ },+ "rangeEndLayer": {+ "enumSource": "sortingLayers",+ "shownWhen": {+ "field": "limitRange",+ "values": [+ 1,+ ],+ },+ "step": 1,+ "tooltip": "Last sorting layer this mask reaches.",+ },+ "rangeEndOrder": {+ "max": 127,+ "min": -128,+ "shownWhen": {+ "field": "limitRange",+ "values": [+ 1,+ ],+ },+ "step": 1,+ "tooltip": "Last order inside that layer this mask reaches, inclusive.",+ },+ },"TilemapLayer": {"hexSideLength": {"min": 0,diff --git a/sdk/tests/cpp-contract.test.ts b/sdk/tests/cpp-contract.test.tsindex 8e0ad2e99..1b3ce0b35 100644--- a/sdk/tests/cpp-contract.test.ts+++ b/sdk/tests/cpp-contract.test.ts@@ -37,6 +37,7 @@ import { BodyType } from '../src/physics/PhysicsComponents';import { UIPositionType, AlignSelf } from '../src/ui/core/ui-node';import { UIVisualType, FillMethod, FillOrigin } from '../src/ui/core/ui-visual';import { MaskMode } from '../src/ui/core/ui-mask';+import { SpriteMaskInteraction } from '../src/ecs/component';import { ScrollMovement } from '../src/ui/core/ui-scroll';import { TilemapOrientation } from '../src/tilemap/tileGeometry';import { TextAlign } from '../src/ui/core/text';@@ -191,6 +192,7 @@ describe('C++ contract: module-published enums ARE their EHT-generated twin', ()['FillOrigin', FillOrigin, gen.UIFillOrigin],['ParticleEasing', ParticleEasing, gen.ParticleEasing],['MaskMode', MaskMode, gen.MaskMode],+ ['SpriteMaskInteraction', SpriteMaskInteraction, gen.SpriteMaskInteraction],['ScrollMovement', ScrollMovement, gen.ScrollMovement],['TilemapOrientation', TilemapOrientation, gen.TilemapOrientation],['FlexDirection', FlexDirection, gen.FlexDirection],@@ -237,7 +239,9 @@ describe('C++ contract: a component field that IS an enum is typed as one', () =.map((l) => /^\s*(?:u8|u16|u32|i8|i16|i32)\s+(\w+)\s*[{=]/.exec(l)?.[1]).find(Boolean);if (!decl) return;- if (!new RegExp(`^\\s*${decl}: ${enumName};$`, 'm').test(data)) {+ // `?` because a field added to a frozen component is optional — the+ // mark is additive, the TYPE is what this holds.+ if (!new RegExp(`^\\s*${decl}\\??: ${enumName};$`, 'm').test(data)) {loose.push(`${name}: ${decl} should be generated as ${enumName}`);}});diff --git a/src/esengine/aot/AotComponents.generated.cpp b/src/esengine/aot/AotComponents.generated.cppindex e4e66d013..fc91c4d1a 100644--- a/src/esengine/aot/AotComponents.generated.cpp+++ b/src/esengine/aot/AotComponents.generated.cpp@@ -30,6 +30,7 @@#include "esengine/ecs/components/SortingGroup.hpp"#include "esengine/ecs/components/SpineAnimation.hpp"#include "esengine/ecs/components/Sprite.hpp"+#include "esengine/ecs/components/SpriteMask.hpp"#include "esengine/ecs/components/TilemapLayer.hpp"#include "esengine/ecs/components/TrailRenderer.hpp"#include "esengine/ecs/components/Transform.hpp"@@ -221,6 +222,11 @@ ComponentAt engineComponentAt(ecs::Registry& registry, const char* name) {return registry.tryGet<esengine::ecs::Sprite>(Entity::fromRaw(raw));};}+ if (std::strcmp(name, "SpriteMask") == 0) {+ return [®istry](std::uint32_t raw) -> void* {+ return registry.tryGet<esengine::ecs::SpriteMask>(Entity::fromRaw(raw));+ };+ }if (std::strcmp(name, "TilemapLayer") == 0) {return [®istry](std::uint32_t raw) -> void* {return registry.tryGet<esengine::ecs::TilemapLayer>(Entity::fromRaw(raw));@@ -430,6 +436,11 @@ CandidatesOf engineComponentCandidates(ecs::Registry& registry, const char* namereturn denseAsIds(registry.entitiesWith<esengine::ecs::Sprite>());};}+ if (std::strcmp(name, "SpriteMask") == 0) {+ return [®istry]() -> Candidates {+ return denseAsIds(registry.entitiesWith<esengine::ecs::SpriteMask>());+ };+ }if (std::strcmp(name, "TilemapLayer") == 0) {return [®istry]() -> Candidates {return denseAsIds(registry.entitiesWith<esengine::ecs::TilemapLayer>());@@ -511,6 +522,7 @@ bool isEngineComponent(const char* name) {if (std::strcmp(name, "SphereCollider3D") == 0) return true;if (std::strcmp(name, "SpineAnimation") == 0) return true;if (std::strcmp(name, "Sprite") == 0) return true;+ if (std::strcmp(name, "SpriteMask") == 0) return true;if (std::strcmp(name, "TilemapLayer") == 0) return true;if (std::strcmp(name, "TrailRenderer") == 0) return true;if (std::strcmp(name, "Transform") == 0) return true;diff --git a/src/esengine/bindings/EditorAPI.generated.cpp b/src/esengine/bindings/EditorAPI.generated.cppindex 3ebaafb17..9bb1cd4d0 100644--- a/src/esengine/bindings/EditorAPI.generated.cpp+++ b/src/esengine/bindings/EditorAPI.generated.cpp@@ -2,10 +2,10 @@* @file EditorAPI.generated.cpp* @brief Auto-generated editor API with string-dispatched component access* @details Generated by EHT - DO NOT EDIT- * @schema_hash 4b73aeac9635cd13+ * @schema_hash a9261da2a8edb96e*/-#define ES_EDITOR_API_SCHEMA_HASH "4b73aeac9635cd13"+#define ES_EDITOR_API_SCHEMA_HASH "a9261da2a8edb96e"#include <emscripten/bind.h>#include <string>@@ -34,6 +34,7 @@#include "../ecs/components/SortingGroup.hpp"#include "../ecs/components/SpineAnimation.hpp"#include "../ecs/components/Sprite.hpp"+#include "../ecs/components/SpriteMask.hpp"#include "../ecs/components/TilemapLayer.hpp"#include "../ecs/components/TrailRenderer.hpp"#include "../ecs/components/Transform.hpp"@@ -95,6 +96,7 @@ std::vector<std::string> editor_getComponentNames() {"SphereCollider3D","SpineAnimation","Sprite",+ "SpriteMask","TilemapLayer","TrailRenderer","Transform",@@ -562,6 +564,7 @@ std::string editor_getComponentSchema(const std::string& name) {{"key":"uvScale.y","type":"float","group":"Sprite"},{"key":"layer","type":"int","group":"Sprite"},{"key":"order","type":"int","group":"Sprite"},+ {"key":"maskInteraction","type":"int","group":"Sprite"},{"key":"lit","type":"bool","group":"Sprite"},{"key":"flipX","type":"bool","group":"Sprite"},{"key":"flipY","type":"bool","group":"Sprite"},@@ -574,6 +577,14 @@ std::string editor_getComponentSchema(const std::string& name) {{"key":"material","type":"asset","group":"Sprite"},{"key":"enabled","type":"bool","group":"Sprite"}])JSON";+ } else if (name == "SpriteMask") {+ return R"JSON([+ {"key":"alphaCutoff","type":"float","group":"SpriteMask"},+ {"key":"limitRange","type":"bool","group":"SpriteMask"},+ {"key":"rangeEndLayer","type":"int","group":"SpriteMask"},+ {"key":"rangeEndOrder","type":"int","group":"SpriteMask"},+ {"key":"enabled","type":"bool","group":"SpriteMask"}+ ])JSON";} else if (name == "TilemapLayer") {return R"JSON([{"key":"cellSize.x","type":"float","group":"TilemapLayer"},@@ -830,6 +841,9 @@ bool editor_addComponent(Registry& reg, u32 e, const std::string& name) {} else if (name == "Sprite") {if (!reg.has<esengine::ecs::Sprite>(entity)) reg.emplace<esengine::ecs::Sprite>(entity);return true;+ } else if (name == "SpriteMask") {+ if (!reg.has<esengine::ecs::SpriteMask>(entity)) reg.emplace<esengine::ecs::SpriteMask>(entity);+ return true;} else if (name == "TilemapLayer") {if (!reg.has<esengine::ecs::TilemapLayer>(entity)) reg.emplace<esengine::ecs::TilemapLayer>(entity);return true;@@ -932,6 +946,8 @@ bool editor_removeComponent(Registry& reg, u32 e, const std::string& name) {if (reg.has<esengine::ecs::SpineAnimation>(entity)) { reg.remove<esengine::ecs::SpineAnimation>(entity); return true; }} else if (name == "Sprite") {if (reg.has<esengine::ecs::Sprite>(entity)) { reg.remove<esengine::ecs::Sprite>(entity); return true; }+ } else if (name == "SpriteMask") {+ if (reg.has<esengine::ecs::SpriteMask>(entity)) { reg.remove<esengine::ecs::SpriteMask>(entity); return true; }} else if (name == "TilemapLayer") {if (reg.has<esengine::ecs::TilemapLayer>(entity)) { reg.remove<esengine::ecs::TilemapLayer>(entity); return true; }} else if (name == "TrailRenderer") {@@ -989,6 +1005,7 @@ bool editor_hasComponent(Registry& reg, u32 e, const std::string& name) {if (name == "SphereCollider3D") return reg.has<esengine::ecs::SphereCollider3D>(entity);if (name == "SpineAnimation") return reg.has<esengine::ecs::SpineAnimation>(entity);if (name == "Sprite") return reg.has<esengine::ecs::Sprite>(entity);+ if (name == "SpriteMask") return reg.has<esengine::ecs::SpriteMask>(entity);if (name == "TilemapLayer") return reg.has<esengine::ecs::TilemapLayer>(entity);if (name == "TrailRenderer") return reg.has<esengine::ecs::TrailRenderer>(entity);if (name == "Transform") return reg.has<esengine::ecs::Transform>(entity);@@ -1039,6 +1056,7 @@ std::vector<std::string> editor_getComponents(Registry& reg, u32 e) {if (reg.has<esengine::ecs::SphereCollider3D>(entity)) result.push_back("SphereCollider3D");if (reg.has<esengine::ecs::SpineAnimation>(entity)) result.push_back("SpineAnimation");if (reg.has<esengine::ecs::Sprite>(entity)) result.push_back("Sprite");+ if (reg.has<esengine::ecs::SpriteMask>(entity)) result.push_back("SpriteMask");if (reg.has<esengine::ecs::TilemapLayer>(entity)) result.push_back("TilemapLayer");if (reg.has<esengine::ecs::TrailRenderer>(entity)) result.push_back("TrailRenderer");if (reg.has<esengine::ecs::Transform>(entity)) result.push_back("Transform");@@ -1407,6 +1425,12 @@ bool editor_setFloat(Registry& reg, u32 e, const std::string& comp, const std::selse if (field == "parallax.y") { c.parallax.y = value; }else { return false; }return true;+ } else if (comp == "SpriteMask") {+ if (!reg.has<esengine::ecs::SpriteMask>(entity)) return false;+ auto& c = reg.get<esengine::ecs::SpriteMask>(entity);+ if (field == "alphaCutoff") { c.alphaCutoff = value; }+ else { return false; }+ return true;} else if (comp == "TilemapLayer") {if (!reg.has<esengine::ecs::TilemapLayer>(entity)) return false;auto& c = reg.get<esengine::ecs::TilemapLayer>(entity);@@ -1856,6 +1880,10 @@ f32 editor_getFloat(Registry& reg, u32 e, const std::string& comp, const std::stelse if (field == "tileSpacing.y") { return c.tileSpacing.y; }else if (field == "parallax.x") { return c.parallax.x; }else if (field == "parallax.y") { return c.parallax.y; }+ } else if (comp == "SpriteMask") {+ if (!reg.has<esengine::ecs::SpriteMask>(entity)) return 0.0f;+ const auto& c = reg.get<esengine::ecs::SpriteMask>(entity);+ if (field == "alphaCutoff") { return c.alphaCutoff; }} else if (comp == "TilemapLayer") {if (!reg.has<esengine::ecs::TilemapLayer>(entity)) return 0.0f;const auto& c = reg.get<esengine::ecs::TilemapLayer>(entity);@@ -2164,9 +2192,17 @@ bool editor_setInt(Registry& reg, u32 e, const std::string& comp, const std::strif (field == "texture") { c.texture = resource::TextureHandle(static_cast<u32>(value)); }else if (field == "layer") { c.layer = static_cast<i32>(value); }else if (field == "order") { c.order = static_cast<i32>(value); }+ else if (field == "maskInteraction") { c.maskInteraction = static_cast<i32>(value); }else if (field == "material") { c.material = static_cast<u32>(value); }else { return false; }return true;+ } else if (comp == "SpriteMask") {+ if (!reg.has<esengine::ecs::SpriteMask>(entity)) return false;+ auto& c = reg.get<esengine::ecs::SpriteMask>(entity);+ if (field == "rangeEndLayer") { c.rangeEndLayer = static_cast<i32>(value); }+ else if (field == "rangeEndOrder") { c.rangeEndOrder = static_cast<i32>(value); }+ else { return false; }+ return true;} else if (comp == "TilemapLayer") {if (!reg.has<esengine::ecs::TilemapLayer>(entity)) return false;auto& c = reg.get<esengine::ecs::TilemapLayer>(entity);@@ -2370,7 +2406,13 @@ i32 editor_getInt(Registry& reg, u32 e, const std::string& comp, const std::striif (field == "texture") { return static_cast<i32>(c.texture.id()); }else if (field == "layer") { return static_cast<i32>(c.layer); }else if (field == "order") { return static_cast<i32>(c.order); }+ else if (field == "maskInteraction") { return static_cast<i32>(c.maskInteraction); }else if (field == "material") { return static_cast<i32>(c.material); }+ } else if (comp == "SpriteMask") {+ if (!reg.has<esengine::ecs::SpriteMask>(entity)) return 0;+ const auto& c = reg.get<esengine::ecs::SpriteMask>(entity);+ if (field == "rangeEndLayer") { return static_cast<i32>(c.rangeEndLayer); }+ else if (field == "rangeEndOrder") { return static_cast<i32>(c.rangeEndOrder); }} else if (comp == "TilemapLayer") {if (!reg.has<esengine::ecs::TilemapLayer>(entity)) return 0;const auto& c = reg.get<esengine::ecs::TilemapLayer>(entity);@@ -2625,6 +2667,13 @@ bool editor_setBool(Registry& reg, u32 e, const std::string& comp, const std::stelse if (field == "enabled") { c.enabled = value; }else { return false; }return true;+ } else if (comp == "SpriteMask") {+ if (!reg.has<esengine::ecs::SpriteMask>(entity)) return false;+ auto& c = reg.get<esengine::ecs::SpriteMask>(entity);+ if (field == "limitRange") { c.limitRange = value; }+ else if (field == "enabled") { c.enabled = value; }+ else { return false; }+ return true;} else if (comp == "TilemapLayer") {if (!reg.has<esengine::ecs::TilemapLayer>(entity)) return false;auto& c = reg.get<esengine::ecs::TilemapLayer>(entity);@@ -2827,6 +2876,11 @@ bool editor_getBool(Registry& reg, u32 e, const std::string& comp, const std::stelse if (field == "flipX") { return c.flipX; }else if (field == "flipY") { return c.flipY; }else if (field == "enabled") { return c.enabled; }+ } else if (comp == "SpriteMask") {+ if (!reg.has<esengine::ecs::SpriteMask>(entity)) return false;+ const auto& c = reg.get<esengine::ecs::SpriteMask>(entity);+ if (field == "limitRange") { return c.limitRange; }+ else if (field == "enabled") { return c.enabled; }} else if (comp == "TilemapLayer") {if (!reg.has<esengine::ecs::TilemapLayer>(entity)) return false;const auto& c = reg.get<esengine::ecs::TilemapLayer>(entity);diff --git a/src/esengine/bindings/WebBindings.generated.cpp b/src/esengine/bindings/WebBindings.generated.cppindex 801c6b2f9..2b05f39cd 100644--- a/src/esengine/bindings/WebBindings.generated.cpp+++ b/src/esengine/bindings/WebBindings.generated.cpp@@ -34,6 +34,7 @@#include "../ecs/components/SortingGroup.hpp"#include "../ecs/components/SpineAnimation.hpp"#include "../ecs/components/Sprite.hpp"+#include "../ecs/components/SpriteMask.hpp"#include "../ecs/components/TilemapLayer.hpp"#include "../ecs/components/TrailRenderer.hpp"#include "../ecs/components/Transform.hpp"@@ -221,6 +222,11 @@ EMSCRIPTEN_BINDINGS(esengine_enums) {.value("World", esengine::ecs::SimulationSpace::World).value("Local", esengine::ecs::SimulationSpace::Local);+ enum_<esengine::ecs::SpriteMaskInteraction>("SpriteMaskInteraction")+ .value("None", esengine::ecs::SpriteMaskInteraction::None)+ .value("VisibleInside", esengine::ecs::SpriteMaskInteraction::VisibleInside)+ .value("VisibleOutside", esengine::ecs::SpriteMaskInteraction::VisibleOutside);+enum_<esengine::ecs::SubEmitterTrigger>("SubEmitterTrigger").value("Death", esengine::ecs::SubEmitterTrigger::Death).value("Birth", esengine::ecs::SubEmitterTrigger::Birth);@@ -1024,6 +1030,7 @@ struct SpriteJS {glm::vec2 uvScale;i32 layer;i32 order;+ i32 maskInteraction;bool lit;bool flipX;bool flipY;@@ -1043,6 +1050,7 @@ void spriteApplyJS(esengine::ecs::Sprite& c, const SpriteJS& js) {c.uvScale = js.uvScale;c.layer = js.layer;c.order = js.order;+ c.maskInteraction = js.maskInteraction;c.lit = js.lit;c.flipX = js.flipX;c.flipY = js.flipY;@@ -1069,6 +1077,7 @@ SpriteJS spriteToJS(const esengine::ecs::Sprite& c) {js.uvScale = c.uvScale;js.layer = c.layer;js.order = c.order;+ js.maskInteraction = c.maskInteraction;js.lit = c.lit;js.flipX = c.flipX;js.flipY = c.flipY;@@ -1749,6 +1758,7 @@ EMSCRIPTEN_BINDINGS(esengine_components) {.field("uvScale", &SpriteJS::uvScale).field("layer", &SpriteJS::layer).field("order", &SpriteJS::order)+ .field("maskInteraction", &SpriteJS::maskInteraction).field("lit", &SpriteJS::lit).field("flipX", &SpriteJS::flipX).field("flipY", &SpriteJS::flipY)@@ -1758,6 +1768,13 @@ EMSCRIPTEN_BINDINGS(esengine_components) {.field("material", &SpriteJS::material).field("enabled", &SpriteJS::enabled);+ value_object<esengine::ecs::SpriteMask>("SpriteMask")+ .field("alphaCutoff", &esengine::ecs::SpriteMask::alphaCutoff)+ .field("limitRange", &esengine::ecs::SpriteMask::limitRange)+ .field("rangeEndLayer", &esengine::ecs::SpriteMask::rangeEndLayer)+ .field("rangeEndOrder", &esengine::ecs::SpriteMask::rangeEndOrder)+ .field("enabled", &esengine::ecs::SpriteMask::enabled);+value_object<TilemapLayerJS>("TilemapLayer").field("cellSize", &TilemapLayerJS::cellSize).field("orientation", &TilemapLayerJS::orientation)@@ -2596,6 +2613,27 @@ EMSCRIPTEN_BINDINGS(esengine_registry) {r.remove<esengine::ecs::Sprite>(entity);}))+ // SpriteMask+ .function("hasSpriteMask", optional_override([](Registry& r, u32 e) {+ return r.has<esengine::ecs::SpriteMask>(static_cast<Entity>(e));+ }))+ .function("getSpriteMask", optional_override([](Registry& r, u32 e) -> esengine::ecs::SpriteMask& {+ auto entity = static_cast<Entity>(e);+ static esengine::ecs::SpriteMask s_dummy{};+ if (!r.valid(entity) || !r.has<esengine::ecs::SpriteMask>(entity)) return s_dummy;+ return r.get<esengine::ecs::SpriteMask>(entity);+ }), allow_raw_pointers())+ .function("addSpriteMask", optional_override([](Registry& r, u32 e, const esengine::ecs::SpriteMask& c) {+ auto entity = static_cast<Entity>(e);+ if (!r.valid(entity)) return;+ r.emplaceOrReplace<esengine::ecs::SpriteMask>(entity, c);+ }))+ .function("removeSpriteMask", optional_override([](Registry& r, u32 e) {+ auto entity = static_cast<Entity>(e);+ if (!r.valid(entity) || !r.has<esengine::ecs::SpriteMask>(entity)) return;+ r.remove<esengine::ecs::SpriteMask>(entity);+ }))+// TilemapLayer.function("hasTilemapLayer", optional_override([](Registry& r, u32 e) {return r.has<esengine::ecs::TilemapLayer>(static_cast<Entity>(e));@@ -2853,6 +2891,7 @@ emscripten::val esengineGetBuiltinComponentNames() {arr.set(i++, val(std::string("SphereCollider3D")));arr.set(i++, val(std::string("SpineAnimation")));arr.set(i++, val(std::string("Sprite")));+ arr.set(i++, val(std::string("SpriteMask")));arr.set(i++, val(std::string("TilemapLayer")));arr.set(i++, val(std::string("TrailRenderer")));arr.set(i++, val(std::string("Transform")));@@ -3152,14 +3191,20 @@ static_assert(offsetof(esengine::ecs::Sprite, uvOffset) == 36, "ABI offset driftstatic_assert(offsetof(esengine::ecs::Sprite, uvScale) == 44, "ABI offset drift: esengine::ecs::Sprite.uvScale (EHT expected 44)");static_assert(offsetof(esengine::ecs::Sprite, layer) == 52, "ABI offset drift: esengine::ecs::Sprite.layer (EHT expected 52)");static_assert(offsetof(esengine::ecs::Sprite, order) == 56, "ABI offset drift: esengine::ecs::Sprite.order (EHT expected 56)");-static_assert(offsetof(esengine::ecs::Sprite, lit) == 60, "ABI offset drift: esengine::ecs::Sprite.lit (EHT expected 60)");-static_assert(offsetof(esengine::ecs::Sprite, flipX) == 61, "ABI offset drift: esengine::ecs::Sprite.flipX (EHT expected 61)");-static_assert(offsetof(esengine::ecs::Sprite, flipY) == 62, "ABI offset drift: esengine::ecs::Sprite.flipY (EHT expected 62)");-static_assert(offsetof(esengine::ecs::Sprite, tileSize) == 64, "ABI offset drift: esengine::ecs::Sprite.tileSize (EHT expected 64)");-static_assert(offsetof(esengine::ecs::Sprite, tileSpacing) == 72, "ABI offset drift: esengine::ecs::Sprite.tileSpacing (EHT expected 72)");-static_assert(offsetof(esengine::ecs::Sprite, parallax) == 80, "ABI offset drift: esengine::ecs::Sprite.parallax (EHT expected 80)");-static_assert(offsetof(esengine::ecs::Sprite, material) == 88, "ABI offset drift: esengine::ecs::Sprite.material (EHT expected 88)");-static_assert(offsetof(esengine::ecs::Sprite, enabled) == 92, "ABI offset drift: esengine::ecs::Sprite.enabled (EHT expected 92)");+static_assert(offsetof(esengine::ecs::Sprite, maskInteraction) == 60, "ABI offset drift: esengine::ecs::Sprite.maskInteraction (EHT expected 60)");+static_assert(offsetof(esengine::ecs::Sprite, lit) == 64, "ABI offset drift: esengine::ecs::Sprite.lit (EHT expected 64)");+static_assert(offsetof(esengine::ecs::Sprite, flipX) == 65, "ABI offset drift: esengine::ecs::Sprite.flipX (EHT expected 65)");+static_assert(offsetof(esengine::ecs::Sprite, flipY) == 66, "ABI offset drift: esengine::ecs::Sprite.flipY (EHT expected 66)");+static_assert(offsetof(esengine::ecs::Sprite, tileSize) == 68, "ABI offset drift: esengine::ecs::Sprite.tileSize (EHT expected 68)");+static_assert(offsetof(esengine::ecs::Sprite, tileSpacing) == 76, "ABI offset drift: esengine::ecs::Sprite.tileSpacing (EHT expected 76)");+static_assert(offsetof(esengine::ecs::Sprite, parallax) == 84, "ABI offset drift: esengine::ecs::Sprite.parallax (EHT expected 84)");+static_assert(offsetof(esengine::ecs::Sprite, material) == 92, "ABI offset drift: esengine::ecs::Sprite.material (EHT expected 92)");+static_assert(offsetof(esengine::ecs::Sprite, enabled) == 96, "ABI offset drift: esengine::ecs::Sprite.enabled (EHT expected 96)");+static_assert(offsetof(esengine::ecs::SpriteMask, alphaCutoff) == 0, "ABI offset drift: esengine::ecs::SpriteMask.alphaCutoff (EHT expected 0)");+static_assert(offsetof(esengine::ecs::SpriteMask, limitRange) == 4, "ABI offset drift: esengine::ecs::SpriteMask.limitRange (EHT expected 4)");+static_assert(offsetof(esengine::ecs::SpriteMask, rangeEndLayer) == 8, "ABI offset drift: esengine::ecs::SpriteMask.rangeEndLayer (EHT expected 8)");+static_assert(offsetof(esengine::ecs::SpriteMask, rangeEndOrder) == 12, "ABI offset drift: esengine::ecs::SpriteMask.rangeEndOrder (EHT expected 12)");+static_assert(offsetof(esengine::ecs::SpriteMask, enabled) == 16, "ABI offset drift: esengine::ecs::SpriteMask.enabled (EHT expected 16)");static_assert(offsetof(esengine::ecs::TilemapLayer, cellSize) == 0, "ABI offset drift: esengine::ecs::TilemapLayer.cellSize (EHT expected 0)");static_assert(offsetof(esengine::ecs::TilemapLayer, orientation) == 8, "ABI offset drift: esengine::ecs::TilemapLayer.orientation (EHT expected 8)");static_assert(offsetof(esengine::ecs::TilemapLayer, hexSideLength) == 12, "ABI offset drift: esengine::ecs::TilemapLayer.hexSideLength (EHT expected 12)");@@ -3249,7 +3294,7 @@ static_assert(offsetof(esengine::ecs::Velocity, angular) == 12, "ABI offset drif// ABI Hash -- runtime handshake against the SDK bundle// =============================================================================-static const char* kEsAbiLayoutHash = "a30e798cbaa98d41";+static const char* kEsAbiLayoutHash = "73a4e6e098cc7a9b";std::string esengineGetAbiLayoutHash() {return std::string(kEsAbiLayoutHash);diff --git a/src/esengine/ecs/components/Sprite.hpp b/src/esengine/ecs/components/Sprite.hppindex a90e99425..c59af0546 100644--- a/src/esengine/ecs/components/Sprite.hpp+++ b/src/esengine/ecs/components/Sprite.hpp@@ -43,6 +43,18 @@ namespace esengine::ecs {* sprite.layer = 10; // Render on top* @endcode*/+/**+ * @brief What a `SpriteMask` reaching this sprite does to it.+ * @details Opt-in per sprite: a mask cuts only what asks to be cut, so adding a mask to a+ * scene cannot make unrelated sprites vanish.+ */+ES_ENUM(stability=public)+enum class SpriteMaskInteraction : i32 {+ None = 0, ///< Masks reaching this sprite are ignored.+ VisibleInside = 1, ///< Drawn only where the mask is — a window.+ VisibleOutside = 2, ///< Drawn only where the mask is NOT — a hole.+};+ES_COMPONENT(renderable=enabled, stability=public)struct Sprite {/** @brief Texture resource handle (type-safe) */@@ -79,6 +91,12 @@ struct Sprite {ES_PROPERTY(step=1, min=-128, max=127, optional, tooltip="Draw order inside the sorting layer — higher draws on top. Overrides the layer's Y-sort or depth ordering; leave 0 to keep it.")i32 order{0};+ /** @brief What a SpriteMask drawn before this sprite does to it. Opt-in, so a mask+ * added to a scene cannot make an unrelated sprite disappear. */+ ES_PROPERTY(enum=SpriteMaskInteraction, optional,+ tooltip="Whether a SpriteMask drawn before this sprite clips it, and which side survives.")+ i32 maskInteraction{0};+/** @brief Lit by the scene's 2D lights (Light), no material needed. Off = unlit. */ES_PROPERTY(tooltip="Receive 2D lights: Light entities light this sprite (flat normal). A custom material overrides this.")bool lit{false};diff --git a/src/esengine/ecs/components/SpriteMask.hpp b/src/esengine/ecs/components/SpriteMask.hppnew file mode 100644index 000000000..9b9141c21--- /dev/null+++ b/src/esengine/ecs/components/SpriteMask.hpp@@ -0,0 +1,57 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file SpriteMask.hpp+ * @brief Turns this entity's Sprite into a stencil the sprites drawn after it can be cut by.+ * @details The mask is a SPRITE, not a shape of its own: the same entity's `Sprite` supplies+ * the texture, size, pivot, flips and 9-slice, and is drawn with colour writes off.+ * A second geometry field would be a second thing to keep in step with what the+ * author sees, and there is nothing a mask needs that a sprite cannot already say.+ *+ * Reach is a RANGE, not a subtree. What a 2D mask cuts is rarely its own children —+ * a hole in a fog layer is drawn over scenery that belongs to no part of it — so the+ * mask reaches the sprites drawn after it, which is the order the author already+ * arranges by layer and order. `UIMask` keeps the subtree rule, because a UI tree+ * IS its containment.+ *+ * @copyright Copyright (c) 2026 ESEngine Team+ * Licensed under the Apache License, Version 2.0.+ */+#pragma once++#include "../../core/Types.hpp"+#include "../../core/Reflection.hpp"++namespace esengine::ecs {++/**+ * @brief A stencil cut from this entity's own Sprite.+ */+ES_COMPONENT(renderable=enabled, stability=beta)+struct SpriteMask {+ /** @brief Above 0, cut to the sprite's SHAPE — fragments below this alpha do not mask. */+ ES_PROPERTY(min=0, max=1, slider,+ tooltip="Cut to the sprite's shape instead of its box: fragments below this alpha do not mask.")+ f32 alphaCutoff{0.0f};++ /** @brief Stop reaching at a stated layer/order instead of running to the end of the frame. */+ ES_PROPERTY(tooltip="Limit how far this mask reaches; off = every sprite drawn after it.")+ bool limitRange{false};++ /** @brief Last sorting layer this mask reaches. */+ ES_PROPERTY(step=1, enum_source=sortingLayers, shown_when=limitRange:true,+ tooltip="Last sorting layer this mask reaches.")+ i32 rangeEndLayer{0};++ /** @brief Last order WITHIN that layer, inclusive. */+ ES_PROPERTY(step=1, min=-128, max=127, shown_when=limitRange:true,+ tooltip="Last order inside that layer this mask reaches, inclusive.")+ i32 rangeEndOrder{0};++ /** @brief Off is not a mask at all: the sprite goes back to being drawn normally,+ * which is what makes "is this masking?" answerable by looking. */+ ES_PROPERTY()+ bool enabled{true};+};++} // namespace esengine::ecsdiff --git a/src/esengine/renderer/draw/BatchBuilder.cpp b/src/esengine/renderer/draw/BatchBuilder.cppindex 3f48b689f..0324ab9e2 100644--- a/src/esengine/renderer/draw/BatchBuilder.cpp+++ b/src/esengine/renderer/draw/BatchBuilder.cpp@@ -51,13 +51,11 @@ void pushBatchDraw(DrawList& drawList, const ClipState& clips,// A group takes over its members' outward identity, so EVERY layer-derived decision// below asks the group's layer: the culling bit, the ordering rule, the key's top field.// Leaving one on the member y-sorts a group through one sprite and not the next.- i32 layer = key.layer;- i32 order = key.order;+ const DrawList::SortIdentity identity =+ drawList.sortIdentity(key.entity.id(), key.layer, key.order);+ const i32 layer = identity.layer;+ const i32 order = identity.order;const DrawList::GroupIdentity* group = drawList.sortingGroupOf(key.entity.id());- if (group) {- layer = group->layer;- order = group->order;- }// The camera's culling mask, applied at the one place draws are produced, so no// render path can be added that forgets it.diff --git a/src/esengine/renderer/draw/ClipState.hpp b/src/esengine/renderer/draw/ClipState.hppindex e5f1fc728..37e2e50ac 100644--- a/src/esengine/renderer/draw/ClipState.hpp+++ b/src/esengine/renderer/draw/ClipState.hpp@@ -34,6 +34,14 @@ public:void setStencilTest(u32 entity, i32 refValue) {auto& e = entries_[entity];e.flags |= CMD_STATE_STENCIL_TEST;+ e.flags &= ~(CMD_STATE_STENCIL_WRITE | CMD_STATE_STENCIL_OUT);+ e.stencil_ref = refValue;+ }++ /// Drawn only where the mask is NOT — the hole, rather than the window.+ void setStencilTestOutside(u32 entity, i32 refValue) {+ auto& e = entries_[entity];+ e.flags |= CMD_STATE_STENCIL_TEST | CMD_STATE_STENCIL_OUT;e.flags &= ~CMD_STATE_STENCIL_WRITE;e.stencil_ref = refValue;}@@ -63,4 +71,4 @@ private:std::unordered_map<u32, Entry> entries_;};-} // namespace esengine+} // namespace esengine\ No newline at end of filediff --git a/src/esengine/renderer/draw/DrawCommand.hpp b/src/esengine/renderer/draw/DrawCommand.hppindex 14413af4a..20170d5d9 100644--- a/src/esengine/renderer/draw/DrawCommand.hpp+++ b/src/esengine/renderer/draw/DrawCommand.hpp@@ -7,6 +7,7 @@#include "./RenderItem.hpp"#include "./BlendMode.hpp"#include "../rhi/TransientBufferPool.hpp"+#include "../rhi/PipelineState.hpp"#include <algorithm>#include <bit>@@ -20,6 +21,25 @@ static constexpr u16 CMD_STATE_SCISSOR = 0x01;static constexpr u16 CMD_STATE_STENCIL_WRITE = 0x02;static constexpr u16 CMD_STATE_STENCIL_TEST = 0x04;static constexpr u16 CMD_STATE_CUSTOM_DRAW = 0x08;+// Tests the reference the other way: drawn only where the stencil does NOT match.+// A separate flag rather than a sign on the ref, so a draw inside a mask and one+// outside the same mask never merge — they are different pipelines.+static constexpr u16 CMD_STATE_STENCIL_OUT = 0x10;++/**+ * @brief The stencil mode a draw's state flags mean.+ * @details One reading of these bits. Done at the point of use it would be done in each+ * backend's own words, and a mode nobody mapped is a draw that quietly tests the+ * wrong way — which looks like a mask that works everywhere but one path.+ */+inline GfxStencilMode stencilModeOf(u16 stateFlags) {+ if (stateFlags & CMD_STATE_STENCIL_WRITE) return GfxStencilMode::Write;+ if (stateFlags & CMD_STATE_STENCIL_TEST) {+ return (stateFlags & CMD_STATE_STENCIL_OUT) ? GfxStencilMode::TestOutside+ : GfxStencilMode::Test;+ }+ return GfxStencilMode::Off;+}/*** Why a draw call had to start rather than join the one before it. Every memberdiff --git a/src/esengine/renderer/draw/DrawList.cpp b/src/esengine/renderer/draw/DrawList.cppindex 63d78d11e..f271ae476 100644--- a/src/esengine/renderer/draw/DrawList.cpp+++ b/src/esengine/renderer/draw/DrawList.cpp@@ -178,9 +178,7 @@ void DrawList::execute(GfxDevice& device, TransientBufferPool& buffers,for (u32 i = 0; i < merged_draw_calls_; ++i) {const auto& cmd = commands_[i];- GfxStencilMode stencil = GfxStencilMode::Off;- if (cmd.state_flags & CMD_STATE_STENCIL_WRITE) stencil = GfxStencilMode::Write;- else if (cmd.state_flags & CMD_STATE_STENCIL_TEST) stencil = GfxStencilMode::Test;+ const GfxStencilMode stencil = stencilModeOf(cmd.state_flags);// Resolve the immutable pipeline. Depth/cull come from the command (resolved from// its material, or the 2D defaults: depth_write on with the test off). createPipeline@@ -292,4 +290,4 @@ void DrawList::execute(GfxDevice& device, TransientBufferPool& buffers,}}-} // namespace esengine+} // namespace esengine\ No newline at end of filediff --git a/src/esengine/renderer/draw/DrawList.hpp b/src/esengine/renderer/draw/DrawList.hppindex 692cf8933..3335f6262 100644--- a/src/esengine/renderer/draw/DrawList.hpp+++ b/src/esengine/renderer/draw/DrawList.hpp@@ -136,6 +136,24 @@ public:return it != group_identities_.end() ? &it->second : nullptr;}+ /** @brief Where a draw sits in the frame's order, once any group has had its say. */+ struct SortIdentity {+ i32 layer = 0;+ i32 order = 0;+ bool operator<(const SortIdentity& o) const {+ return layer != o.layer ? layer < o.layer : order < o.order;+ }+ bool operator<=(const SortIdentity& o) const { return !(o < *this); }+ };++ /** @brief The one answer to "where does this draw sit". Asked by the draw path when it+ * builds a key, and by anything that must reason about that order BEFORE the+ * keys exist — a second implementation is a second order. */+ SortIdentity sortIdentity(u32 entity, i32 ownLayer, i32 ownOrder) const {+ if (const GroupIdentity* g = sortingGroupOf(entity)) return {g->layer, g->order};+ return {ownLayer, ownOrder};+ }+private:struct SortEntry {u64 key;diff --git a/src/esengine/renderer/draw/SpriteMaskRange.hpp b/src/esengine/renderer/draw/SpriteMaskRange.hppnew file mode 100644index 000000000..bd7322e8d--- /dev/null+++ b/src/esengine/renderer/draw/SpriteMaskRange.hpp@@ -0,0 +1,58 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file SpriteMaskRange.hpp+ * @brief Which SpriteMask, if any, cuts a sprite — the rule, apart from the frame.+ * @details A mask reaches FORWARD: it cuts what is drawn after it, because that is the+ * order the stencil is written in and the order the author already arranges by+ * layer and order. Pure so it can be held to cases directly; a frame can only+ * show that some mask won, never which one the rule chose.+ *+ * @copyright Copyright (c) 2026 ESEngine Team+ * Licensed under the Apache License, Version 2.0.+ */+#pragma once++#include "./DrawList.hpp"++namespace esengine {++/// A SpriteMask's own place in the frame, how far it reaches, and the ref it stamps.+struct ResolvedMask {+ DrawList::SortIdentity at;+ DrawList::SortIdentity reachEnd;+ bool limited = false;+ i32 ref = 0;+};++/**+ * @brief Whether @p mask still covers a draw sitting at @p where.+ *+ * Strictly after: a mask and a sprite at the same place have no order between them, and+ * a stencil written by a draw that may come second cuts nothing reliably.+ */+inline bool maskReaches(const ResolvedMask& mask, const DrawList::SortIdentity& where) {+ if (!(mask.at < where)) return false;+ return !mask.limited || where <= mask.reachEnd;+}++/**+ * @brief The mask whose ref the stencil still holds at @p where, or null.+ *+ * @details The NEAREST reaching one, because it wrote last: where two masks overlap, the+ * later write is what is in the buffer, so testing an earlier mask's ref would+ * fail exactly inside the mask that covered it.+ */+inline const ResolvedMask* nearestReachingMask(+ const ResolvedMask* masks, u32 count, const DrawList::SortIdentity& where+) {+ const ResolvedMask* nearest = nullptr;+ for (u32 i = 0; i < count; ++i) {+ const ResolvedMask& mask = masks[i];+ if (mask.ref == 0 || !maskReaches(mask, where)) continue;+ if (!nearest || nearest->at < mask.at) nearest = &mask;+ }+ return nearest;+}++} // namespace esengine\ No newline at end of filediff --git a/src/esengine/renderer/frame/RenderFrame.cpp b/src/esengine/renderer/frame/RenderFrame.cppindex c85320e19..a5d3933c0 100644--- a/src/esengine/renderer/frame/RenderFrame.cpp+++ b/src/esengine/renderer/frame/RenderFrame.cpp@@ -10,6 +10,8 @@#include "../../ecs/components/Light.hpp"#include "../../ecs/components/ShadowCaster2D.hpp"#include "../../ecs/components/SortingGroup.hpp"+#include "../../ecs/components/SpriteMask.hpp"+#include "../../ecs/components/Sprite.hpp"#include "../../ecs/components/Hierarchy.hpp"#include "../../ecs/components/MeshRenderer.hpp"#include "../../resource/ShaderParser.hpp"@@ -369,6 +371,10 @@ void RenderFrame::openPass(const PassClear& clear, RenderTargetManager::Handle tRenderPassDesc pass{};pass.clearColor = clear.color;pass.clearDepth = clear.depth;+ // Stencil shares depth's attachment, so it clears on the same terms and costs the same+ // load-op. A frame keeping last frame's stencil cuts along a mask that has since moved;+ // a camera deliberately keeping depth means to keep that cut too.+ pass.clearStencil = clear.depth;// Authored clear colors are sRGB; the linear frame clears in linear light.const glm::vec3 clearRgb = linear_color_? srgbToLinearCpu({clear.colorValue.r, clear.colorValue.g, clear.colorValue.b})@@ -959,6 +965,72 @@ void RenderFrame::buildSortingGroups(ecs::Registry& registry) {}}+void RenderFrame::buildSpriteMasks(ecs::Registry& registry) {+ // 255 is the stencil attachment's, not a budget: refs are per FRAME and a mask past+ // the last one is dropped rather than aliased onto another mask's cut.+ static constexpr i32 MAX_MASK_REF = 255;++ std::vector<ResolvedMask>& masks = sprite_mask_scratch_;+ masks.clear();++ auto maskView = registry.view<ecs::SpriteMask>();+ for (auto entity : maskView) {+ const auto& mask = maskView.get(entity);+ if (!mask.enabled) continue;+ // The mask IS its sprite, so a sprite that will not be drawn cuts nothing. Without+ // this, hiding a mask makes everything it reached disappear instead of appear.+ if (!registry.has<ecs::Sprite>(entity)) continue;+ const auto& sprite = registry.get<ecs::Sprite>(entity);+ if (!sprite.enabled) continue;++ masks.push_back({+ draw_list_.sortIdentity(entity.id(), sprite.layer, sprite.order),+ {mask.rangeEndLayer, mask.rangeEndOrder},+ mask.limitRange,+ 0,+ });+ mask_entities_scratch_.push_back(entity);+ }+ if (masks.empty()) { mask_entities_scratch_.clear(); return; }++ // Refs run in DRAW order so a later mask overwrites an earlier one where they overlap,+ // which is what the stencil does anyway — assigning them in view order would make which+ // mask wins depend on entity creation.+ std::vector<u32> byDraw(masks.size());+ for (u32 i = 0; i < masks.size(); ++i) byDraw[i] = i;+ std::sort(byDraw.begin(), byDraw.end(),+ [&](u32 a, u32 b) { return masks[a].at < masks[b].at; });++ i32 nextRef = 1;+ for (u32 slot : byDraw) {+ if (nextRef > MAX_MASK_REF) {+ ES_LOG_WARN("SpriteMask: more than 255 masks in one frame; the rest cut nothing");+ break;+ }+ masks[slot].ref = nextRef++;+ clip_state_.setStencilMask(mask_entities_scratch_[slot].id(), masks[slot].ref);+ }++ auto spriteView = registry.view<ecs::Sprite>();+ for (auto entity : spriteView) {+ const auto& sprite = spriteView.get(entity);+ if (sprite.maskInteraction == 0 || !sprite.enabled) continue;+ if (registry.has<ecs::SpriteMask>(entity)) continue; // a mask is not its own subject++ const auto where = draw_list_.sortIdentity(entity.id(), sprite.layer, sprite.order);+ const ResolvedMask* nearest =+ nearestReachingMask(masks.data(), static_cast<u32>(masks.size()), where);+ if (!nearest) continue;++ if (sprite.maskInteraction == static_cast<i32>(ecs::SpriteMaskInteraction::VisibleOutside)) {+ clip_state_.setStencilTestOutside(entity.id(), nearest->ref);+ } else {+ clip_state_.setStencilTest(entity.id(), nearest->ref);+ }+ }+ mask_entities_scratch_.clear();+}+RenderFrameContext RenderFrame::makeContext() {return {context_,@@ -1696,6 +1768,8 @@ void RenderFrame::collectAll(ecs::Registry& registry) {// work that a single total cannot be told apart by.{ ES_PROFILE_SCOPE("render.collect.clip"); buildClipState(); }{ ES_PROFILE_SCOPE("render.collect.sorting"); buildSortingGroups(registry); }+ // After the groups, because a mask's reach is stated in the order a group may own.+ { ES_PROFILE_SCOPE("render.collect.spriteMasks"); buildSpriteMasks(registry); }{ ES_PROFILE_SCOPE("render.collect.lights"); collectLights(registry); }// Decided here, drawn by the graph. Nothing in this function may touch the// device: the frame reaches the host as several calls with its own drawsdiff --git a/src/esengine/renderer/frame/RenderFrame.hpp b/src/esengine/renderer/frame/RenderFrame.hppindex 245d64c8d..c80e5131b 100644--- a/src/esengine/renderer/frame/RenderFrame.hpp+++ b/src/esengine/renderer/frame/RenderFrame.hpp@@ -21,6 +21,7 @@#include "../rhi/TransientBufferPool.hpp"#include "../draw/DrawList.hpp"#include "../draw/ClipState.hpp"+#include "../draw/SpriteMaskRange.hpp"#include "../../ecs/Registry.hpp"#include "../../resource/ResourceManager.hpp"@@ -558,6 +559,8 @@ private:RenderFrameContext makeContext();void buildClipState();+ /// Resolves every SpriteMask into the stencil refs the draw path reads.+ void buildSpriteMasks(ecs::Registry& registry);/// Resolves every SortingGroup into the per-entity identity the draw path reads.void buildSortingGroups(ecs::Registry& registry);/// Adds a finalized list's cost to this frame's tally (see the definition).@@ -740,6 +743,9 @@ private:i32 overlay_vp_x_ = 0, overlay_vp_y_ = 0;u32 overlay_vp_w_ = 0, overlay_vp_h_ = 0;+ /// buildSpriteMasks scratch, reused across cameras/frames.+ std::vector<ResolvedMask> sprite_mask_scratch_;+ std::vector<Entity> mask_entities_scratch_;// processMasks scratch, reused across cameras/frames.std::vector<Entity> mask_scissor_scratch_;std::vector<Entity> mask_stencil_scratch_;diff --git a/src/esengine/renderer/plugins/SpritePlugin.cpp b/src/esengine/renderer/plugins/SpritePlugin.cppindex c47b61748..1212a3b14 100644--- a/src/esengine/renderer/plugins/SpritePlugin.cpp+++ b/src/esengine/renderer/plugins/SpritePlugin.cpp@@ -7,6 +7,7 @@#include "../rhi/Texture.hpp"#include "../../ecs/components/Transform.hpp"#include "../../ecs/components/Sprite.hpp"+#include "../../ecs/components/SpriteMask.hpp"#include "../../ecs/components/UINode.hpp"#include <cmath>@@ -118,6 +119,16 @@ void SpritePlugin::collect(RenderCollectContext& collect_ctx) {if (litProgram != 0) key.shaderId = litProgram;}+ // A mask with a cutoff cuts to the SHAPE it draws, not its box: this same draw runs+ // with colour writes off to fill the stencil, so it needs the variant that discards+ // transparent fragments or a round mask cuts a rectangle. Same resolution as UIMask.+ if (ctx.frame) {+ if (const auto* mask = registry.tryGet<ecs::SpriteMask>(entity);+ mask && mask->enabled && mask->alphaCutoff > 0.0f) {+ key.shaderId = ctx.frame->batchProgram({"ALPHA_CLIP"});+ }+ }+if (hasTiling) {emitTiledQuads(buffers, draw_list, clips,position, finalSize, sprite.pivot,diff --git a/src/esengine/renderer/rhi/GLDevice.cpp b/src/esengine/renderer/rhi/GLDevice.cppindex f39981193..f033a4096 100644--- a/src/esengine/renderer/rhi/GLDevice.cpp+++ b/src/esengine/renderer/rhi/GLDevice.cpp@@ -955,6 +955,7 @@ void GLDevice::applyStencilMode(GfxStencilMode mode) {setStencilMask(0xFF);break;case GfxStencilMode::Test:+ case GfxStencilMode::TestOutside:setStencilTest(true);setStencilOp(GfxStencilOp::Keep, GfxStencilOp::Keep, GfxStencilOp::Keep);setColorMask(true, true, true, true);@@ -992,6 +993,9 @@ void GLDevice::setStencilReference(i32 ref) {case GfxStencilMode::Test:setStencilFunc(GfxStencilFunc::Equal, ref, 0xFF);break;+ case GfxStencilMode::TestOutside:+ setStencilFunc(GfxStencilFunc::NotEqual, ref, 0xFF);+ break;case GfxStencilMode::Off:break;}diff --git a/src/esengine/renderer/rhi/PipelineState.hpp b/src/esengine/renderer/rhi/PipelineState.hppindex 5b3dd1688..cfaaff4d6 100644--- a/src/esengine/renderer/rhi/PipelineState.hpp+++ b/src/esengine/renderer/rhi/PipelineState.hpp@@ -31,9 +31,10 @@ namespace esengine {* (GfxDevice::setStencilReference), the compare/op/masks are pipeline state.*/enum class GfxStencilMode : u8 {- Off, ///< No stencil test; full color write.- Write, ///< Write the reference where drawn (mask fill): func Always, op Replace, color write off.- Test, ///< Draw only where the stencil equals the reference (mask clip): func Equal, op Keep.+ Off, ///< No stencil test; full color write.+ Write, ///< Write the reference where drawn (mask fill): func Always, op Replace, color write off.+ Test, ///< Draw only INSIDE the mask: func Equal, op Keep.+ TestOutside, ///< Draw only OUTSIDE it: func NotEqual, op Keep — a hole, not a window.};/**diff --git a/src/esengine/renderer/webgpu/WebGPUMappings.hpp b/src/esengine/renderer/webgpu/WebGPUMappings.hppindex db840088f..15632f5eb 100644--- a/src/esengine/renderer/webgpu/WebGPUMappings.hpp+++ b/src/esengine/renderer/webgpu/WebGPUMappings.hpp@@ -276,6 +276,11 @@ inline WGPUStencilFaceState toWGPUStencilFace(GfxStencilMode mode) {face.failOp = WGPUStencilOperation_Keep;face.passOp = WGPUStencilOperation_Keep;break;+ case GfxStencilMode::TestOutside:+ face.compare = WGPUCompareFunction_NotEqual;+ face.failOp = WGPUStencilOperation_Keep;+ face.passOp = WGPUStencilOperation_Keep;+ break;case GfxStencilMode::Off:default:face.compare = WGPUCompareFunction_Always;diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txtindex 96502c376..6812a16f6 100644--- a/tests/CMakeLists.txt+++ b/tests/CMakeLists.txt@@ -176,6 +176,14 @@ target_include_directories(test_draw_params PRIVATE)add_test(NAME test_draw_params COMMAND test_draw_params)+# Which SpriteMask cuts a sprite — the reach rule, apart from a frame. Header-only.+add_executable(test_sprite_mask_range renderer/test_sprite_mask_range.cpp)+target_include_directories(test_sprite_mask_range PRIVATE+ ${CMAKE_SOURCE_DIR}/src+ ${CMAKE_SOURCE_DIR}/third_party/glm+)+add_test(NAME test_sprite_mask_range COMMAND test_sprite_mask_range)+# The sort key's field layout, asserted on the bits. Header-only, so no engine link.add_executable(test_sort_key renderer/test_sort_key.cpp)target_include_directories(test_sort_key PRIVATEdiff --git a/tests/aot/generated/conformance/handshake.h b/tests/aot/generated/conformance/handshake.hindex 02c02df7b..096a1f704 100644--- a/tests/aot/generated/conformance/handshake.h+++ b/tests/aot/generated/conformance/handshake.h@@ -1,5 +1,5 @@/* GENERATED by sdk/tests/aot-conformance.test.ts — do not edit. *//* The contract half of the handshake. The width half is the harness. */-#define ES_CONF_EXPECTED_CONTRACT_HASH 0xa4154112ef21846cULL+#define ES_CONF_EXPECTED_CONTRACT_HASH 0xde68c21baa4ee1b4ULL/* And which BUILD the artifact beside this one is. */#define ES_CONF_EXPECTED_MODULE_CONTRACT 0xc3d0e057d5701a2eULLdiff --git a/tests/aot/generated/conformance/systems_decl.c b/tests/aot/generated/conformance/systems_decl.cindex de1cf3021..8d0f958bc 100644--- a/tests/aot/generated/conformance/systems_decl.c+++ b/tests/aot/generated/conformance/systems_decl.c@@ -10,7 +10,7 @@answer, it is a read of a different field. The address width belongsto the MACHINE, so it mixes in here rather than in the compiler and a32-bit artifact cannot load into a 64-bit host. */-#define ES_ABI_ENGINE_DIGEST 0xa4154112ef21846cULL+#define ES_ABI_ENGINE_DIGEST 0xde68c21baa4ee1b4ULLES_EXPORT const uint64_t es_abi_hash =ES_ABI_ENGINE_DIGEST ^ (0x9e3779b97f4a7c15ULL * (uint64_t)sizeof(es_addr_t));diff --git a/tests/renderer/test_batch_builder.cpp b/tests/renderer/test_batch_builder.cppindex 90a225558..3dcca562e 100644--- a/tests/renderer/test_batch_builder.cpp+++ b/tests/renderer/test_batch_builder.cpp@@ -1189,3 +1189,43 @@ TEST_CASE("group: an ungrouped draw is unaffected by another entity's group") {CHECK(h.list.command(0).texture_ids[0] == 2);CHECK(h.list.command(1).texture_ids[0] == 1);}++// A sprite cut to the inside of a mask and one cut to the outside of the SAME mask differ+// only in a state flag. Merged, one of them would be drawn with the other's stencil compare+// — the hole and the window are the same picture then.+TEST_CASE("stencil: inside and outside of one mask are different draws") {+ Harness h;+ h.clips.setStencilTest(61, 1);+ h.clips.setStencilTestOutside(62, 1);+ BatchVertex quad[4] = {};++ BatchDrawKey inside = quadKey(1, /*layer=*/2);+ inside.entity = Entity(61);+ BatchDrawKey outside = quadKey(1, /*layer=*/2);+ outside.entity = Entity(62);++ appendQuad(h.pool, h.list, h.clips, quad, inside);+ appendQuad(h.pool, h.list, h.clips, quad, outside);+ h.list.finalize(h.pool);++ REQUIRE(h.list.mergedDrawCallCount() == 2);+ CHECK((h.list.command(0).state_flags & CMD_STATE_STENCIL_OUT) == 0);+ CHECK((h.list.command(1).state_flags & CMD_STATE_STENCIL_OUT) != 0);+}++// Setting one mode must clear the other, or a sprite switched from outside to inside keeps+// both flags and reads as outside forever.+TEST_CASE("stencil: the two test modes are exclusive on one entity") {+ ClipState clips;+ clips.setStencilTestOutside(70, 3);+ clips.setStencilTest(70, 3);+ DrawCommand cmd{};+ clips.applyTo(Entity(70), cmd);+ CHECK((cmd.state_flags & CMD_STATE_STENCIL_TEST) != 0);+ CHECK((cmd.state_flags & CMD_STATE_STENCIL_OUT) == 0);++ clips.setStencilTestOutside(70, 3);+ DrawCommand back{};+ clips.applyTo(Entity(70), back);+ CHECK((back.state_flags & CMD_STATE_STENCIL_OUT) != 0);+}diff --git a/tests/renderer/test_sort_key.cpp b/tests/renderer/test_sort_key.cppindex 75b7f4d3e..b5210c818 100644--- a/tests/renderer/test_sort_key.cpp+++ b/tests/renderer/test_sort_key.cpp@@ -102,6 +102,30 @@ int main() {"stamping a member order touches no other field");}+ // ---- What the state flags mean ------------------------------------------------+ // The one reading of these bits. A backend doing it in its own words is how a mask+ // ends up working everywhere but one path.+ {+ CHECK(stencilModeOf(0) == GfxStencilMode::Off, "no stencil bits means no stencil");+ CHECK(stencilModeOf(CMD_STATE_STENCIL_WRITE) == GfxStencilMode::Write,+ "the write bit fills the mask");+ CHECK(stencilModeOf(CMD_STATE_STENCIL_TEST) == GfxStencilMode::Test,+ "the test bit alone cuts to the INSIDE");+ CHECK(stencilModeOf(CMD_STATE_STENCIL_TEST | CMD_STATE_STENCIL_OUT)+ == GfxStencilMode::TestOutside,+ "the outside bit cuts to the hole instead");+ // Write outranks test: a mask filling the stencil cannot also be tested against+ // the value it is in the middle of writing.+ CHECK(stencilModeOf(CMD_STATE_STENCIL_WRITE | CMD_STATE_STENCIL_TEST)+ == GfxStencilMode::Write,+ "a draw that writes is not also a draw that tests");+ // The outside bit on its own is not a test — it qualifies one.+ CHECK(stencilModeOf(CMD_STATE_STENCIL_OUT) == GfxStencilMode::Off,+ "the outside bit alone turns nothing on");+ CHECK(stencilModeOf(CMD_STATE_SCISSOR) == GfxStencilMode::Off,+ "a scissored draw is not a stencilled one");+ }+std::printf(g_failures ? "\n%d check(s) failed\n" : "\nall checks passed\n", g_failures);return g_failures == 0 ? 0 : 1;}diff --git a/tests/renderer/test_sprite_mask_range.cpp b/tests/renderer/test_sprite_mask_range.cppnew file mode 100644index 000000000..35049dea7--- /dev/null+++ b/tests/renderer/test_sprite_mask_range.cpp@@ -0,0 +1,100 @@+// Which SpriteMask cuts a sprite. A frame can show that SOME mask won; only this can+// show which one the rule chose, and the rule is what the next change has to keep.+// Header-only, so no engine link.++#include "esengine/renderer/draw/SpriteMaskRange.hpp"++#include <cstdio>+#include <vector>++using namespace esengine;++static int g_failures = 0;+#define CHECK(cond, msg) \+ do { \+ if (!(cond)) { std::printf("FAIL: %s\n", msg); ++g_failures; } \+ else { std::printf("ok: %s\n", msg); } \+ } while (0)++static DrawList::SortIdentity at(i32 layer, i32 order) { return {layer, order}; }++/// An unlimited mask sitting at (layer, order), with the ref it would stamp.+static ResolvedMask mask(i32 layer, i32 order, i32 ref) {+ return {at(layer, order), {}, false, ref};+}+static ResolvedMask limited(i32 layer, i32 order, i32 endLayer, i32 endOrder, i32 ref) {+ return {at(layer, order), at(endLayer, endOrder), true, ref};+}++static const ResolvedMask* nearest(const std::vector<ResolvedMask>& v,+ const DrawList::SortIdentity& where) {+ return nearestReachingMask(v.data(), static_cast<u32>(v.size()), where);+}++int main() {+ // ---- Forward reach ------------------------------------------------------------+ // A mask cuts what is drawn AFTER it, because that is when its stencil exists.+ {+ const ResolvedMask m = mask(2, 0, 1);+ CHECK(maskReaches(m, at(2, 1)), "a mask reaches a sprite later in its layer");+ CHECK(maskReaches(m, at(3, -128)), "a mask reaches into a later layer");+ CHECK(!maskReaches(m, at(2, -1)), "a mask does not reach a sprite drawn before it");+ CHECK(!maskReaches(m, at(1, 127)), "nor one in an earlier layer");+ }++ // Equal is NOT covered: two draws at one place have no order between them, so the+ // stencil may be written after the draw that was supposed to test it.+ {+ const ResolvedMask m = mask(2, 5, 1);+ CHECK(!maskReaches(m, at(2, 5)), "a mask does not reach a sprite at its own place");+ }++ // ---- A stated reach ------------------------------------------------------------+ // Inclusive at the end: the field says "last order this reaches".+ {+ const ResolvedMask m = limited(2, 0, /*end=*/2, 5, 1);+ CHECK(maskReaches(m, at(2, 5)), "a limited mask reaches its stated end");+ CHECK(!maskReaches(m, at(2, 6)), "and stops one past it");+ CHECK(!maskReaches(m, at(3, -128)), "a limited mask does not spill into a later layer");+ }++ // ---- Which mask the stencil actually holds --------------------------------------+ // The nearest one, because it wrote last. Testing the earlier mask's ref would fail+ // exactly where the later mask covered it — the sprite would vanish inside the mask.+ {+ const std::vector<ResolvedMask> v{mask(1, 0, 1), mask(2, 0, 2)};+ const ResolvedMask* n = nearest(v, at(3, 0));+ CHECK(n && n->ref == 2, "the nearest reaching mask decides");+ }+ // Order in the list is not the answer — the same pair, listed the other way.+ {+ const std::vector<ResolvedMask> v{mask(2, 0, 2), mask(1, 0, 1)};+ const ResolvedMask* n = nearest(v, at(3, 0));+ CHECK(n && n->ref == 2, "and it is nearest by PLACE, not by position in the list");+ }+ // A nearer mask that does not reach this far leaves the farther one in charge.+ {+ const std::vector<ResolvedMask> v{mask(1, 0, 1), limited(2, 0, 2, 3, 2)};+ const ResolvedMask* n = nearest(v, at(5, 0));+ CHECK(n && n->ref == 1, "a nearer mask whose reach ended does not take over");+ }+ {+ const std::vector<ResolvedMask> v{};+ CHECK(nearest(v, at(1, 0)) == nullptr, "no masks, no cut");+ }+ {+ const std::vector<ResolvedMask> v{mask(5, 0, 1)};+ CHECK(nearest(v, at(1, 0)) == nullptr, "a mask drawn later cuts nothing before it");+ }++ // A mask that never got a ref (past the stencil's 255) must not be chosen — it cuts+ // nothing, and picking it would test ref 0, which is every unmasked pixel.+ {+ const std::vector<ResolvedMask> v{mask(1, 0, 1), mask(2, 0, 0)};+ const ResolvedMask* n = nearest(v, at(3, 0));+ CHECK(n && n->ref == 1, "a mask with no ref is skipped, not chosen with ref 0");+ }++ std::printf(g_failures ? "\n%d check(s) failed\n" : "\nall checks passed\n", g_failures);+ return g_failures == 0 ? 0 : 1;+}diff --git a/tools/check-gizmo-coverage.mjs b/tools/check-gizmo-coverage.mjsindex e4ed8b487..db6c7e572 100644--- a/tools/check-gizmo-coverage.mjs+++ b/tools/check-gizmo-coverage.mjs@@ -133,6 +133,7 @@ const DISPOSITION = {'CacheAsBitmap.width': ['not-world', 'the cache texture\'s pixel size'],'CacheAsBitmap.height': ['not-world', 'the cache texture\'s pixel size'],'UIDropdown.optionHeight': ['not-world', 'a row height inside a laid-out box, resolved by layout rather than placed'],+ 'SpriteMask.rangeEndOrder': ['not-world', 'the last draw ORDER a mask reaches, not a distance it reaches over'],'LODGroup.lod1Size': ['not-world', 'a fraction of SCREEN height — a property of the view, not of the entity'],'LODGroup.lod2Size': ['not-world', 'a fraction of SCREEN height — a property of the view, not of the entity'],'LODGroup.lod3Size': ['not-world', 'a fraction of SCREEN height — a property of the view, not of the entity'],diff --git a/tools/renderScenes.mjs b/tools/renderScenes.mjsindex a97bfc1b6..fdd0efd3c 100644--- a/tools/renderScenes.mjs+++ b/tools/renderScenes.mjs@@ -74,6 +74,10 @@ export const SCENES = [// the coverage check, so "grazing" is what tells the two apart.{ id: "editor-grid-grazing", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_SCENE: "/scenes/mesh-instanced.esscene", ESTELLA_VERIFY_GRID: "64", ESTELLA_VERIFY_GRID_EXPECT: "grazing", ESTELLA_VERIFY_PERSPECTIVE: "1", ESTELLA_VERIFY_ORBIT: "0,4", ESTELLA_VERIFY_STEPS: "3" } },{ id: "mesh-renderer", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_SCENE: "/scenes/mesh-renderer.esscene", ESTELLA_VERIFY_MANIFEST: "/scenes/mesh-renderer.textures.json", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "4", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.30,\"y\":0.556,\"rgb\":[255,0,0],\"tol\":40},{\"x\":0.70,\"y\":0.556,\"rgb\":[0,255,0],\"tol\":40},{\"x\":0.30,\"y\":0.40,\"rgb\":[255,0,0],\"tol\":40}]" } },+ // One mask, both its sides, and a sprite that never asked. A mask that does nothing+ // paints the frame red; a side that inverted swaps green and red. The blue bar states+ // no interaction and must survive, or masking is not opt-in.+ { id: "sprite-mask", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_SCENE: "/scenes/sprite-mask.esscene", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "2", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.25,\"y\":0.5,\"rgb\":[0,255,0],\"tol\":30},{\"x\":0.75,\"y\":0.5,\"rgb\":[255,0,0],\"tol\":30},{\"x\":0.25,\"y\":0.9375,\"rgb\":[0,0,255],\"tol\":30},{\"x\":0.75,\"y\":0.9375,\"rgb\":[0,0,255],\"tol\":30}]" } },{ id: "parallax-shape", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_SCENE: "/scenes/parallax-shape.esscene", ESTELLA_VERIFY_MANIFEST: "/scenes/parallax-shape.textures.json", ESTELLA_VERIFY_STEPS: "4", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.5,\"y\":0.5,\"rgb\":[0,255,0],\"tol\":40},{\"x\":0.25,\"y\":0.5,\"rgb\":[255,0,0],\"tol\":40}]" } },{ id: "tilemap-flip", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_SCENE: "/scenes/tilemap-flip.esscene", ESTELLA_VERIFY_MANIFEST: "/scenes/tilemap-flip.textures.json", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "2", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.40,\"y\":0.36,\"rgb\":[255,0,0]},{\"x\":0.60,\"y\":0.36,\"rgb\":[0,255,0]},{\"x\":0.40,\"y\":0.58,\"rgb\":[0,0,255]},{\"x\":0.60,\"y\":0.58,\"rgb\":[255,255,0]}]" } },// A layer's own offset, set through the inspector's door: 16 world units is one