XRWebGLDepthInformation: texture 屬性

可用性有限

此特性不是基線特性,因為它在一些最廣泛使用的瀏覽器中不起作用。

實驗性: 這是一項實驗性技術
在生產中使用此技術之前,請仔細檢查瀏覽器相容性表格

只讀 texture 屬性是 XRWebGLDepthInformation 介面的一個屬性,它是一個 WebGLTexture,包含作為不透明紋理的深度緩衝區資訊。

一個 WebGLTexture

示例

使用 XRWebGLBinding.getDepthInformation() 來獲取 GPU 深度資訊。返回的 XRWebGLDepthInformation 物件將包含 texture 緩衝區,然後可以將其繫結到紋理,並將深度緩衝區資訊提供給 WebGL 片段著色器。

js
const depthInfo = glBinding.getDepthInformation(view);
const uvTransform = depthInfo.normDepthBufferFromNormView.matrix;

const u_DepthTextureLocation = gl.getUniformLocation(program, "u_DepthTexture");
const u_UVTransformLocation = gl.getUniformLocation(program, "u_UVTransform");
const u_RawValueToMeters = gl.getUniformLocation(program, "u_RawValueToMeters");

gl.bindTexture(gl.TEXTURE_2D, depthInfo.texture);
gl.activeTexture(gl.TEXTURE0);
gl.uniform1i(u_DepthTextureLocation, 0);

// UV transform to correctly index into the depth map
gl.uniformMatrix4fv(u_UVTransformLocation, false, uvTransform);

// scaling factor to convert from the raw number to meters
gl.uniform1f(u_RawValueToMeters, depthInfo.rawValueToMeters);

規範

規範
WebXR Depth Sensing 模組
# dom-xrwebgldepthinformation-texture

瀏覽器相容性

另見