WebXRLightEstimation.d.ts 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. import { Observable } from "../../Misc/observable";
  2. import type { Nullable } from "../../types";
  3. import type { WebXRSessionManager } from "../webXRSessionManager";
  4. import { WebXRAbstractFeature } from "./WebXRAbstractFeature";
  5. import { Color3 } from "../../Maths/math.color";
  6. import { Vector3 } from "../../Maths/math.vector";
  7. import { DirectionalLight } from "../../Lights/directionalLight";
  8. import { BaseTexture } from "../../Materials/Textures/baseTexture";
  9. import { SphericalHarmonics } from "../../Maths/sphericalPolynomial";
  10. /**
  11. * Options for Light Estimation feature
  12. */
  13. export interface IWebXRLightEstimationOptions {
  14. /**
  15. * Disable the cube map reflection feature. In this case only light direction and color will be updated
  16. */
  17. disableCubeMapReflection?: boolean;
  18. /**
  19. * Should the scene's env texture be set to the cube map reflection texture
  20. * Note that this doesn't work is disableCubeMapReflection if set to false
  21. */
  22. setSceneEnvironmentTexture?: boolean;
  23. /**
  24. * How often should the cubemap update in ms.
  25. * If not set the cubemap will be updated every time the underlying system updates the environment texture.
  26. */
  27. cubeMapPollInterval?: number;
  28. /**
  29. * How often should the light estimation properties update in ms.
  30. * If not set the light estimation properties will be updated on every frame (depending on the underlying system)
  31. */
  32. lightEstimationPollInterval?: number;
  33. /**
  34. * Should a directional light source be created.
  35. * If created, this light source will be updated whenever the light estimation values change
  36. */
  37. createDirectionalLightSource?: boolean;
  38. /**
  39. * Define the format to be used for the light estimation texture.
  40. */
  41. reflectionFormat?: XRReflectionFormat;
  42. /**
  43. * Should the light estimation's needed vectors be constructed on each frame.
  44. * Use this when you use those vectors and don't want their values to change outside of the light estimation feature
  45. */
  46. disableVectorReuse?: boolean;
  47. /**
  48. * disable applying the spherical polynomial to the cube map texture
  49. */
  50. disableSphericalPolynomial?: boolean;
  51. /**
  52. * disable prefiltering the cube map texture
  53. */
  54. disablePreFiltering?: boolean;
  55. }
  56. /**
  57. * An interface describing the result of a light estimation
  58. */
  59. export interface IWebXRLightEstimation {
  60. /**
  61. * The intensity of the light source
  62. */
  63. lightIntensity: number;
  64. /**
  65. * Color of light source
  66. */
  67. lightColor: Color3;
  68. /**
  69. * The direction from the light source
  70. */
  71. lightDirection: Vector3;
  72. /**
  73. * Spherical harmonics coefficients of the light source
  74. */
  75. sphericalHarmonics: SphericalHarmonics;
  76. }
  77. /**
  78. * Light Estimation Feature
  79. *
  80. * @since 5.0.0
  81. */
  82. export declare class WebXRLightEstimation extends WebXRAbstractFeature {
  83. /**
  84. * options to use when constructing this feature
  85. */
  86. readonly options: IWebXRLightEstimationOptions;
  87. private _canvasContext;
  88. private _reflectionCubeMap;
  89. private _xrLightEstimate;
  90. private _xrLightProbe;
  91. private _xrWebGLBinding;
  92. private _lightDirection;
  93. private _lightColor;
  94. private _intensity;
  95. private _sphericalHarmonics;
  96. private _cubeMapPollTime;
  97. private _lightEstimationPollTime;
  98. /**
  99. * The module's name
  100. */
  101. static readonly Name = "xr-light-estimation";
  102. /**
  103. * The (Babylon) version of this module.
  104. * This is an integer representing the implementation version.
  105. * This number does not correspond to the WebXR specs version
  106. */
  107. static readonly Version = 1;
  108. /**
  109. * ARCore's reflection cube map size is 16x16.
  110. * Once other systems support this feature we will need to change this to be dynamic.
  111. * see https://github.com/immersive-web/lighting-estimation/blob/main/lighting-estimation-explainer.md#cube-map-open-questions
  112. */
  113. private _reflectionCubeMapTextureSize;
  114. private _hdrFilter;
  115. /**
  116. * If createDirectionalLightSource is set to true this light source will be created automatically.
  117. * Otherwise this can be set with an external directional light source.
  118. * This light will be updated whenever the light estimation values change.
  119. */
  120. directionalLight: Nullable<DirectionalLight>;
  121. /**
  122. * This observable will notify when the reflection cube map is updated.
  123. */
  124. onReflectionCubeMapUpdatedObservable: Observable<BaseTexture>;
  125. /**
  126. * Creates a new instance of the light estimation feature
  127. * @param _xrSessionManager an instance of WebXRSessionManager
  128. * @param options options to use when constructing this feature
  129. */
  130. constructor(_xrSessionManager: WebXRSessionManager,
  131. /**
  132. * options to use when constructing this feature
  133. */
  134. options: IWebXRLightEstimationOptions);
  135. /**
  136. * While the estimated cube map is expected to update over time to better reflect the user's environment as they move around those changes are unlikely to happen with every XRFrame.
  137. * Since creating and processing the cube map is potentially expensive, especially if mip maps are needed, you can listen to the onReflectionCubeMapUpdatedObservable to determine
  138. * when it has been updated.
  139. */
  140. get reflectionCubeMapTexture(): Nullable<BaseTexture>;
  141. /**
  142. * The most recent light estimate. Available starting on the first frame where the device provides a light probe.
  143. */
  144. get xrLightingEstimate(): Nullable<IWebXRLightEstimation>;
  145. private _getCanvasContext;
  146. private _getXRGLBinding;
  147. /**
  148. * Event Listener for "reflectionchange" events.
  149. */
  150. private _updateReflectionCubeMap;
  151. /**
  152. * attach this feature
  153. * Will usually be called by the features manager
  154. *
  155. * @returns true if successful.
  156. */
  157. attach(): boolean;
  158. /**
  159. * detach this feature.
  160. * Will usually be called by the features manager
  161. *
  162. * @returns true if successful.
  163. */
  164. detach(): boolean;
  165. /**
  166. * Dispose this feature and all of the resources attached
  167. */
  168. dispose(): void;
  169. protected _onXRFrame(_xrFrame: XRFrame): void;
  170. }