-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Sprite masks #10169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Sprite masks #10169
Conversation
Welcome, new contributor! Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨ |
The generated |
My first thought is that this should be implemented like alpha mask for 3D. But, if you want to do masking of transparent materials separate to its transparency, then a different method is needed indeed. |
@colinjneville can you resolve merge conflicts? I'd like to wrangle review effort for 0.13 |
Making this up for adoption, after some discussion on Discord. |
triage: Still up for adoption, no change |
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 ↩