Upstream: crates/rune/README.md § Isolated opacity at 65f8eb43f710, MIT © Anomaly. Bundled by build-rune-apps; links point at this snapshot or at GitHub at that rev.

Isolated opacity

Fading containers render their subtree into a bounded, pooled target, then apply opacity once. Overlapping opaque children in a 0.5 group therefore have 0.5 coverage everywhere. Nested groups compose inside-out. Opaque containers and individual leaves retain the direct instance path; zero-opacity subtrees emit no draws. live_opacity updates this without a view rebuild or layout. Targets use 64-pixel buckets, reused while they fit and occupy at most twice the needed area (with a minimum-bucket floor), and are released at either endpoint. Projection and viewport cover only the used rectangle. Static translucent containers also cost a target and pass each presentation; target resources and planning capacity are reused, but contents are redrawn.

For static disabled styling, El::dim(alpha) distributes a fixed alpha to each element's own paint in the built subtree, including fills, strokes, text, icons, images and native surfaces. Call it after adding children. It neither changes inherited/hit-test opacity nor introduces layers. Rune-kit uses this for disabled controls; normal container opacity still isolates. A dimmed box with a solid fill fades as CSS opacity fades it: its outer shadows stay outside it, and its fill and gradient fade as one. Content drawn over it (a label, an icon) still fades on its own, so it shows a little of the faded fill through it where a layer would not.

The manual kit-gallery disabled_controls_gpu_cost benchmark measures the whole GPU frame for disabled controls: leaf dimming allocates no layer targets or passes and matches a flat reference, where container opacity would cost one isolated target per control.

Low-level compositors can use Instance::begin_layer(bounds, clip, LayerSpec { opacity, ..Default::default() }) and Instance::end_layer(). Bounds are device-pixel [x,y,w,h]; include native surfaces and the full travel of any retained GPU translations. Primitive/shadow bounds expand this rectangle, and the result is clipped to the viewport. Scope records retain absolute instance indices, including before_instance video insertions and GPU-spring IDs. List and range boundaries must preserve balanced scopes; filtering individual glyphs out of a scope is not a valid partition. Call encode_layers after image/surface preparation and before opening passes using draw_range. draw, draw_timed, and Frame::draw_ui do this automatically. layer_stats exposes target bytes, allocations and extra passes; draw_timed includes the layer passes in its interval. The lab demo's custom lighting/effect graph still uses its previous flattened-opacity semantics; its adapter consumes scope records before splitting glyphs, backgrounds and effect anchors. Full isolation across that custom graph requires applying opacity after its lighting/effect passes.

The default blend remains source-over: B at 1-t over A at t has alpha 1-t+t², not 1. For full-state crossfades, opt into additive composition with a dissolve container:

el().dissolve()
    .child(state_a.opacity(1.0 - t))
    .child(state_b.opacity(t)) // position the states over the same rectangle

El::dissolve() keeps the parent isolated even at opacity 1, composites each child's subtree internally with source-over, then adds the states with premultiplied One/One blending. Two opaque states give alpha 1 and their exact linear colour average at t = .5. A single-draw state can fold directly into the additive pass. Shared backgrounds belong outside this scope; the container's own paint also participates in addition. Normal opacity/Live bindings control the weights. Hit testing still uses effective opacity.

The low-level equivalent is LayerSpec { blend: Blend::PlusLighter, ..Default::default() }. Its direct primitives and native surfaces add; wrap each multi-draw state in a normal child scope, including at opacity 1. The completed dissolve clamps its premultiplied result before applying its own opacity, then uses its parent's blend (normally source-over) on the backdrop.

The headless GPU path uses the same layers as windows. The rune-ref replay format currently covers only flat primitive kinds 0–4 and rejects layer records; it cannot yet replay a grouped scene. Layer pixel tests use an independent scalar premultiplied source-over oracle. Existing flat reference scenes retain their original semantics and hashes.