Layer masks
A layer mask is a grayscale RGBA buffer where the luminance of each pixel controls the visibility of the corresponding pixel in the layer. White pixels (255, 255, 255) are fully visible, black pixels (0, 0, 0) are fully hidden, and gray values create partial transparency.Setting a layer mask
Inverted masks
You can invert the mask luminance so that black = visible and white = hidden:Removing a mask
Checking for masks
Clipping masks
A clipping mask constrains a layer’s visibility to the alpha channel of the layer directly below it. This is useful for adding textures, patterns, or colors that conform to the shape of another layer.Using clipping masks
Stacking clipping masks
You can stack multiple layers that all clip to the same base layer:Mask internals
Layer masks are stored as optionalImageBuffer fields in LayerCommon (see ~/workspace/source/crates/kimg-core/src/layer.rs:88-112):
- Layer masks are applied by multiplying the layer’s alpha channel with the mask’s luminance
- Inverted masks flip the luminance values before applying
- Clipping masks multiply the layer’s alpha with the alpha of the layer below
render/clipped_layer_stack/512: 18.40 msrender/masked_layer_stack/512: 10.59 ms