Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Objective
Adds the ability to mask
Sprite
s with otherImage
s.Implements #4210
Solution
Usage
Entity
withMask
containing a handle to theImage
. Most of the other fields work like the ones fromSprite
.SpriteBundle
(s) withMasked
components taking theEntity
with theMask
component.A
Mask
will be applied to all renderedMasked
Sprite
s pointing to it. ASprite
can only be affected by a singleMask
.Pipeline implementation
threshold
values.threshold
currently) form group(3). AddsSIXTEEN_BYTE_ALIGNMENT
define to align uniforms when targeting WebGL2.Sprite
Image
orMask
.Shader implementation
Masked
vertex, calculate the effectiveMask
uv coordinates at that point. (If the vertex is not contained within theMask
bounds, the UVs will be outside of the 0 to 1 range and use the sampler'sAddressMode
.)Design concerns
Masked
toMask
with just anEntity
is not great, but I don't know of anything better until kinded entities or relations are available? This also makes spawning a self-maskingEntity
awkward.Mask
andMasked
be more specific? To differentiate from potential future UI or polygon-based masking?Sampler AddressModes
Changing the
AddressMode
of the mask's sampler is useful to set masking state outside of the mask bounds, or to create a repeating mask. Currently, setting the sampler can't be be done as a part ofImage
loading, it must be done after loading is complete #6893. The recent asset loading changes could make this easy to allow withImageLoaderSettings
, ifImageSampler
were serializable.Note,
AddressMode::ClampToBorder
is not currently supported by WebGPU (gpuweb/gpuweb#1305), though it can be replicated withClampToEdge
and adding a slight border to the mask.Changelog
Mask
andMasked
components.Sprite
s withMasked
components will be masked by the linkedMask
entity.Migration Guide
ExtractedSprite
,ExtractedSprites
,SpritePipeline
,SpriteMeta
,SpriteBatch
, andImageBindGroups
.Footnotes
To allow single-channel grayscale masks ↩