WebXR 深度センシングモジュール

W3C 作業草案,

この文書の詳細
このバージョン:
https://www.w3.org/TR/2025/WD-webxr-depth-sensing-1-20251210/
最新公開バージョン:
https://www.w3.org/TR/webxr-depth-sensing-1/
編集者草案:
https://immersive-web.github.io/depth-sensing/
以前のバージョン:
履歴:
https://www.w3.org/standards/history/webxr-depth-sensing-1/
フィードバック:
GitHub
編集者:
(Google)
元編集者:
(Google)
参加方法:
課題を提出する (未解決の課題)
メーリングリストアーカイブ
W3C の #immersive-web IRC

概要

Depth Sensing API は、WebXR Device API の機能を拡張するモジュールです。これは、より没入感のある体験を 提供するために、対応する XR デバイスによって計算された深度情報をアプリが取得できるようにします。Depth Sensing API のユースケース例には、仮想オブジェクトと現実世界との物理的相互作用のシミュレーション、オクルージョン、および ユーザー環境に対する認識の向上を利用できる非視覚的アプリケーションが含まれます(ただし、これらに限定されません)。

この文書のステータス

この節では、公開時点におけるこの文書のステータスを説明します。現在の W3C 公開物の一覧と、この技術報告書の最新改訂版は、 W3C 標準および草案索引で確認できます。

Immersive Web Working Group は、グループがまだ対処していない すべてのバグ報告の一覧を管理しています。この草案は、作業部会でまだ議論されるべき保留中の課題の一部を 強調しています。これらの課題の結果については、それらが有効であるかどうかを含め、まだ決定されていません。 未解決の課題に対する仕様テキスト案を含む pull request が強く推奨されます。

この文書は、Immersive Web Working Group によって、Recommendation track を用いた Working Draft として公開されました。この文書は W3C Recommendation になることを意図しています。

Working Draft としての公開は、 W3C およびそのメンバーによる承認を意味するものではありません。 これは草案文書であり、いつでも他の文書によって更新、置換、または廃止される可能性があります。この文書を 作業中のもの以外として引用することは不適切です。

この文書は、 W3C Patent Policy の下で活動するグループによって作成されました。 W3C は、このグループの成果物に関連して行われた特許開示の公開一覧を 管理しています。そのページには、特許を開示するための手順も含まれています。個人が、その個人が Essential Claim(s) を含むと考える特許について実際の知識を有する場合、その情報を W3C Patent Policy の 第 6 節に従って開示しなければなりません。

この文書は、2025年8月18日 W3C Process Document によって管理されます。

1. 序論

Virtual Reality と Augmented Reality がより普及するにつれて、ユーザーがいる環境について より詳細な情報にアクセスできる新機能が native APIs によって導入されています。Depth Sensing API は、 そのような機能の 1 つを WebXR Device API にもたらし、WebXR を利用した体験の作者が、 ユーザーのデバイスからユーザー環境内の現実世界の geometry までの距離に関する情報を取得できるようにします。

この文書は、WebXR Device API および WebXR Augmented Reality Module 仕様に読者が精通していることを前提としています。これは、それらの上に構築され、 XRSessions に追加機能を提供するためです。

1.1. 用語

この文書では、AR という略語を Augmented Reality を表すものとして、VR を Virtual Reality を表すものとして使用します。

この文書では、XR device によって返されるか、API 自体によって返される、深度情報を含む byte 配列を指す場合に、 "depth buffer"、"depth buffer data" および "depth data" のような用語を同じ意味で使用します。 depth buffer の具体的な内容についての詳細は、仕様の data および texture entries で確認できます。

この文書では、view の左上隅を原点とし、X 軸が右方向に増加し、Y 軸が下方向に増加する座標系を指す場合に、 normalized view coordinates という用語を使用します。

2. 初期化

2.1. Feature descriptor

アプリケーションは、適切な feature descriptor を渡すことで、XRSession で depth sensing を有効にするよう要求できます。 このモジュールは、depth sensing feature の新しい有効な feature descriptor として、新しい文字列 - depth-sensing を導入します。

デバイスが native depth sensing capability を公開している場合、そのデバイスは depth sensing feature を capable of supporting とされます。inline XR device は、depth sensing feature を capable of supporting として扱ってはなりません。

depth sensing feature は feature policy の対象であり、 要求元文書の origin で "xr-spatial-tracking" policy が許可されている必要があります。

2.2. 意図される depth type、data usage、および data formats

enum XRDepthType {
  "raw",
  "smooth",
};
enum XRDepthUsage {
  "cpu-optimized",
  "gpu-optimized",
};
enum XRDepthDataFormat {
  "luminance-alpha",
  "float32",
  "unsigned-short",
};

次の表は、さまざまな data formats を利用できる方法を要約します:

Data format GLenum value equivalent Depth buffer entry のサイズ CPU での使用 GPU での使用
"luminance-alpha" LUMINANCE_ALPHA 2 times 8 bit dataUint16Array として解釈する Luminance および Alpha channels を調べ、単一の値を再構成する。
"float32" R32F 32 bit dataFloat32Array として解釈する Red channel を調べ、その値を使用する。
"unsigned-short" R16UI 16 bit dataUint16Array として解釈する Red channel を調べ、その値を使用する。

2.3. Session configuration

dictionary XRDepthStateInit {
  required sequence<XRDepthUsage> usagePreference;
  required sequence<XRDepthDataFormat> dataFormatPreference;
  sequence<XRDepthType> depthTypeRequest;
  boolean matchDepthView = true;
};

usagePreference は、session に望まれる depth sensing usage を記述するために使用される、XRDepthUsage の ordered sequence です。

dataFormatPreference は、session に望まれる depth sensing data format を記述するために使用される、XRDepthDataFormat の ordered sequence です。

depthTypeRequest は、session に望まれる depth sensing type を記述するために使用される、XRDepthType の ordered sequence です。この要求はユーザーエージェントによって無視されてもよいです。

matchDepthView は、depth information の viewXRView と揃っていなければならないことを要求します。 これが true の場合、XRSystem は current frame を反映する depth information を返すべきです。これが false の場合、XRSystem は earlier point in time で capture された depth information を返してもよいです。

注: matchDepthViewfalse の場合、作者は XRDepthInformation からの view を使用して reprojection を行うべきです。

XRSessionInit dictionary は、新しい depthSensing key を追加することで拡張されます。この key は XRSessionInit では optional ですが、depth-sensingrequiredFeatures または optionalFeatures のいずれかに含まれる場合は、提供されなければなりません。

partial dictionary XRSessionInit {
  XRDepthStateInit depthSensing;
};

depth sensing feature が required feature であるにもかかわらず、application が depthSensing key を提供しなかった場合、ユーザーエージェントはこれを unresolved required feature として扱い、requestSession(mode, options) promise を NotSupportedError で reject しなければなりません。 optional feature として要求された場合、ユーザーエージェントはその feature request を無視し、新しく作成された session で depth sensing を有効にしてはなりません。

depth sensing feature が required feature であるにもかかわらず、XRDepthStateInit を用いて呼び出された finding supported configuration combination algorithm の結果が null である場合、ユーザーエージェントはこれを unresolved required feature として扱い、requestSession(mode, options) promise を NotSupportedError で reject しなければなりません。 optional feature として要求された場合、ユーザーエージェントはその feature request を無視し、新しく作成された session で depth sensing を有効にしてはなりません。

XRSession が depth sensing を有効にして作成された場合、depthUsagedepthDataFormat、 および depthType attributes は、XRDepthStateInit を用いて呼び出された finding supported configuration combination algorithm の結果に設定されなければなりません。 depthActivetrue を既定値としなければなりません。

注: この algorithm の意図は、 preferences を最も制約の強いものから最も制約の弱いものへ処理することです。したがって、単一の item のみが示されている場合から items の処理を開始し、その後 multiple、最後に preference が示されていない場合を処理します。

depthStateInit dictionary が与えられた depth sensing API について find supported configuration combination するために、 ユーザーエージェントは次の algorithm を実行しなければなりません:
  1. depthStateInitdepthTypeRequest key が設定されている場合はそれに含まれる値を、そうでない場合は空の sequence を depthTypeRequest とします。

  2. selectedTypenull とします

  3. depthStateInit 内の usagePreference key に含まれる値を usagePreference とします

  4. selectedUsagenull とします。

  5. depthStateInit 内の dataFormatPreference key に含まれる値を dataFormatPreference とします

  6. selectedDataFormatnull とします。

  7. processingOrder を、(preferences, selection) pairs の sequence とします。ここで selection は前の手順で導入された variables の 1 つへの reference です: [(depthTypeRequest, selectedType), (usagePreference,selectedUsage),(dataFormatPreference,selectedDataFormat)]

  8. processingOrder 内の各 (preferences, selection) について、 次の手順を実行します

    1. preferences が単一の値のみを含む場合、selection をその値に設定します。

  9. processingOrder 内の各 (preferences, selection) について、 次の手順を実行します:

    1. selectionnull でない場合、次の entry に進みます。

    2. preferences sequence が空の場合、次の entry に進みます。

    3. preferences 内の各 preference について、次の手順を実行します:

    4. selectedType,selectedUsage,selectedDataFormat の他の値を伴う preference が、device の native depth sensing capabilities によって supported depth sensing configuration と見なされない場合、次の entry に進みます。

    5. selectionpreference に設定し、これらの nested steps を中止します。

  10. processingOrder 内の各 (preferences, selection) について、 次の手順を実行します:

    1. selectionnull でない場合、次の entry に進みます。

    2. selection を、selectedType,selectedUsage,selectedDataFormat の他の値を伴う preferred native depth sensing capability によって決定される値に設定します。

  11. selectedType,selectedUsage,selectedDataFormat のいずれかが null の場合、null を返し、これらの手順を中止します。

  12. selectedType,selectedUsage,selectedDataFormat が device の native depth sensing capabilities によって supported depth sensing configuration と見なされる場合、 selectedType,selectedUsage,selectedDataFormatdepth sensing configuration を返し、これらの 手順を中止します。

  13. depthTypeRequest が空の list でない場合、それを空の list に設定し、これらの手順を繰り返します。

  14. null を返し、これらの手順を中止します。

注: user agents は usages と data formats の 既存のすべての組み合わせをサポートする必要はありません。これは、それらが効率的な方法で data を提供できるようにすることを 意図しており、underlying platforms に依存します。この決定は application developers に追加の負担を課しますが、 API complexity を隠す libraries の作成により、performance を犠牲にする可能性はあるものの、軽減できる可能性があります。

depth sensing API を capable of supporting なユーザーエージェントは、少なくとも 1 つの XRDepthUsage mode をサポートしなければなりません。depth sensing API を capable of supporting なユーザーエージェントは "luminance-alpha" data format をサポートしなければならず、他の formats をサポートしてもよいです。

次の code は、depth sensing API を必要とする session をどのように要求できるかを示します。この example は、呼び出し元が CPU-optimized usage と GPU-optimized usage の両方、および "luminance-alpha" と "float32" formats の両方を扱うことができ、CPU と "luminance-alpha" を優先することを前提としています:
const session = await navigator.xr.requestSession("immersive-ar", {
  requiredFeatures: ["depth-sensing"],
  depthSensing: {
    usagePreference: ["cpu-optimized", "gpu-optimized"],
    dataFormatPreference: ["luminance-alpha", "float32"],
  },
});
partial interface XRSession {
  readonly attribute XRDepthUsage depthUsage;
  readonly attribute XRDepthDataFormat depthDataFormat;
  readonly attribute XRDepthType? depthType;
  readonly attribute boolean? depthActive;

  undefined pauseDepthSensing();
  undefined resumeDepthSensing();
};

depthUsage は、session が設定された depth sensing usage を記述します。この属性が depth sensing を有効にしていない session でアクセスされた場合、ユーザーエージェントは InvalidStateError を投げなければなりません。

depthDataFormat は、session が設定された depth sensing data format を記述します。この属性が depth sensing を有効にしていない session でアクセスされた場合、ユーザーエージェントは InvalidStateError を投げなければなりません。

depthType は、session が設定された depth sensing type を記述します。この属性が depth sensing を有効にしていない session でアクセスされた場合、ユーザーエージェントは InvalidStateError を投げなければなりません。 runtime が単一の XRDepthType のみをサポートしている場合、または depthTypeRequest を別の理由で無視した場合、これは null を返すことがあります。

depthActive は現在の depth sensing active state を返します。この属性が depth sensing を有効にしていない session でアクセスされた場合、ユーザーエージェントは InvalidStateError を投げなければなりません。 この値が false の場合、ユーザーエージェントは depth data を取得する試みを reject しなければなりません。 この値が true の場合、ユーザーエージェントは有効な depth data または null を返してもよいです。

resumeDepthSensing()XRSession session 上で呼び出されたとき、User Agent は次の手順を実行しなければなりません:

  1. sessionended 値が true の場合、InvalidStateError を投げ、これらの手順を中止します。

  2. sessionanimation frameframe とします。

  3. frameactive boolean が false の場合、InvalidStateError を投げ、これらの手順を中止します。

  4. depth-sensing feature descriptor が、sessionXR device の、sessionmode に対する list of enabled featurescontained されていない場合、NotSupportedError投げ、 これらの手順を中止します。

  5. depth sensing active statetrue の場合、これらの手順を中止します。

  6. depth sensing active statetrue に設定します。

pauseDepthSensing()XRSession session 上で呼び出されたとき、User Agent は次の手順を実行しなければなりません:
  1. sessionended 値が true の場合、InvalidStateError を投げ、これらの手順を中止します。

  2. sessionanimation frameframe とします。

  3. frameactive boolean が false の場合、InvalidStateError を投げ、これらの手順を中止します。

  4. depth-sensing feature descriptor が、sessionXR device の、sessionmode に対する list of enabled featurescontained されていない場合、NotSupportedError投げ、 これらの手順を中止します。

  5. depth sensing active statefalse の場合、これらの手順を中止します。

  6. depth sensing active statefalse に設定します。

3. Depth data の取得

3.1. XRDepthInformation

[SecureContext, Exposed=Window]
interface XRDepthInformation {
  readonly attribute unsigned long width;
  readonly attribute unsigned long height;

  [SameObject] readonly attribute XRRigidTransform normDepthBufferFromNormView;
  readonly attribute float rawValueToMeters;
};

XRDepthInformation includes XRViewGeometry;

width 属性は、depth buffer の幅(すなわち列数)を含みます。

height 属性は、depth buffer の高さ(すなわち行数)を含みます。

normDepthBufferFromNormView 属性は、depth buffer に index する際に適用する必要がある XRRigidTransform を含みます。 その matrix が表す transformation は、coordinate system を normalized view coordinates から normalized depth buffer coordinates に変更し、それを depth buffer の width および height で scale することで、absolute depth buffer coordinates を得られるようにします。

注: applications が結果の depth buffer を mesh の texturing に使用する意図がある場合、mesh vertices の texture coordinates が normalized view coordinates で表現されていること、または適切な coordinate system change が shader 内で実行されることを確保するよう注意しなければなりません。

rawValueToMeters 属性は、depth buffer からの raw depth values を meters 単位の depth にするために掛けなければならない scale factor を含みます。

transform は、関連付けられた viewreference space 内で与えられます。

sensor が関連付けられた view と揃っている場合、XRViewGeometry から含まれるすべての値は、関連付けられた view が返すものと同じ値を返さなければなりません。

XRDepthInformation は、関連付けられた view を持ち、これは sensor に最も近い XRView であり、XRDepthInformation を取得するために使用されます。

XRDepthInformation は、関連付けられた sensor を持ち、これは depth information が取得された XRViewGeometrycontaining object です。

XRDepthInformation は、関連付けられた depth buffer を持ち、これは depth buffer data を含みます。 異なる XRDepthInformation は、depth buffer 内に異なる concrete types の objects を格納することがあります。

XRDepthInformation またはそれを継承する任意の interface の depth buffer にアクセスしようとする とき、 ユーザーエージェントは次の手順を実行しなければなりません:

  1. depthInformation を、member がアクセスされた instance とします。

  2. depthInformationviewview とします。

  3. viewframeframe とします。

  4. frameactive でない場合、InvalidStateError を投げ、これらの手順を中止します。

  5. frameanimationFrame でない場合、InvalidStateError を投げ、これらの手順を中止します。

  6. depthInformation の member にアクセスするために必要な通常の手順を続行します。

3.2. XRCPUDepthInformation

[Exposed=Window]
interface XRCPUDepthInformation : XRDepthInformation {
  [SameObject] readonly attribute ArrayBuffer data;

  float getDepthInMeters(float x, float y);
};

data 属性は、必要であれば WebGL texture へ upload するのに適した raw format の depth buffer information を含みます。 data は padding なしの row-major format で格納され、各 entry は sensor の near plane から users' environment までの距離に対応し、 単位は unspecified です。各 data entry のサイズと type は depthDataFormat によって決定されます。 値は rawValueToMeters を掛けることで unspecified units から meters に変換できます。 normDepthBufferFromNormView は、normalized view coordinates から depth buffer の coordinate system へ transform するために使用できます。アクセス時には、depth buffer にアクセスする algorithm を実行しなければなりません。

注: Applications は data array の内容を変更しようとすべきではありません。これは getDepthInMeters(x, y) method によって返される結果を不正確にする可能性があるためです。

getDepthInMeters(x, y) method は、obtain depth at coordinates するために使用できます。呼び出されたとき、 depth buffer にアクセスする algorithm を実行しなければなりません。

getDepthInMeters(x, y) method が、x, y とともに XRCPUDepthInformation depthInformation 上で呼び出されたとき、ユーザーエージェントは次の手順を実行して obtain depth at coordinates しなければなりません:

  1. depthInformationviewviewviewframeframe、そして framesessionsession とします。

  2. x1.0 より大きい、または 0.0 より小さい場合、RangeError投げ、これらの手順を中止します。

  3. y1.0 より大きい、または 0.0 より小さい場合、RangeError投げ、これらの手順を中止します。

  4. normalizedViewCoordinates を、space 内の 3-dimensional point を表す vector とします。 その x coordinate は xy coordinate は yz coordinate は 0.0w coordinate は 1.0 に設定されます。

  5. normalizedDepthCoordinates を、normalizedViewCoordinates vector を depthInformationnormDepthBufferFromNormView によって左から premultiply した結果とします。

  6. depthCoordinates を、normalizedDepthCoordinates を scale した結果とします。 x coordinate は depthInformationwidth で乗算され、y coordinate は depthInformationheight で乗算されます。

  7. depthCoordinatesx coordinate の値を integer に切り捨て、 [0, width-1] integer range に clamp したものを column とします。

  8. depthCoordinatesy coordinate の値を integer に切り捨て、 [0, height-1] integer range に clamp したものを row とします。

  9. rowwidth を掛け、column を加えた値と等しいものを index とします。

  10. index に depth data format のサイズを掛けたものを byteIndex とします。

  11. data 内の index byteIndex にある値を、sessiondepthDataFormat に従って number として解釈したものに等しいものを rawDepth とします。

  12. depthInformationrawValueToMeters に等しいものを rawValueToMeters とします。

  13. rawDepthrawValueToMeters を掛けた値を返します。

partial interface XRFrame {
  XRCPUDepthInformation? getDepthInformation(XRView view);
};

getDepthInformation(view) method は、XRFrame 上で呼び出されたとき、application が frame に関連する CPU depth information を取得 したいことを示します。

getDepthInformation(view) method が、XRFrame frame 上で、XRView view とともに呼び出されたとき、ユーザーエージェントは次の手順を実行して CPU depth information を取得 しなければなりません:

  1. framesessionsession とします。

  2. depth-sensing feature descriptor が、sessionXR device の、sessionmode に対する list of enabled featurescontained されていない場合、NotSupportedError投げ、 これらの手順を中止します。

  3. frameactive boolean が false の場合、InvalidStateError を投げ、これらの手順を中止します。

  4. frameanimationFrame boolean が false の場合、 InvalidStateError を投げ、これらの手順を中止します。

  5. frameviewframe と一致しない場合、InvalidStateError投げ、これらの手順を中止します。

  6. sessiondepthUsage"cpu-optimized" でない場合、InvalidStateError を投げ、これらの手順を中止します。

  7. frame および view が与えられた CPU depth information instance の作成 の結果を depthInformation とします。

  8. depthInformation を返します。

XRFrame frame および XRView view が与えられて CPU depth information instance を作成 するには、 ユーザーエージェントは次の手順を実行しなければなりません:

  1. XRCPUDepthInformation の new instance を result とします。

  2. frametimetime とします。

  3. framesessionsession とします。

  4. sessionXR devicedevice とします。

  5. depthActivefalse である場合、null を返し、これらの手順を中止します。

  6. sessiondepthType, depthUsage, および depthDataFormat を考慮し、指定された view について time 時点で有効な depth information を device に query した結果を nativeDepthInformation とします。

  7. nativeDepthInformationnull である場合、null を返し、 これらの手順を中止します。

  8. nativeDepthInformation 内に存在する depth buffer が、depth data への access を block するための user agent の criteria を満たす場合、null を返し、これらの手順を中止します。

  9. nativeDepthInformation 内に存在する depth buffer が、depth buffer で利用可能な information の量を制限する ための user agent の criteria を満たす場合、depth buffer をそれに応じて調整します。

  10. resultwidth を、nativeDepthInformation で返された depth buffer の width に初期化します。

  11. resultheight を、nativeDepthInformation で返された depth buffer の height に初期化します。

  12. resultnormDepthBufferFromNormView を、nativeDepthInformationdepth coordinates transformation matrix に基づく new XRRigidTransform に初期化します。

  13. resultdata を、nativeDepthInformation で返された raw depth buffer に初期化します。

  14. resultviewview に初期化します。

  15. resulttransform を、viewreference space 内の time における sensor の pose に初期化します。

  16. result を返します。

次の code は、XRFrameRequestCallback 内で depth data を取得する方法を示します。 depth sensing が有効で、usage が "cpu-optimized" に設定され、data format が "luminance-alpha" に設定された session であると仮定します:
const session = ...;          // Session created with depth sensing enabled.
const referenceSpace = ...;   // Reference space created from the session.

function requestAnimationFrameCallback(t, frame) {
  session.requestAnimationFrame(requestAnimationFrameCallback);

  const pose = frame.getViewerPose(referenceSpace);
  if (pose) {
    for (const view of pose.views) {
      const depthInformation = frame.getDepthInformation(view);
      if (depthInformation) {
        useCpuDepthInformation(view, depthInformation);
      }
    }
  }
}

XRCPUDepthInformation が取得されると、それを使用して view plane から user’s environment までの距離を調べることができます(詳細は § 4 結果の解釈 節を参照)。以下の code は normalized view coordinates (0.25, 0.75) における depth を取得する例を示します:

function useCpuDepthInformation(view, depthInformation) {
  const depthInMeters = depthInformation.getDepthInMeters(0.25, 0.75);
  console.log("Depth at normalized view coordinates (0.25, 0.75) is:",
    depthInMeters);
}

3.3. XRWebGLDepthInformation

[Exposed=Window]
interface XRWebGLDepthInformation : XRDepthInformation {
  [SameObject] readonly attribute WebGLTexture texture;

  readonly attribute XRTextureType textureType;
  readonly attribute unsigned long? imageIndex;
};

texture 属性は、depth buffer information を opaque texture として含みます。各 texel は、sensor の near plane から users' environment までの距離に対応し、単位は unspecified です。各 data entry のサイズと type は depthDataFormat によって決定されます。 値は rawValueToMeters を掛けることで unspecified units から meters に変換できます。 normDepthBufferFromNormView は、normalized view coordinates から depth buffer の coordinate system へ transform するために使用できます。アクセス時には、depth buffer にアクセスする algorithm を XRDepthInformation について実行しなければなりません。

textureType 属性は、texture が TEXTURE_2D 型であるか、TEXTURE_2D_ARRAY 型であるかを記述します。

imageIndex 属性は、texture array への offset を返します。textureTypeTEXTURE_2D_ARRAY と等しい場合は定義されなければならず、TEXTURE_2D である場合は undefined でなければなりません。

partial interface XRWebGLBinding {
  XRWebGLDepthInformation? getDepthInformation(XRView view);
};

getDepthInformation(view) method は、XRWebGLBinding 上で呼び出されたとき、application が frame に関連する WebGL depth information を取得 したいことを示します。

getDepthInformation(view) method が、XRWebGLBinding binding 上で、XRView view とともに呼び出されたとき、ユーザーエージェントは次の手順を実行して WebGL depth information を取得 しなければなりません:

  1. bindingsessionsession とします。

  2. viewframeframe とします。

  3. sessionframesession と一致しない場合、InvalidStateError を投げ、これらの手順を中止します。

  4. depth-sensing feature descriptor が、sessionXR device の、sessionmode に対する list of enabled featurescontained されていない場合、NotSupportedError投げ、 これらの手順を中止します。

  5. sessiondepthUsage"gpu-optimized" でない場合、InvalidStateError を投げ、これらの手順を中止します。

  6. frameactive boolean が false の場合、InvalidStateError を投げ、これらの手順を中止します。

  7. frameanimationFrame boolean が false の場合、 InvalidStateError を投げ、これらの手順を中止します。

  8. frame および view が与えられた WebGL depth information instance の作成 の結果を depthInformation とします。

  9. depthInformation を返します。

XRFrame frame および XRView view が与えられて WebGL depth information instance を作成 するには、 ユーザーエージェントは次の手順を実行しなければなりません:

  1. XRWebGLDepthInformation の new instance を result とします。

  2. time を次のように初期化します:

    XRSessionmatchDepthViewtrue に設定して作成された場合:
    frametimetime とします。
    それ以外の場合
    device が depth information を capture した time を time とします。
  3. framesessionsession とします。

  4. sessionXR devicedevice とします。

  5. depthActivefalse である場合、null を返し、これらの手順を中止します。

  6. sessiondepthType, depthUsage, および depthDataFormat を考慮し、指定された view について time 時点で有効な depth information を devicenative depth sensing に query した結果を nativeDepthInformation とします。

  7. nativeDepthInformationnull である場合、null を返し、 これらの手順を中止します。

  8. nativeDepthInformation 内に存在する depth buffer が、depth data への access を block するための user agent の criteria を満たす場合、null を返し、これらの手順を中止します。

  9. nativeDepthInformation 内に存在する depth buffer が、depth buffer で利用可能な information の量を制限する ための user agent の criteria を満たす場合、depth buffer をそれに応じて調整します。

  10. resultwidth を、nativeDepthInformation で返された depth buffer の width に初期化します。

  11. resultheight を、nativeDepthInformation で返された depth buffer の height に初期化します。

  12. resultnormDepthBufferFromNormView を、nativeDepthInformationdepth coordinates transformation matrix に基づく new XRRigidTransform に初期化します。

  13. resulttexture を、nativeDepthInformation で返された depth buffer を含む opaque texture に初期化します。

  14. resultviewview に初期化します。

  15. resulttransform を、viewreference space 内の time における sensor の pose に初期化します。

  16. resulttextureType を次のように初期化します:

    resulttexturetexture-array の textureType で作成された場合:
    resulttextureType を "texture-array" に初期化します。
    それ以外の場合
    resulttextureType を "texture" に初期化します。
  17. resultimageIndex を次のように初期化します:

    textureTypetexture である場合
    resultimageIndexnull に初期化します。
    それ以外の場合で、vieweye"right" である場合
    resultimageIndex1 に初期化します。
    それ以外の場合
    resultimageIndex0 に初期化します。
  18. result を返します。

次の code は、XRFrameRequestCallback 内で depth data を取得する方法を示します。 depth sensing が有効で、usage が "gpu-optimized" に設定され、data format が "luminance-alpha" に設定された session であると仮定します:
const session = ...;          // Session created with depth sensing enabled.
const referenceSpace = ...;   // Reference space created from the session.
const glBinding = ...;        // XRWebGLBinding created from the session.

function requestAnimationFrameCallback(t, frame) {
  session.requestAnimationFrame(requestAnimationFrameCallback);

  const pose = frame.getViewerPose(referenceSpace);
  if (pose) {
    for (const view of pose.views) {
      const depthInformation = glBinding.getDepthInformation(view);
      if (depthInformation) {
        useGpuDepthInformation(view, depthInformation);
      }
    }
  }
}

XRWebGLDepthInformation が取得されると、それを使用して view plane から user’s environment までの距離を調べることができます(詳細は § 4 結果の解釈 節を参照)。以下の code は、data を shader に 転送する方法を示します:

const gl = ...;             // GL context to use.
const shaderProgram = ...;  // Linked WebGLProgram.
const programInfo = {
  uniformLocations: {
    depthTexture: gl.getUniformLocation(shaderProgram, 'uDepthTexture'),
    uvTransform: gl.getUniformLocation(shaderProgram, 'uUvTransform'),
    rawValueToMeters: gl.getUniformLocation(shaderProgram, 'uRawValueToMeters'),
  }
};

function useGpuDepthInformation(view, depthInformation) {
  // ...

  gl.bindTexture(gl.TEXTURE_2D, depthInformation.texture);
  gl.activeTexture(gl.TEXTURE0);
  gl.uniform1i(programInfo.uniformLocations.depthTexture, 0);

  gl.uniformMatrix4fv(
    programInfo.uniformLocations.uvTransform, false,
    depthData.normDepthBufferFromNormView.matrix);

  gl.uniform1f(
    programInfo.uniformLocations.rawValueToMeters,
    depthData.rawValueToMeters);

  // ...
}

depth buffer を利用する fragment shader は、たとえば次のようになります:

precision mediump float;

uniform sampler2D uDepthTexture;
uniform mat4 uUvTransform;
uniform float uRawValueToMeters;

varying vec2 vTexCoord;

float DepthGetMeters(in sampler2D depth_texture, in vec2 depth_uv) {
  // Depth is packed into the luminance and alpha components of its texture.
  // The texture is a normalized format, storing millimeters.
  vec2 packedDepth = texture2D(depth_texture, depth_uv).ra;
  return dot(packedDepth, vec2(255.0, 256.0 * 255.0)) * uRawValueToMeters;
}

void main(void) {
  vec2 texCoord = (uUvTransform * vec4(vTexCoord.xy, 0, 1)).xy;

  float depthInMeters = DepthGetMeters(uDepthTexture, texCoord);

  gl_FragColor = ...;
}

4. 結果の解釈

ある pixel が invalid depth data を持つと判断された場合、または depth data を他の理由で 判定できない場合、ユーザーエージェントは depth value 0 を返さなければなりません。

data および texture に格納される値は、camera plane から real-world-geometry(XR system によって理解されるもの)までの距離を表します。 以下の例では、point a = (x, y) における depth value は、point A から camera plane までの距離に対応します。 具体的には、depth value は aA vector の長さを表すものではありません。

Depth API data explanation

上の画像は次の code に対応します:

// depthInfo is of type XRCPUDepthInformation:
const depthInMeters = depthInfo.getDepthInMeters(x, y);

5. Native device concepts

5.1. Native depth sensing

Depth sensing specification は、depth sensing API が実装される基盤となる native device が、device の native depth sensing capabilities を query する方法を提供することを前提としています。 device が depth buffer data を取得する方法を公開している場合、その device は device の native depth sensing capabilities の query をサポートしていると言われます。 depth buffer data は、buffer dimensions、buffer に格納された値で使用される units に関する情報、normalized view coordinates から normalized depth buffer coordinates への coordinate system change を行う depth coordinates transformation matrix を含まなければなりません。 この transform は、transformed 3D vector の z coordinate を影響を受けないままにすべきです。 device はまた、projection matrix および sensortransform を公開する何らかの mechanism も提供しなければなりません。

device は support depth sensing type を 2 通りの方法で行うことができます。 device が最小限の post-processing で estimated depth values を単に返す場合、"raw" depth type をサポートすると言われます。device または runtime が、この data から noise を "smooth" out するための追加処理 (たとえば同じ depth value のより大きな領域へ)を適用できる場合、"smooth" depth type をサポートすると言われます。

注: "Raw" depth data は、confidence values を伴うことが多いです。 UA は、low confidence value を持つ depth data を、page にそのような data を返す際に invalid depth data として扱うことを選択できます。

device は support depth sensing usage を 2 通りの方法で行うことができます。 device が主に CPU-accessible memory を通じて depth data を返すことができる場合、"cpu-optimized" usage をサポートすると言われます。device が主に GPU-accessible memory を通じて depth data を返すことができる場合、 "gpu-optimized" usage をサポートすると言われます。

注: user agent は、両方の usage modes をサポートすることを 選択できます(たとえば、device が CPU-accessible data と GPU-accessible data の両方を提供できる場合、または CPU-accessible data と GPU-accessible data 間の転送を手動で実行する場合)。

device は、depth sensing usage および type が与えられたとき、次の方法で support depth sensing data format を行うことができます。 depth sensing usage および type が与えられたとき、device が 16 bit unsigned integers を含む buffer として depth data を返せる場合、"luminance-alpha" および "unsigned-short" data formats をサポートすると言われます。depth sensing usage および type が与えられたとき、device が 32 bit floating point values を含む buffer として depth data を返せる場合、"float32" data format をサポートすると言われます。

depth sensing configuration は、1 つの XRDepthType、 1 つの XRDepthUsage、 および 1 つの XRDepthDataFormat の組み合わせによって表されます。

device が指定された configuration について depth sensing type をサポートし、depth sensing usage をサポートし、かつ depth sensing data format をサポートする場合、その device は support the depth sensing configuration と言われます。

注: depth sensing API のサポートは、AR-capable と分類される hardware のみに限定されません。ただし、そのような devices ではこの feature がより一般的になることが期待されます。 適切な sensors を含む、または depth buffer を提供するための他の techniques を使用する VR devices も、 depth sensing API を実装するために必要な data を提供できるべきです。

depthTypeRequestusagePreference、 および dataFormatPreference のそれぞれについて、対応する array が空である場合に使用されなければならない preferred native depth sensing capability を device は持たなければなりません。type、usage、および format は、相互依存する可能性がありますが、 device の最も効率的なものを反映すべきです。

device は depth sensing active state を持つと言うことができ、これは depth sensing capabilities が active に running しているかを表す boolean です。この state は true として 開始しなければなりません。この state が false の場合、ユーザーエージェントはこの feature が有効であることによる performance impact を軽減する手段を取るべきです。

6. プライバシーおよびセキュリティに関する考慮事項

depth sensing API は、depth buffer という format で、ユーザー環境に関する追加情報を websites に提供します。 十分に高い resolution と十分に高い precision を持つ depth buffer が与えられると、websites はユーザーが 快適と感じる範囲を超える、より詳細な情報を潜在的に知ることができます。使用される underlying technology によっては、 depth data は camera image および IMU sensors に基づいて作成されることがあります。

ユーザーに対する privacy risks を軽減するため、user agents は session で depth sensing API を有効にする前に user consent を求めるべきです。さらに、depth sensing technologies および hardware が向上するにつれて、 user agents は API を通じて公開される information の量を制限する こと、またはそのような制限を 導入することが feasible でない場合、API から返される data への access を block する ことを考慮すべきです。information の量を制限するために、 user agents はたとえば、結果の depth buffer の resolution を下げたり、depth buffer 内に存在する値の precision を 下げたり(たとえば quantization によって)できます。そのような方法で data の量を制限することを決定した user agents は、それでもこの仕様を実装していると見なされます。

user agent が、device の cameras によって提供される情報と等価になるほど詳細な depth buffers を提供できる場合、 まず camera access を取得するために必要な consent と等価な user consent を取得しなければなりません。

変更点

First Public Working Draft 31 August 2021 からの変更点

7. 謝辞

次の個人が WebXR Depth Sensing 仕様の設計に貢献しました:

適合性

文書の 慣例

適合要件は、説明的な表明と RFC 2119 の用語との組み合わせで表現されます。 この文書の規範的部分におけるキーワード “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” は、RFC 2119 で説明されているとおりに解釈されるべきです。 ただし、読みやすさのため、 この仕様ではこれらの語がすべて大文字で現れるとは限りません。

この仕様のすべてのテキストは、明示的に非規範的と示された節、例、および注を除き、規範的です。[RFC2119]

この仕様の例は、“for example” という語で導入されるか、 または規範的テキストから class="example" によって分離されます。 次のようになります:

これは参考情報の例の一例です。

参考情報の注は “Note” という語で始まり、 規範的テキストから class="note" によって分離されます。 次のようになります:

注、これは参考情報の注です。

適合 アルゴリズム

アルゴリズムの一部として命令形で表現される要件 (たとえば "strip any leading space characters" または "return false and abort these steps") は、そのアルゴリズムを導入する際に使用されたキーワード ("must", "should", "may" など) の意味で解釈されるべきです。

アルゴリズムまたは具体的な手順として表現される適合要件は、 最終結果が等価である限り、 どのような方法で実装してもかまいません。 特に、この仕様で定義されるアルゴリズムは、 理解しやすいことを意図しており、 高性能であることを意図していません。 実装者には最適化が推奨されます。

索引

この 仕様で定義される用語

参照により定義される 用語

参考文献

規範的参考文献

[INFRA]
Anne van Kesteren; Domenic Denicola. Infra Standard. Living Standard. URL: https://infra.spec.whatwg.org/
[RFC2119]
S. Bradner. RFC で要件レベルを示すために 使用するキーワード. March 1997. Best Current Practice. URL: https://datatracker.ietf.org/doc/html/rfc2119
[WEBGL-2]
Dean Jackson; Jeff Gilbert. WebGL 2.0 Specification. 12 August 2017. URL: https://www.khronos.org/registry/webgl/specs/latest/2.0/
[WEBIDL]
Edgar Chen; Timothy Gu. Web IDL Standard. Living Standard. URL: https://webidl.spec.whatwg.org/
[WEBXR]
Brandon Jones; Manish Goregaokar; Rik Cabanier. WebXR Device API. 1 October 2025. CRD. URL: https://www.w3.org/TR/webxr/
[WEBXRLAYERS-1]
Rik Cabanier. WebXR Layers API Level 1. 24 November 2025. WD. URL: https://www.w3.org/TR/webxrlayers-1/

参考情報の参考文献

[WEBXR-AR-MODULE-1]
Brandon Jones; Manish Goregaokar; Rik Cabanier. WebXR Augmented Reality Module - Level 1. 25 April 2025. CRD. URL: https://www.w3.org/TR/webxr-ar-module-1/

IDL 索引

enum XRDepthType {
  "raw",
  "smooth",
};

enum XRDepthUsage {
  "cpu-optimized",
  "gpu-optimized",
};

enum XRDepthDataFormat {
  "luminance-alpha",
  "float32",
  "unsigned-short",
};

dictionary XRDepthStateInit {
  required sequence<XRDepthUsage> usagePreference;
  required sequence<XRDepthDataFormat> dataFormatPreference;
  sequence<XRDepthType> depthTypeRequest;
  boolean matchDepthView = true;
};

partial dictionary XRSessionInit {
  XRDepthStateInit depthSensing;
};

partial interface XRSession {
  readonly attribute XRDepthUsage depthUsage;
  readonly attribute XRDepthDataFormat depthDataFormat;
  readonly attribute XRDepthType? depthType;
  readonly attribute boolean? depthActive;

  undefined pauseDepthSensing();
  undefined resumeDepthSensing();
};

[SecureContext, Exposed=Window]
interface XRDepthInformation {
  readonly attribute unsigned long width;
  readonly attribute unsigned long height;

  [SameObject] readonly attribute XRRigidTransform normDepthBufferFromNormView;
  readonly attribute float rawValueToMeters;
};

XRDepthInformation includes XRViewGeometry;

[Exposed=Window]
interface XRCPUDepthInformation : XRDepthInformation {
  [SameObject] readonly attribute ArrayBuffer data;

  float getDepthInMeters(float x, float y);
};

partial interface XRFrame {
  XRCPUDepthInformation? getDepthInformation(XRView view);
};

[Exposed=Window]
interface XRWebGLDepthInformation : XRDepthInformation {
  [SameObject] readonly attribute WebGLTexture texture;

  readonly attribute XRTextureType textureType;
  readonly attribute unsigned long? imageIndex;
};

partial interface XRWebGLBinding {
  XRWebGLDepthInformation? getDepthInformation(XRView view);
};

MDN

XRCPUDepthInformation/data

In only one current engine.

FirefoxNoneSafariNoneChrome90+
Opera?Edge90+
Edge (Legacy)?IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebViewNoneSamsung Internet?Opera Mobile?
MDN

XRCPUDepthInformation/getDepthInMeters

In only one current engine.

FirefoxNoneSafariNoneChrome90+
Opera?Edge90+
Edge (Legacy)?IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebViewNoneSamsung Internet?Opera Mobile?
MDN

XRCPUDepthInformation

In only one current engine.

FirefoxNoneSafariNoneChrome90+
Opera?Edge90+
Edge (Legacy)?IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebViewNoneSamsung Internet?Opera Mobile?
MDN

XRDepthInformation/height

In only one current engine.

FirefoxNoneSafariNoneChrome90+
Opera?Edge90+
Edge (Legacy)?IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebViewNoneSamsung Internet?Opera Mobile?
MDN

XRDepthInformation/normDepthBufferFromNormView

In only one current engine.

FirefoxNoneSafariNoneChrome90+
Opera?Edge90+
Edge (Legacy)?IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebViewNoneSamsung Internet?Opera Mobile?
MDN

XRDepthInformation/rawValueToMeters

In only one current engine.

FirefoxNoneSafariNoneChrome90+
Opera?Edge90+
Edge (Legacy)?IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebViewNoneSamsung Internet?Opera Mobile?
MDN

XRDepthInformation/width

In only one current engine.

FirefoxNoneSafariNoneChrome90+
Opera?Edge90+
Edge (Legacy)?IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebViewNoneSamsung Internet?Opera Mobile?
MDN

XRDepthInformation

In only one current engine.

FirefoxNoneSafariNoneChrome90+
Opera?Edge90+
Edge (Legacy)?IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebViewNoneSamsung Internet?Opera Mobile?
MDN

XRFrame/getDepthInformation

In only one current engine.

FirefoxNoneSafariNoneChrome90+
Opera?Edge90+
Edge (Legacy)?IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebViewNoneSamsung Internet?Opera Mobile?
MDN

XRSession/depthDataFormat

In only one current engine.

FirefoxNoneSafariNoneChrome90+
Opera?Edge90+
Edge (Legacy)?IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebViewNoneSamsung Internet?Opera Mobile?
MDN

XRSession/depthUsage

In only one current engine.

FirefoxNoneSafariNoneChrome90+
Opera?Edge90+
Edge (Legacy)?IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebViewNoneSamsung Internet?Opera Mobile?
MDN

XRWebGLBinding/getDepthInformation

In only one current engine.

FirefoxNoneSafariNoneChrome90+
Opera?Edge90+
Edge (Legacy)?IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebViewNoneSamsung Internet?Opera Mobile?
MDN

XRWebGLDepthInformation/texture

In only one current engine.

FirefoxNoneSafariNoneChrome90+
Opera?Edge90+
Edge (Legacy)?IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebViewNoneSamsung Internet?Opera Mobile?
MDN

XRWebGLDepthInformation

In only one current engine.

FirefoxNoneSafariNoneChrome90+
Opera?Edge90+
Edge (Legacy)?IENone
Firefox for Android?iOS Safari?Chrome for Android?Android WebViewNoneSamsung Internet?Opera Mobile?