XRWebGLBinding: getReflectionCubeMap() 方法

可用性有限

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

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

XRWebGLBinding 介面的 getReflectionCubeMap() 方法返回一個包含反射立方體貼圖紋理的 WebGLTexture 物件。

紋理格式由會話的 reflectionFormat 指定。有關更多詳細資訊,請參閱 XRSession.requestLightProbe()XRSession.preferredReflectionFormat 中的 options 引數。預設情況下,使用 srgba8 格式。當使用 rgba16f 格式時,您需要處於 WebGL 2.0 上下文中,或者在 WebGL 1.0 上下文中啟用 OES_texture_half_float 擴充套件。

語法

js
getReflectionCubeMap(lightProbe)

引數

lightProbe

呼叫 XRSession.requestLightProbe() 返回的 XRLightProbe 物件。

返回值

一個 WebGLTexture 物件。

示例

通常,當光探針上觸發 reflectionchange 事件時,您會呼叫 getReflectionCubeMap() 來檢索更新的立方體貼圖。這比為每個 XRFrame 檢索光照資訊更高效。

如果使用 rgba16f 格式,請在 WebGL 1.0 上下文中啟用 OES_texture_half_float 擴充套件。

js
const glBinding = new XRWebGLBinding(xrSession, gl);
gl.getExtension("OES_texture_half_float"); // if rgba16f is the preferredReflectionFormat

xrSession.requestLightProbe().then((lightProbe) => {
  lightProbe.addEventListener("reflectionchange", () => {
    glBinding.getReflectionCubeMap(lightProbe);
  });
});

規範

規範
WebXR 光照估算 API Level 1
# dom-xrwebglbinding-getreflectioncubemap

瀏覽器相容性

另見