WebXR 光照估计 API 第 1 级

W3C 工作草案,

关于此文档的更多详细信息
此版本:
https://www.w3.org/TR/2025/WD-webxr-lighting-estimation-1-20251211/
最新发布版本:
https://www.w3.org/TR/webxr-lighting-estimation-1/
编辑草案:
https://immersive-web.github.io/lighting-estimation/
先前版本:
历史:
https://www.w3.org/standards/history/webxr-lighting-estimation-1/
反馈:
GitHub
编辑:
(Google)
前任编辑:
([Mozilla 至 2020 年])
参与:
提交问题未解决的问题
邮件列表归档
W3C 的 #immersive-web IRC

摘要

本规范描述了对向 WebXR 会话暴露环境光照条件估计的支持。

本文档的状态

本节描述本文档在发布时的状态。当前 W3C 出版物以及此技术报告最新修订版的列表,可在 W3C 标准和草案索引中找到。

沉浸式 Web 工作组维护着该小组尚未处理的所有错误 报告列表。此草案突出显示了一些仍有待在工作组中讨论的待处理问题。 对这些问题的结果尚未作出决定,包括它们是否有效。 强烈鼓励针对未解决问题提交带有拟议规范文本的 pull request。

本文档由沉浸式 Web 工作组使用推荐标准 轨道作为工作草案发布。本文档旨在成为 W3C 推荐标准。

作为工作草案发布并不意味着 W3C 及其成员的认可。本文档是一份草案文档,可能 随时由其他文档更新、替换或废弃。除作为进行中的工作外,不应引用本文档。

本文档由一个根据 W3C 专利政策运作的小组制作。 W3C 维护一份与该小组交付成果相关的任何 专利 披露的公开列表;该页面还包括 披露专利的说明。任何实际知晓某项专利,且该个人 认为该专利包含 必要 权利要求的个人,都必须按照 W3C 专利政策第 6 节披露该信息。

本文档受 2025年8月18日 W3C 流程文档约束。

1. 简介

WebXR 光照估计模块扩展了 WebXR Device APIWebXR 增强现实模块WebXR Layers 模块,使其能够暴露 对用户环境光照条件的估计。

2. 光照基元

2.1. XRLightProbe

XRLightProbe 收集用户环境中给定点的估计光照信息。

[SecureContext, Exposed=Window]
interface XRLightProbe : EventTarget {
  readonly attribute XRSpace probeSpace;
  attribute EventHandler onreflectionchange;
};

probeSpace 属性是一个 XRSpace, 其原生原点跟踪 XRLightProbe 生成光照估计时所相对的位置和方向。

onreflectionchange 属性是 reflectionchange 事件类型的事件处理器 IDL 属性

2.2. XRReflectionFormat

enum XRReflectionFormat {
  "srgba8",
  "rgba16f",
};

反射立方体贴图具有一个内部反射格式,用于指示纹理数据如何表示, 并可能改变应用选择使用该纹理的方式。可以使用 "srgba8" 格式或光照探针的 preferredReflectionFormat 来请求立方体贴图。

XRReflectionFormat WebGL 格式 WebGL 内部格式 WebGPU 格式 HDR
"srgba8" RGBA SRGB8_ALPHA8 "rgba8unorm-srgb"
"rgba16f" RGBA RGBA16F "rgba16float"

2.3. XRLightEstimate

XRLightEstimate 提供在 XRFrame 所表示的时间上,某个 XRLightProbe 的估计光照值。 XRLightEstimate 通过将 XRLightProbe 传递给 XRFramegetLightEstimate() 方法来查询。

[SecureContext, Exposed=Window]
interface XRLightEstimate {
  readonly attribute Float32Array sphericalHarmonicsCoefficients;
  readonly attribute DOMPointReadOnly primaryLightDirection;
  readonly attribute DOMPointReadOnly primaryLightIntensity;
};

sphericalHarmonicsCoefficients 属性返回一个包含 9 个球谐系数的 Float32Array。 该数组长度必须为 27 个元素,其中每 3 个元素分别定义单个系数的红、绿、蓝分量。 sphericalHarmonicsCoefficients 的第一项,即数组的前 3 个元素,必须代表一个有效的光照估计。所有其他 项都是可选的;如果由于用户隐私设置或平台能力而无法获得相应的光照估计, 则可以为 0。

sphericalHarmonicsCoefficients 中系数的顺序为 [C00, C1-1, C10, C11, C2-2, C2-1, C20, C21, C22],其中 Clm 是 球谐函数 Ylm 的系数。

primaryLightDirection 表示 从生成该 XRLightEstimateXRLightProbeprobeSpace原生 原点到主光源的方向。 该值必须是单位长度的 3D 向量,并且 w 值必须为 0.0。如果无法从用户环境获得估计值,则 primaryLightDirection 必须为 { x: 0.0, y: 1.0, z: 0.0, w: 0.0 },表示从上方垂直向下照射的光。

primaryLightIntensity 表示 主光源的颜色。该值必须表示一个 RGB 值,分别映射到 xyz 值,其中每个分量都大于或等于 0.0,并且 w 值必须为 1.0。如果无法从用户环境获得估计值,则 primaryLightIntensity 必须为 {x: 0.0, y: 0.0, z: 0.0, w: 1.0},表示无照明。

3. WebXR Device API 集成

来自 WebXR Device APIXRSessionXRFrame 接口都由本模块扩展。

3.1. 会话初始化

字符串“light-estimation”由本模块作为新的 有效特性描述符引入。希望使用光照估计 特性的应用,必须使用“light-estimation特性 描述符来请求。

3.2. XRSession

XRSession 接口被扩展为能够创建新的 XRLightProbe 实例。XRLightProbe 实例具有一个 会话对象,即创建此 XRLightProbeXRSession。 还具有一个 反射格式对象,即该光照探针可以取得的 XRReflectionFormat

XRSession 接口进一步扩展了一个属性 preferredReflectionFormat, 指示底层 XR 设备 最接近支持的 XRReflectionFormat

dictionary XRLightProbeInit {
  XRReflectionFormat reflectionFormat = "srgba8";
};

partial interface XRSession {
  Promise<XRLightProbe> requestLightProbe(optional XRLightProbeInit options = {});
  readonly attribute XRReflectionFormat preferredReflectionFormat;
};
当在 XRSession session 上调用 requestLightProbe(options) 方法时, 用户代理必须运行以下步骤:
  1. promise一个新的 Promise

  2. 如果 light-estimation 特性描述符未被 包含session已启用特性列表中,则用 NotSupportedError 拒绝 promise,并中止这些步骤。

  3. 如果 sessionended 值为 true,则抛出 InvalidStateError 并中止这些步骤。

    如果 optionsreflectionFormat"srgba8" 或与 sessionpreferredReflectionFormat 匹配:
    1. probe 为一个新的 XRLightProbe

    2. probe会话设为 session

    3. probe反射格式设为 optionsreflectionFormat

    4. probe 解决 promise

    否则
    1. 用“NotSupportedErrorDOMException 拒绝 promise

3.3. XRFrame

XRFrame 接口被扩展为能够为给定的 XRLightProbe 查询 XRLightEstimate

partial interface XRFrame {
  XRLightEstimate? getLightEstimate(XRLightProbe lightProbe);
};
当在 XRFrame frame 上调用 getLightEstimate(lightProbe) 方法时, 用户代理必须运行以下步骤:
  1. 如果 frameactive 布尔值为 `false`,则抛出 InvalidStateError 并中止这些步骤。

  2. sessionframesession 对象。

  3. 如果 lightProbe会话不等于 session,则抛出 InvalidStateError 并中止这些步骤。

  4. devicesessionXR 设备

  5. 如果 device 无法估计此帧的光照,则返回 null。

  6. estimate 为一个新的 XRLightEstimate

  7. device 提供的系数填充 estimatesphericalHarmonicsCoefficients

    如果 device 具有光源的估计方向
    1. estimateprimaryLightDirection 设为光源的估计方向。

    否则
    1. estimateprimaryLightDirection 设为 { x: 0.0, y: 1.0, z: 0.0, w: 0.0 }

    如果 device 具有光源的估计强度
    1. estimateprimaryLightIntensity 设为光源的估计强度。

    否则
    1. estimateprimaryLightIntensity 设为 {x: 0.0, y: 0.0, z: 0.0, w: 1.0}

  8. 返回 estimate

4. WebXR Layers 集成

来自 WebXR Layers 模块XRWebGLBinding 接口由本模块扩展。

4.1. XRWebGLBinding

XRWebGLBinding 接口被扩展为能够为给定的 XRLightProbe 查询反射立方体贴图。

partial interface XRWebGLBinding {
  WebGLTexture? getReflectionCubeMap(XRLightProbe lightProbe);
};
当在 XRWebGLBinding binding 上调用 getReflectionCubeMap(lightProbe) 方法时,用户代理必须运行以下步骤:
  1. 如果 binding上下文已丢失,则抛出 InvalidStateError 并中止这些步骤。

  2. sessionbinding会话

  3. 如果 sessionended 值为 true,则抛出 InvalidStateError 并中止这些步骤。

  4. 如果 sessionlightProbe会话不匹配,则抛出 InvalidStateError 并中止这些步骤。

  5. devicesessionXR 设备

  6. 如果没有可从 device 获得的反射立方体贴图,则返回 null

  7. 返回一个新的 WebGLTexture 立方体贴图,其格式由 lightProbe反射格式指定,并填充来自 device 的数据。

5. 事件

除非另有规定,本规范中所有排队任务任务源XR 任务源

5.1. 事件类型

每当通过调用 getReflectionCubeMap() 返回的立方体贴图内容发生变化时,用户代理必须在 XRLightProbe 对象上触发一个事件,其名称为 reflectionchange

6. 隐私与安全考量

光照估计 API 与 Ambient Light Sensor API [AMBIENT-LIGHT] 共享许多潜在的隐私和安全风险,包括:

除此之外,还需要考虑一些光照估计特有的向量。

创建 XR Session 时,必须将光照估计声明为一个特性 描述符,这将允许用户代理通知用户允许网站使用光照估计 API 的潜在隐私 影响。鼓励用户代理不要为光照估计 API 的任何部分提供实时更新,尤其是 反射立方体贴图。默认情况下,WebXR API 应仅返回低空间频率和低时间频率信息。 除非用户还同意了特定源的相机权限,否则反射立方体贴图应保持低分辨率。 作为进一步缓解措施,球谐系数和主光方向可以被量化。

变更

2021年9月9日首个 公开工作草案以来的变更

一致性

文档 约定

一致性要求通过描述性断言 与 RFC 2119 术语的组合来表达。 关键词“MUST”、“MUST NOT”、“REQUIRED”、“SHALL”、“SHALL NOT”、“SHOULD”、“SHOULD NOT”、“RECOMMENDED”、 “MAY”和“OPTIONAL” 在本文档的规范性部分中 应按 RFC 2119 中所述进行解释。 但是,为了可读性, 这些词在本规范中并不全部以大写字母出现。

除明确标记为非规范性的章节、示例和注释外, 本规范的所有文本均为规范性的。[RFC2119]

本规范中的示例以“例如”一词引入, 或通过 class="example" 与规范性文本区分开来, 如下所示:

这是一个资料性示例的示例。

资料性注释以“注”一词开头, 并通过 class="note" 与规范性文本区分开来, 如下所示:

注,这是一个资料性注释。

一致性 算法

作为算法的一部分以祈使句表述的要求 (例如“去除任何前导空格字符” 或“返回 false 并中止这些步骤”), 应按照引入该算法时使用的关键词 (“must”、“should”、“may”等) 的含义进行解释。

以算法或具体步骤形式表述的一致性要求 可以以任何方式实现, 只要最终结果等价即可。 特别是,本规范中定义的算法 旨在易于理解, 并非旨在具备高性能。 鼓励实现者进行优化。

索引

由本 规范定义的术语

由引用 定义的术语

引用

规范性引用

[AMBIENT-LIGHT]
Anssi Kostiainen; Rijubrata Bhaumik. 环境光 传感器. 2025年2月12日. WD. URL: https://www.w3.org/TR/ambient-light/
[DOM]
Anne van Kesteren. DOM 标准. Living Standard. URL: https://dom.spec.whatwg.org/
[GEOMETRY-1]
Simon Pieters; Chris Harrelson. 几何接口模块 第 1 级. 2018年12月4日. CR. URL: https://www.w3.org/TR/geometry-1/
[HTML]
Anne van Kesteren; et al. HTML 标准. Living Standard. URL: https://html.spec.whatwg.org/multipage/
[INFRA]
Anne van Kesteren; Domenic Denicola. Infra 标准. Living Standard. URL: https://infra.spec.whatwg.org/
[RFC2119]
S. Bradner. 用于在 RFC 中 指示要求级别的关键词. 1997年3月. Best Current Practice. URL: https://datatracker.ietf.org/doc/html/rfc2119
[WEBGL-2]
Dean Jackson; Jeff Gilbert. WebGL 2.0 规范. 2017年8月12日. URL: https://www.khronos.org/registry/webgl/specs/latest/2.0/
[WEBIDL]
Edgar Chen; Timothy Gu. Web IDL 标准. Living Standard. URL: https://webidl.spec.whatwg.org/
[WEBXR]
Brandon Jones; Manish Goregaokar; Rik Cabanier. WebXR Device API. 2025年10月1日. CRD. URL: https://www.w3.org/TR/webxr/

IDL 索引

[SecureContext, Exposed=Window]
interface XRLightProbe : EventTarget {
  readonly attribute XRSpace probeSpace;
  attribute EventHandler onreflectionchange;
};

enum XRReflectionFormat {
  "srgba8",
  "rgba16f",
};

[SecureContext, Exposed=Window]
interface XRLightEstimate {
  readonly attribute Float32Array sphericalHarmonicsCoefficients;
  readonly attribute DOMPointReadOnly primaryLightDirection;
  readonly attribute DOMPointReadOnly primaryLightIntensity;
};

dictionary XRLightProbeInit {
  XRReflectionFormat reflectionFormat = "srgba8";
};

partial interface XRSession {
  Promise<XRLightProbe> requestLightProbe(optional XRLightProbeInit options = {});
  readonly attribute XRReflectionFormat preferredReflectionFormat;
};

partial interface XRFrame {
  XRLightEstimate? getLightEstimate(XRLightProbe lightProbe);
};

partial interface XRWebGLBinding {
  WebGLTexture? getReflectionCubeMap(XRLightProbe lightProbe);
};

MDN

XRFrame/getLightEstimate

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

XRLightEstimate/primaryLightDirection

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

XRLightEstimate/primaryLightIntensity

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

XRLightEstimate/sphericalHarmonicsCoefficients

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

XRLightEstimate

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

XRLightProbe/probeSpace

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

XRLightProbe/reflectionchange_event

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

XRLightProbe/reflectionchange_event

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

XRLightProbe

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/preferredReflectionFormat

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/requestLightProbe

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/getReflectionCubeMap

In only one current engine.

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