Skip to content

Web: the canvas is opaque, so a page-level background (three.js, CSS) can't sit behind the app #3014

Done

Description

@kebab-casee

What

A Rune web app always paints an opaque canvas, so a page-level background can't sit behind the UI. Dashboards that want a live backdrop (three.js scene, CSS gradient, video) have nowhere to put it: the canvas covers the viewport and clear_color() clears to the theme background.

On native this is already possible with WindowOptions { transparent: true, .. }. On wasm there is no equivalent, and RuntimeCore::transparent is never set, so the web clear is opaque even when the root element has no fill.

What works today

We pinned Rune at 8705dbea and carry a two-file patch. It makes the canvas transparent so a three.js canvas behind it shows through:

  1. crates/rune/src/platform/web/gpu.rs ΓÇö in canvas_config, pick the premultiplied alpha mode when the adapter offers it:
if caps
    .alpha_modes
    .contains(&wgpu::CompositeAlphaMode::PreMultiplied)
{
    config.alpha_mode = wgpu::CompositeAlphaMode::PreMultiplied;
}
  1. crates/rune/src/runtime/paint/blend.rs ΓÇö treat wasm like a transparent window, so the clear is [0, 0, 0, 0] when the app's root has no opaque fill:
if self.transparent || cfg!(target_arch = "wasm32") {

Verification

  • Chrome 158, WebGPU: the app canvas reports rgba(0, 0, 0, 0); a <canvas> at z-index: 0 with a three.js scene is visible behind the Rune UI.
  • Android Chrome, WebGL2: same (fallback path), with the WebGL2 glyph caveat below.
  • Opaque root fills still paint over the background, so existing apps that fill their root are unchanged.
  • No console errors; the a11y mirror, pointer and keyboard input are unaffected.

Proposal

Rather than always-transparent, expose it explicitly, the way native does:

  • honor WindowOptions { transparent: true } on wasm (set RuntimeCore::transparent when the window is created), or
  • add App::transparent(bool) / an AppSpec field, documented as "the page behind must paint something".

The two-line behaviour above is the implementation we'd expect; the remaining work is turning it on deliberately and documenting the CPU-first handover (the CPU canvas still paints the theme background for the first frames).

Caveats

  • We only tested WebGPU and WebGL2 on Chrome/Android; Safari and WebGL1 are untested.
  • With a transparent canvas the browser composites every frame over the page, which may matter for battery on mobile; an opt-in flag lets apps choose.
  • The WebGL2 path has an unrelated Android bug we hit: text inside cards renders with missing glyphs. Skipping image textures did not fix it, so it is not an atlas/texture interaction. Filed as Web (Android, WebGL2): text inside card elements renders with missing glyphs #3015.

Happy to open a PR with the alpha-mode change, the clear change and a doc note if this shape is acceptable.

Activity

  1. opencodejr commented on Dec 1, 2026

    @opencodejr
    Contributor

    the web host ignored WindowOptions::transparent, so RuntimeCore::transparent stayed false, webgpu stayed on CompositeAlphaMode::Opaque, and the cpu-first 2d canvas used alpha: false. App::window_options(WindowOptions { transparent: true, ..Default::default() }) now enables transparent clears ([0, 0, 0, 0]), picks CompositeAlphaMode::PreMultiplied on webgpu when offered (while keeping webgl2's premultiplied alpha canvas compatible with wgpu-hal), and enables alpha with straight-rgba unpremultiplication on the cpu 2d canvas across startup, handover, and fallback; opaque apps are unchanged. web code was only compiled and unit-tested on headless linux without a browser or real window, so please confirm on the new commit.

    Fixed in #3026.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions