Skip to content

Commit

Permalink
add far/near field + isvalid
Browse files Browse the repository at this point in the history
+ made reprojection optional
  • Loading branch information
cabanier committed Feb 4, 2025
1 parent ceec341 commit 106de44
Showing 1 changed file with 32 additions and 11 deletions.
43 changes: 32 additions & 11 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -185,23 +185,24 @@ The following table summarizes the ways various data formats can be consumed:
<tr>
<td>{{XRDepthDataFormat/"luminance-alpha"}}</td>
<td>[=GLenum/LUMINANCE_ALPHA=]</td>
<td>2 times 8 bit</dt>
<td>2 times 8 bit</td>
<td>Interpret {{XRCPUDepthInformation/data}} as {{Uint16Array}}</td>
<td>Inspect Luminance and Alpha channels to reassemble single value.</td>
</tr>
<tr>
<td>{{XRDepthDataFormat/"float32"}}</td>
<td>[=GLenum/R32F=]</td>
<td>32 bit</dt>
<td>32 bit</td>
<td>Interpret {{XRCPUDepthInformation/data}} as {{Float32Array}}</td>
<td>Inspect Red channel and use the value.</td>
</tr>
<tr>
<td>{{XRDepthDataFormat/"unsigned-short"}}</td>
<td>[=GLenum/R16UI=]</td>
<td>16 bit</dt>
<td>16 bit</td>
<td>Interpret {{XRCPUDepthInformation/data}} as {{Uint16Array}}</td>
<td>Inspect Red channel and use the value.</td>
<td>Inspect Red channel and use the
value.</td>
</tr>
</tbody>
</table>
Expand All @@ -213,13 +214,18 @@ Session configuration {#session-configuration}
dictionary XRDepthStateInit {
required sequence<XRDepthUsage> usagePreference;
required sequence<XRDepthDataFormat> dataFormatPreference;
boolean matchDepthView = true;
};
</script>

The {{XRDepthStateInit/usagePreference}} is an ordered sequence of {{XRDepthUsage}}s, used to describe the desired depth sensing usage for the session.

The {{XRDepthStateInit/dataFormatPreference}} is an ordered sequence of {{XRDepthDataFormat}}s, used to describe the desired depth sensing data format for the session.

The {{XRDepthStateInit/matchDepthView}} requests that {{XRDepthInformation/view}} of the depth information must be in sync with the {{XRView}}. If this is <code>true</code>, the {{XRSystem}} SHOULD return depth information that reflects the current frame. If this is <code>false</code>, the {{XRSystem}} MAY return depth information that was captured at an earlier point in time.

NOTE: If {{XRDepthStateInit/matchDepthView}} is <code>false</code>, the author should do the reprojection using the [=XRDepthInformation/view=] from {{XRDepthInformation}}.

The {{XRSessionInit}} dictionary is expanded by adding new {{XRSessionInit/depthSensing}} key. The key is optional in {{XRSessionInit}}, but it MUST be provided when [=depth-sensing=] is included in either {{XRSessionInit/requiredFeatures}} or {{XRSessionInit/optionalFeatures}}.

<script type="idl">
Expand Down Expand Up @@ -308,6 +314,10 @@ interface XRDepthInformation {
[SameObject] readonly attribute XRRigidTransform normDepthBufferFromNormView;
readonly attribute float rawValueToMeters;
readonly attribute XRView? view;

readonly attribute boolean isValid;
readonly attribute float depthNear;
readonly attribute float depthFar;
};
</script>

Expand All @@ -321,9 +331,11 @@ Note: if the applications intend to use the resulting depth buffer for texturing

The {{XRDepthInformation/rawValueToMeters}} attribute contains the scale factor by which the raw depth values from a [=XRDepthInformation/depth buffer=] must be multiplied in order to get the depth in meters.

The optional {{XRDepthInformation/view}} attribute contains the {{XRView}} that was active when the {{XRSystem}} calculated the {{XRDepthInformation}}. This attribute MAY be used by experiences to better align with the real world. If the {{XRDepthInformation/view}} is not provided, the user MUST assume it is the same as the one from the current {{XRFrame}}'s {{XRViewerPose}}.
The {{XRDepthInformation/depthNear}}, {{XRDepthInformation/depthFar}} and optional {{XRDepthInformation/view}} attribute contain the near and far field and the {{XRView}} respectively that were active when the {{XRSystem}} calculated the {{XRDepthInformation}}. This attribute MAY be used by experiences to better align with the real world. If the {{XRDepthInformation/view}} is not provided, the user MUST assume it is the same as the one from the current {{XRFrame}}'s {{XRViewerPose}}.

The {{XRDepthInformation/isValid}} attribute is set to <code>true</code> if the {{XRSystem}} was able to generate depth information for the current frame. It is set to <code>false</code> otherwise.

Each {{XRDepthInformation}} has an associated <dfn for=XRDepthInformation>view</dfn> that stores {{XRView}} from which the depth information instance was created.
Each {{XRDepthInformation}} has an associated <dfn for=XRDepthInformation>view</dfn> that reflects the {{XRView}} from which the depth information instance was created.

Each {{XRDepthInformation}} has an associated <dfn for=XRDepthInformation>depth buffer</dfn> that contains depth buffer data. Different {{XRDepthInformation}}s may store objects of different concrete types in the depth buffer.

Expand Down Expand Up @@ -503,18 +515,28 @@ When {{XRWebGLBinding/getDepthInformation(view)}} method is invoked on a {{XRWeb

In order to <dfn>create a WebGL depth information instance</dfn> given {{XRFrame}} |frame| and {{XRView}} |view|, the user agent MUST run the following steps:
1. Let |result| be a new instance of {{XRWebGLDepthInformation}}.
1. Let |time| be |frame|'s [=XRFrame/time=].
1. Initialize |time| as follows:
<dl class="switch">
<dt> If the {{XRSession}} was created with {{XRDepthStateInit/matchDepthView}} set to <code>true</code>:
<dd> Let |time| be |frame|'s [=XRFrame/time=].
<dt> Otherwise
<dd> Let |time| be time that the |device| captured the depth information.
</dl>
1. Let |session| be |frame|'s {{XRFrame/session}}.
1. Let |device| be the |session|'s [=XRSession/XR device=].
1. Let |nativeDepthInformation| be a result of querying |device|'s [=native depth sensing=] for the depth information valid as of |time|, for specified |view|, taking into account |session|'s {{XRSession/depthUsage}} and {{XRSession/depthDataFormat}}.
1. If |nativeDepthInformation| is <code>null</code>, return <code>null</code> and abort these steps.
1. If the depth buffer present in |nativeDepthInformation| meets user agent's criteria to [=block access=] to the depth data, return <code>null</code> and abort these steps.
1. Initialize |result|'s {{XRDepthInformation/isValid}} to <code>false</code>.
1. If |nativeDepthInformation| is <code>null</code>, return |result| and abort these steps.
1. If the depth buffer present in |nativeDepthInformation| meets user agent's criteria to [=block access=] to the depth data, return |result| and abort these steps.
1. If the depth buffer present in |nativeDepthInformation| meets user agent's criteria to [=limit the amount of information=] available in depth buffer, adjust the depth buffer accordingly.
1. Set |result|'s {{XRDepthInformation/isValid}} to <code>true</code>.
1. Initialize |result|'s {{XRDepthInformation/width}} to the width of the depth buffer returned in |nativeDepthInformation|.
1. Initialize |result|'s {{XRDepthInformation/height}} to the height of the depth buffer returned in |nativeDepthInformation|.
1. Initialize |result|'s {{XRDepthInformation/normDepthBufferFromNormView}} to a new {{XRRigidTransform}}, based on |nativeDepthInformation|'s [=depth coordinates transformation matrix=].
1. Initialize |result|'s {{XRWebGLDepthInformation/texture}} to an [=opaque texture=] containing the depth buffer returned in |nativeDepthInformation|.
1. Initialize |result|'s [=XRDepthInformation/view=] to |view|.
1. Initialize |result|'s {{XRDepthInformation/view}} to the {{XRView}} captured at |time|.
1. Initialize |result|'s {{XRDepthInformation/depthNear}} to the |device|'s [=native depth sensing=] near clip plane at |time|.
1. Initialize |result|'s {{XRDepthInformation/depthFar}} to the |device|'s [=native depth sensing=] far clip plane at |time|.
1. Initialize |result|'s {{XRWebGLDepthInformation/textureType}} as follows:
<dl class="switch">
<dt> If the |result|'s {{XRWebGLDepthInformation/texture}} was created with a textureType of [=XRTextureType/texture-array=]:
Expand All @@ -530,7 +552,6 @@ In order to <dfn>create a WebGL depth information instance</dfn> given {{XRFrame
<dd> Initialize |result|'s {{XRWebGLDepthInformation/imageIndex}} to <code>1</code>.
<dt> Otherwise
<dd> Initialize |result|'s {{XRWebGLDepthInformation/imageIndex}} to <code>0</code>.
</dl>
</dl>
1. Return |result|.

Expand Down

0 comments on commit 106de44

Please sign in to comment.