Skip to content

Commit

Permalink
[WebXR] Implement clipping planes clamping
Browse files Browse the repository at this point in the history
The WebXR specs specify[1] that user agents should enforce a minimum near clip plane and a maximum far clip plane. In particular they
must not be negative.

[1] https://immersive-web.github.io/webxr/#minimum-near-clip-plane

WPT test

Change-Id: Ib9c7dbbd524d24e657ea85f9bb9208bfc80a6aef
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5185618
Commit-Queue: Sergio Villar <[email protected]>
Reviewed-by: Alexander Cooper <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1252767}
  • Loading branch information
svillar authored and chromium-wpt-export-bot committed Jan 26, 2024
1 parent 0c4d2cc commit 014486a
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions webxr/render_state_update.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,40 @@
});
};

let testMinMaxClippingPlanes = function(session, fakeDeviceController, t, sessionObjects) {
return new Promise((resolve, reject) => {
let gl = sessionObjects.gl;
gl.makeXRCompatible().then(() => {
t.step(() => {
let near = 0.2;
let far = 0.8;
let layer = new XRWebGLLayer(session, gl);
session.updateRenderState({ depthNear: near, depthFar: far, baseLayer: layer });
assert_not_equals(session.renderState.depthNear, near);
assert_not_equals(session.renderState.depthFar, far);
assert_not_equals(session.renderState.baseLayer, layer);
session.requestAnimationFrame((time, xrFrame) => {
t.step(() => {
assert_equals(session.renderState.depthNear, near);
assert_equals(session.renderState.depthFar, far);
// Clamp negative values
near = -20.3;
far = -1.5;
session.updateRenderState({ depthNear: near, depthFar: far });
session.requestAnimationFrame((time, xrFrame) => {
t.step(() => {
assert_equals(session.renderState.depthNear, 0.0);
assert_equals(session.renderState.depthFar, 0.0);
resolve();
});
});
});
});
});
});
});
};

let testName = "updateRenderState handles appropriately ended sessions";
xr_session_promise_test(testName, testSessionEnded, fakeDeviceInitParams, 'immersive-vr');

Expand All @@ -92,4 +126,7 @@
testName = "updateRenderState handles appropriately XRRenderStateInit params";
xr_session_promise_test(testName, testParams, fakeDeviceInitParams, 'inline');

testName = "updateRenderState clamps appropriately near/far clipping planes";
xr_session_promise_test(testName, testMinMaxClippingPlanes, fakeDeviceInitParams, 'immersive-vr');

</script>

0 comments on commit 014486a

Please sign in to comment.