Notes on alpha

The AR Spec contains a concept of environment blend mode. Some XR devices use a pass-through camera and manually composite the scene with the real world using source-over blending, which is the alpha-blend mode. Others use additive light displays and directly display the buffers, using lighter blending, which is the additive mode. opaque is used for VR displays with no capabilities of showing the real world.


enum XREnvironmentBlendMode {
  "opaque",
  "alpha-blend",
  "additive"
};



There have been some long discussions about the exact semantics of the additive mode (#14). The initial spec text mentioned that alpha values are ignored in additive mode displays. This isn’t quite correct, the existing additive light displays simply assume premultiplied alpha, which may also be true of the larger spec.

While the initial issue with the AR spec text has been resolved, there’s still a lot of ambiguity around this, and we have issues filed.


Firstly, we need to figure out the core spec’s position on premultiplied alpha (#837, #838, draft fix at #840). Currently, XRWebGLLayerInit allows for setting multiple context options like the existence of a depth/stencil buffer or alpha channel, but the premultipliedAlpha option that WebGL supports is absent.

We have a couple options:

  • Continue not having this option. Specify that the XR compositor will assume that all buffers with alpha have premultiplied alpha. Draft PR in #840
  • This leaves the door open for future changes
  • If we do this, we need to figure out what to do when a WebGL context with premultipliedAlpha: false is used (#837).
  • either we claim that those parameters only apply to the default framebuffer used in the canvas, and WebXR’s buffer uses the parameters from XRWebGLLayerInit.
  • or we treat this as an error/warning case
  • Add a premultipliedAlpha parameter to XRWebGLLayerInit which defaults to true.
  • This is more symmetric, and allows users more freedom
  • It’s unclear if people actually want this functionality.



Secondly, we need to figure out what blend mode additive light AR devices should report in immersive-vr mode, should they choose to support it (#16)

The core conflict is that reporting opaque isn’t accurate, however if we report “additive” we may encourage people to use immersive-vr for AR experiences. This disadvantages AR devices that choose to not support immersive-vr, as well as creating content that appears to work, but works suboptimally on VR devices.


(Ask everyone to read Nell’s toplevel comment)

There is also one smaller issue that spun out of the discussions had on the AR spec:

  • #17: Should we allow XRWebGLLayers to be created for alpha-blend AR sessions without an alpha channel?