environmentTextureTools.d.ts 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. import type { Nullable } from "../types";
  2. import { SphericalPolynomial } from "../Maths/sphericalPolynomial";
  3. import { InternalTexture } from "../Materials/Textures/internalTexture";
  4. import { BaseTexture } from "../Materials/Textures/baseTexture";
  5. import "../Engines/Extensions/engine.renderTargetCube";
  6. import "../Engines/Extensions/engine.readTexture";
  7. import "../Materials/Textures/baseTexture.polynomial";
  8. import "../Shaders/rgbdEncode.fragment";
  9. import "../Shaders/rgbdDecode.fragment";
  10. /**
  11. * Raw texture data and descriptor sufficient for WebGL texture upload
  12. */
  13. export type EnvironmentTextureInfo = EnvironmentTextureInfoV1 | EnvironmentTextureInfoV2;
  14. /**
  15. * v1 of EnvironmentTextureInfo
  16. */
  17. interface EnvironmentTextureInfoV1 {
  18. /**
  19. * Version of the environment map
  20. */
  21. version: 1;
  22. /**
  23. * Width of image
  24. */
  25. width: number;
  26. /**
  27. * Irradiance information stored in the file.
  28. */
  29. irradiance: any;
  30. /**
  31. * Specular information stored in the file.
  32. */
  33. specular: any;
  34. }
  35. /**
  36. * v2 of EnvironmentTextureInfo
  37. */
  38. interface EnvironmentTextureInfoV2 {
  39. /**
  40. * Version of the environment map
  41. */
  42. version: 2;
  43. /**
  44. * Width of image
  45. */
  46. width: number;
  47. /**
  48. * Irradiance information stored in the file.
  49. */
  50. irradiance: any;
  51. /**
  52. * Specular information stored in the file.
  53. */
  54. specular: any;
  55. /**
  56. * The mime type used to encode the image data.
  57. */
  58. imageType: string;
  59. }
  60. /**
  61. * Defines One Image in the file. It requires only the position in the file
  62. * as well as the length.
  63. */
  64. interface BufferImageData {
  65. /**
  66. * Length of the image data.
  67. */
  68. length: number;
  69. /**
  70. * Position of the data from the null terminator delimiting the end of the JSON.
  71. */
  72. position: number;
  73. }
  74. /**
  75. * Defines the specular data enclosed in the file.
  76. * This corresponds to the version 1 of the data.
  77. */
  78. export interface EnvironmentTextureSpecularInfoV1 {
  79. /**
  80. * Defines where the specular Payload is located. It is a runtime value only not stored in the file.
  81. */
  82. specularDataPosition?: number;
  83. /**
  84. * This contains all the images data needed to reconstruct the cubemap.
  85. */
  86. mipmaps: Array<BufferImageData>;
  87. /**
  88. * Defines the scale applied to environment texture. This manages the range of LOD level used for IBL according to the roughness.
  89. */
  90. lodGenerationScale: number;
  91. }
  92. /**
  93. * Options for creating environment textures
  94. */
  95. export interface CreateEnvTextureOptions {
  96. /**
  97. * The mime type of encoded images.
  98. */
  99. imageType?: string;
  100. /**
  101. * the image quality of encoded WebP images.
  102. */
  103. imageQuality?: number;
  104. }
  105. /**
  106. * Gets the environment info from an env file.
  107. * @param data The array buffer containing the .env bytes.
  108. * @returns the environment file info (the json header) if successfully parsed, normalized to the latest supported version.
  109. */
  110. export declare function GetEnvInfo(data: ArrayBufferView): Nullable<EnvironmentTextureInfoV2>;
  111. /**
  112. * Normalizes any supported version of the environment file info to the latest version
  113. * @param info environment file info on any supported version
  114. * @returns environment file info in the latest supported version
  115. * @private
  116. */
  117. export declare function normalizeEnvInfo(info: EnvironmentTextureInfo): EnvironmentTextureInfoV2;
  118. /**
  119. * Creates an environment texture from a loaded cube texture.
  120. * @param texture defines the cube texture to convert in env file
  121. * @param options options for the conversion process
  122. * @param options.imageType the mime type for the encoded images, with support for "image/png" (default) and "image/webp"
  123. * @param options.imageQuality the image quality of encoded WebP images.
  124. * @returns a promise containing the environment data if successful.
  125. */
  126. export declare function CreateEnvTextureAsync(texture: BaseTexture, options?: CreateEnvTextureOptions): Promise<ArrayBuffer>;
  127. /**
  128. * Creates the ArrayBufferViews used for initializing environment texture image data.
  129. * @param data the image data
  130. * @param info parameters that determine what views will be created for accessing the underlying buffer
  131. * @returns the views described by info providing access to the underlying buffer
  132. */
  133. export declare function CreateImageDataArrayBufferViews(data: ArrayBufferView, info: EnvironmentTextureInfo): Array<Array<ArrayBufferView>>;
  134. /**
  135. * Uploads the texture info contained in the env file to the GPU.
  136. * @param texture defines the internal texture to upload to
  137. * @param data defines the data to load
  138. * @param info defines the texture info retrieved through the GetEnvInfo method
  139. * @returns a promise
  140. */
  141. export declare function UploadEnvLevelsAsync(texture: InternalTexture, data: ArrayBufferView, info: EnvironmentTextureInfo): Promise<void>;
  142. /**
  143. * Uploads the levels of image data to the GPU.
  144. * @param texture defines the internal texture to upload to
  145. * @param imageData defines the array buffer views of image data [mipmap][face]
  146. * @param imageType the mime type of the image data
  147. * @returns a promise
  148. */
  149. export declare function UploadLevelsAsync(texture: InternalTexture, imageData: ArrayBufferView[][], imageType?: string): Promise<void>;
  150. /**
  151. * Uploads spherical polynomials information to the texture.
  152. * @param texture defines the texture we are trying to upload the information to
  153. * @param info defines the environment texture info retrieved through the GetEnvInfo method
  154. */
  155. export declare function UploadEnvSpherical(texture: InternalTexture, info: EnvironmentTextureInfo): void;
  156. /**
  157. * @internal
  158. */
  159. export declare function _UpdateRGBDAsync(internalTexture: InternalTexture, data: ArrayBufferView[][], sphericalPolynomial: Nullable<SphericalPolynomial>, lodScale: number, lodOffset: number): Promise<InternalTexture>;
  160. /**
  161. * Sets of helpers addressing the serialization and deserialization of environment texture
  162. * stored in a BabylonJS env file.
  163. * Those files are usually stored as .env files.
  164. */
  165. export declare const EnvironmentTextureTools: {
  166. /**
  167. * Gets the environment info from an env file.
  168. * @param data The array buffer containing the .env bytes.
  169. * @returns the environment file info (the json header) if successfully parsed, normalized to the latest supported version.
  170. */
  171. GetEnvInfo: typeof GetEnvInfo;
  172. /**
  173. * Creates an environment texture from a loaded cube texture.
  174. * @param texture defines the cube texture to convert in env file
  175. * @param options options for the conversion process
  176. * @param options.imageType the mime type for the encoded images, with support for "image/png" (default) and "image/webp"
  177. * @param options.imageQuality the image quality of encoded WebP images.
  178. * @returns a promise containing the environment data if successful.
  179. */
  180. CreateEnvTextureAsync: typeof CreateEnvTextureAsync;
  181. /**
  182. * Creates the ArrayBufferViews used for initializing environment texture image data.
  183. * @param data the image data
  184. * @param info parameters that determine what views will be created for accessing the underlying buffer
  185. * @returns the views described by info providing access to the underlying buffer
  186. */
  187. CreateImageDataArrayBufferViews: typeof CreateImageDataArrayBufferViews;
  188. /**
  189. * Uploads the texture info contained in the env file to the GPU.
  190. * @param texture defines the internal texture to upload to
  191. * @param data defines the data to load
  192. * @param info defines the texture info retrieved through the GetEnvInfo method
  193. * @returns a promise
  194. */
  195. UploadEnvLevelsAsync: typeof UploadEnvLevelsAsync;
  196. /**
  197. * Uploads the levels of image data to the GPU.
  198. * @param texture defines the internal texture to upload to
  199. * @param imageData defines the array buffer views of image data [mipmap][face]
  200. * @param imageType the mime type of the image data
  201. * @returns a promise
  202. */
  203. UploadLevelsAsync: typeof UploadLevelsAsync;
  204. /**
  205. * Uploads spherical polynomials information to the texture.
  206. * @param texture defines the texture we are trying to upload the information to
  207. * @param info defines the environment texture info retrieved through the GetEnvInfo method
  208. */
  209. UploadEnvSpherical: typeof UploadEnvSpherical;
  210. };
  211. export {};