Depth peeling OIT renders nothing on NVIDIA + ANGLE (OpenGL ES backend): `oitDepthSampler` is sampled at lowp/fp16 precision

Babylon.js version: 9.30.0 (WebGL2)

Playground Repro: https://playground.babylonjs.com/#LV2FI4#1

Environment:

  • GPU: NVIDIA GeForce RTX 5070 Ti
  • OS: Ubuntu 26.04, Wayland
  • Browser: Chrome, renderer string ANGLE (NVIDIA Corporation, NVIDIA GeForce RTX 5070 Ti/PCIe/SSE2, OpenGL ES 3.2) (Chrome’s default on Linux Wayland)
  • No WebGL errors, shaders compile, every extension needed is present (EXT_color_buffer_float, EXT_float_blend, OES_texture_float_linear)

Symptom:
With scene.useOrderIndependentTransparency = true, every transparent mesh disappears. A 50% alpha red quad over black reads back as (0,0,0) instead of ~(128,0,0). The same code works in SwiftShader and on other platforms.

Repro:

const scene = new BABYLON.Scene(engine);
scene.clearColor = new BABYLON.Color4(0, 0, 0, 1);
const camera = new BABYLON.FreeCamera("cam", new BABYLON.Vector3(0, 0, -3), scene);
camera.setTarget(BABYLON.Vector3.Zero());
const quad = BABYLON.MeshBuilder.CreatePlane("quad", { size: 4 }, scene);
const mat = new BABYLON.StandardMaterial("m", scene);
mat.disableLighting = true;
mat.emissiveColor = new BABYLON.Color3(1, 0, 0);
mat.alpha = 0.5;
mat.backFaceCulling = false;
quad.material = mat;
scene.useOrderIndependentTransparency = true;
// Expected: dark red quad. Actual on NVIDIA/ANGLE-GLES: nothing is drawn.

Investigation:
I traced the depth peeling ping-pong textures pass by pass:

  • The first depth pass writes depth0 correctly: (-0.66673, 0.66673).
  • In the first peel pass every fragment takes the early return in oitFragment, so nothing reaches frontColor.

I then patched oitFragment to output (fragDepth - nearestDepth) * 1e6. On this machine it reads 229.4. The fragment depth is 0.6667334 (near 1, far 10000, distance 3). Rounded to fp16 that is 0.6665039, which is exactly 229.4e-6 lower. So texelFetch(oitDepthSampler, ...) returns the stored RG32F depth rounded to half precision. The exact comparisons fragDepth < nearestDepth || fragDepth > furthestDepth then reject every fragment.

Cause:
oitDeclaration declares uniform sampler2D oitDepthSampler; with no precision qualifier. Babylon’s shader processor only prepends precision highp float;, and in GLSL ES 3.00 the default precision of sampler2D is lowp. Most drivers ignore this. NVIDIA’s native GLES driver (used by ANGLE’s GL ES backend) honours it and returns fp16-precision texels.

Fix (verified on the machine above):
In oitDeclaration (GLSL), declare the depth sampler highp:

uniform highp sampler2D oitDepthSampler;

With only this change, OIT renders correctly on this machine. It should be harmless everywhere else, since it is already the effective behaviour on drivers that ignore precision qualifiers. It might be worth adding precision highp sampler2D; to the default precision header generally, since other float-texture lookups could hit the same issue.

Workaround for anyone affected, run before any OIT shader compiles:

const store = BABYLON.ShaderStore.IncludesShadersStore;
store.oitDeclaration = store.oitDeclaration.replace(
  "uniform sampler2D oitDepthSampler;",
  "uniform highp sampler2D oitDepthSampler;");

Separately, a small note: with OIT on, the prepass and peeling targets are not multisampled, so canvas MSAA no longer applies (the existing TODO in DepthPeelingRenderer). We added FXAA while OIT is active as a workaround.

cc @Evgeni_Popov

Thanks for the detailed investigation and for verifying the fix!

You’re right: precision highp float; doesn’t set sampler precision, and the depth-peeling comparisons require sufficient precision in the fetched depth values.

I’ve opened a PR applying your fix:

uniform highp sampler2D oitDepthSampler;

I’ve kept this scoped to the OIT depth sampler rather than changing sampler defaults engine-wide.

Regarding MSAA, that’s a separate limitation of the current OIT implementation. FXAA is a reasonable workaround while OIT is enabled.