backgroundMaterial.d.ts 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. import type { Nullable, int, float } from "../../types";
  2. import type { Scene } from "../../scene";
  3. import type { Matrix } from "../../Maths/math.vector";
  4. import { Vector3 } from "../../Maths/math.vector";
  5. import type { SubMesh } from "../../Meshes/subMesh";
  6. import type { AbstractMesh } from "../../Meshes/abstractMesh";
  7. import type { Mesh } from "../../Meshes/mesh";
  8. import { PushMaterial } from "../../Materials/pushMaterial";
  9. import type { ColorCurves } from "../../Materials/colorCurves";
  10. import { ImageProcessingConfiguration } from "../../Materials/imageProcessingConfiguration";
  11. import type { BaseTexture } from "../../Materials/Textures/baseTexture";
  12. import type { IShadowLight } from "../../Lights/shadowLight";
  13. import { Color3 } from "../../Maths/math.color";
  14. import "../../Shaders/background.fragment";
  15. import "../../Shaders/background.vertex";
  16. /**
  17. * Background material used to create an efficient environment around your scene.
  18. */
  19. export declare class BackgroundMaterial extends PushMaterial {
  20. /**
  21. * Standard reflectance value at parallel view angle.
  22. */
  23. static StandardReflectance0: number;
  24. /**
  25. * Standard reflectance value at grazing angle.
  26. */
  27. static StandardReflectance90: number;
  28. protected _primaryColor: Color3;
  29. /**
  30. * Key light Color (multiply against the environment texture)
  31. */
  32. primaryColor: Color3;
  33. protected __perceptualColor: Nullable<Color3>;
  34. /**
  35. * Experimental Internal Use Only.
  36. *
  37. * Key light Color in "perceptual value" meaning the color you would like to see on screen.
  38. * This acts as a helper to set the primary color to a more "human friendly" value.
  39. * Conversion to linear space as well as exposure and tone mapping correction will be applied to keep the
  40. * output color as close as possible from the chosen value.
  41. * (This does not account for contrast color grading and color curves as they are considered post effect and not directly
  42. * part of lighting setup.)
  43. */
  44. get _perceptualColor(): Nullable<Color3>;
  45. set _perceptualColor(value: Nullable<Color3>);
  46. protected _primaryColorShadowLevel: float;
  47. /**
  48. * Defines the level of the shadows (dark area of the reflection map) in order to help scaling the colors.
  49. * The color opposite to the primary color is used at the level chosen to define what the black area would look.
  50. */
  51. get primaryColorShadowLevel(): float;
  52. set primaryColorShadowLevel(value: float);
  53. protected _primaryColorHighlightLevel: float;
  54. /**
  55. * Defines the level of the highlights (highlight area of the reflection map) in order to help scaling the colors.
  56. * The primary color is used at the level chosen to define what the white area would look.
  57. */
  58. get primaryColorHighlightLevel(): float;
  59. set primaryColorHighlightLevel(value: float);
  60. protected _reflectionTexture: Nullable<BaseTexture>;
  61. /**
  62. * Reflection Texture used in the material.
  63. * Should be author in a specific way for the best result (refer to the documentation).
  64. */
  65. reflectionTexture: Nullable<BaseTexture>;
  66. protected _reflectionBlur: float;
  67. /**
  68. * Reflection Texture level of blur.
  69. *
  70. * Can be use to reuse an existing HDR Texture and target a specific LOD to prevent authoring the
  71. * texture twice.
  72. */
  73. reflectionBlur: float;
  74. protected _diffuseTexture: Nullable<BaseTexture>;
  75. /**
  76. * Diffuse Texture used in the material.
  77. * Should be author in a specific way for the best result (refer to the documentation).
  78. */
  79. diffuseTexture: Nullable<BaseTexture>;
  80. protected _shadowLights: Nullable<IShadowLight[]>;
  81. /**
  82. * Specify the list of lights casting shadow on the material.
  83. * All scene shadow lights will be included if null.
  84. */
  85. shadowLights: Nullable<IShadowLight[]>;
  86. protected _shadowLevel: float;
  87. /**
  88. * Helps adjusting the shadow to a softer level if required.
  89. * 0 means black shadows and 1 means no shadows.
  90. */
  91. shadowLevel: float;
  92. protected _sceneCenter: Vector3;
  93. /**
  94. * In case of opacity Fresnel or reflection falloff, this is use as a scene center.
  95. * It is usually zero but might be interesting to modify according to your setup.
  96. */
  97. sceneCenter: Vector3;
  98. protected _opacityFresnel: boolean;
  99. /**
  100. * This helps specifying that the material is falling off to the sky box at grazing angle.
  101. * This helps ensuring a nice transition when the camera goes under the ground.
  102. */
  103. opacityFresnel: boolean;
  104. protected _reflectionFresnel: boolean;
  105. /**
  106. * This helps specifying that the material is falling off from diffuse to the reflection texture at grazing angle.
  107. * This helps adding a mirror texture on the ground.
  108. */
  109. reflectionFresnel: boolean;
  110. protected _reflectionFalloffDistance: number;
  111. /**
  112. * This helps specifying the falloff radius off the reflection texture from the sceneCenter.
  113. * This helps adding a nice falloff effect to the reflection if used as a mirror for instance.
  114. */
  115. reflectionFalloffDistance: number;
  116. protected _reflectionAmount: number;
  117. /**
  118. * This specifies the weight of the reflection against the background in case of reflection Fresnel.
  119. */
  120. reflectionAmount: number;
  121. protected _reflectionReflectance0: number;
  122. /**
  123. * This specifies the weight of the reflection at grazing angle.
  124. */
  125. reflectionReflectance0: number;
  126. protected _reflectionReflectance90: number;
  127. /**
  128. * This specifies the weight of the reflection at a perpendicular point of view.
  129. */
  130. reflectionReflectance90: number;
  131. /**
  132. * Sets the reflection reflectance fresnel values according to the default standard
  133. * empirically know to work well :-)
  134. */
  135. set reflectionStandardFresnelWeight(value: number);
  136. protected _useRGBColor: boolean;
  137. /**
  138. * Helps to directly use the maps channels instead of their level.
  139. */
  140. useRGBColor: boolean;
  141. protected _enableNoise: boolean;
  142. /**
  143. * This helps reducing the banding effect that could occur on the background.
  144. */
  145. enableNoise: boolean;
  146. /**
  147. * The current fov(field of view) multiplier, 0.0 - 2.0. Defaults to 1.0. Lower values "zoom in" and higher values "zoom out".
  148. * Best used when trying to implement visual zoom effects like fish-eye or binoculars while not adjusting camera fov.
  149. * Recommended to be keep at 1.0 except for special cases.
  150. */
  151. get fovMultiplier(): number;
  152. set fovMultiplier(value: number);
  153. private _fovMultiplier;
  154. /**
  155. * Enable the FOV adjustment feature controlled by fovMultiplier.
  156. */
  157. useEquirectangularFOV: boolean;
  158. private _maxSimultaneousLights;
  159. /**
  160. * Number of Simultaneous lights allowed on the material.
  161. */
  162. maxSimultaneousLights: int;
  163. private _shadowOnly;
  164. /**
  165. * Make the material only render shadows
  166. */
  167. shadowOnly: boolean;
  168. /**
  169. * Default configuration related to image processing available in the Background Material.
  170. */
  171. protected _imageProcessingConfiguration: ImageProcessingConfiguration;
  172. /**
  173. * Keep track of the image processing observer to allow dispose and replace.
  174. */
  175. private _imageProcessingObserver;
  176. /**
  177. * Attaches a new image processing configuration to the PBR Material.
  178. * @param configuration (if null the scene configuration will be use)
  179. */
  180. protected _attachImageProcessingConfiguration(configuration: Nullable<ImageProcessingConfiguration>): void;
  181. /**
  182. * Gets the image processing configuration used either in this material.
  183. */
  184. get imageProcessingConfiguration(): Nullable<ImageProcessingConfiguration>;
  185. /**
  186. * Sets the Default image processing configuration used either in the this material.
  187. *
  188. * If sets to null, the scene one is in use.
  189. */
  190. set imageProcessingConfiguration(value: Nullable<ImageProcessingConfiguration>);
  191. /**
  192. * Gets whether the color curves effect is enabled.
  193. */
  194. get cameraColorCurvesEnabled(): boolean;
  195. /**
  196. * Sets whether the color curves effect is enabled.
  197. */
  198. set cameraColorCurvesEnabled(value: boolean);
  199. /**
  200. * Gets whether the color grading effect is enabled.
  201. */
  202. get cameraColorGradingEnabled(): boolean;
  203. /**
  204. * Gets whether the color grading effect is enabled.
  205. */
  206. set cameraColorGradingEnabled(value: boolean);
  207. /**
  208. * Gets whether tonemapping is enabled or not.
  209. */
  210. get cameraToneMappingEnabled(): boolean;
  211. /**
  212. * Sets whether tonemapping is enabled or not
  213. */
  214. set cameraToneMappingEnabled(value: boolean);
  215. /**
  216. * The camera exposure used on this material.
  217. * This property is here and not in the camera to allow controlling exposure without full screen post process.
  218. * This corresponds to a photographic exposure.
  219. */
  220. get cameraExposure(): float;
  221. /**
  222. * The camera exposure used on this material.
  223. * This property is here and not in the camera to allow controlling exposure without full screen post process.
  224. * This corresponds to a photographic exposure.
  225. */
  226. set cameraExposure(value: float);
  227. /**
  228. * Gets The camera contrast used on this material.
  229. */
  230. get cameraContrast(): float;
  231. /**
  232. * Sets The camera contrast used on this material.
  233. */
  234. set cameraContrast(value: float);
  235. /**
  236. * Gets the Color Grading 2D Lookup Texture.
  237. */
  238. get cameraColorGradingTexture(): Nullable<BaseTexture>;
  239. /**
  240. * Sets the Color Grading 2D Lookup Texture.
  241. */
  242. set cameraColorGradingTexture(value: Nullable<BaseTexture>);
  243. /**
  244. * The color grading curves provide additional color adjustment that is applied after any color grading transform (3D LUT).
  245. * They allow basic adjustment of saturation and small exposure adjustments, along with color filter tinting to provide white balance adjustment or more stylistic effects.
  246. * These are similar to controls found in many professional imaging or colorist software. The global controls are applied to the entire image. For advanced tuning, extra controls are provided to adjust the shadow, midtone and highlight areas of the image;
  247. * corresponding to low luminance, medium luminance, and high luminance areas respectively.
  248. */
  249. get cameraColorCurves(): Nullable<ColorCurves>;
  250. /**
  251. * The color grading curves provide additional color adjustment that is applied after any color grading transform (3D LUT).
  252. * They allow basic adjustment of saturation and small exposure adjustments, along with color filter tinting to provide white balance adjustment or more stylistic effects.
  253. * These are similar to controls found in many professional imaging or colorist software. The global controls are applied to the entire image. For advanced tuning, extra controls are provided to adjust the shadow, midtone and highlight areas of the image;
  254. * corresponding to low luminance, medium luminance, and high luminance areas respectively.
  255. */
  256. set cameraColorCurves(value: Nullable<ColorCurves>);
  257. /**
  258. * Due to a bug in iOS10, video tags (which are using the background material) are in BGR and not RGB.
  259. * Setting this flag to true (not done automatically!) will convert it back to RGB.
  260. */
  261. switchToBGR: boolean;
  262. private _enableGroundProjection;
  263. /**
  264. * Enables the ground projection mode on the material.
  265. * @see https://doc.babylonjs.com/features/featuresDeepDive/environment/skybox#ground-projection
  266. */
  267. enableGroundProjection: boolean;
  268. /**
  269. * Defines the radius of the projected ground if enableGroundProjection is true.
  270. * @see https://doc.babylonjs.com/features/featuresDeepDive/environment/skybox#ground-projection
  271. */
  272. projectedGroundRadius: number;
  273. /**
  274. * Defines the height of the projected ground if enableGroundProjection is true.
  275. * @see https://doc.babylonjs.com/features/featuresDeepDive/environment/skybox#ground-projection
  276. */
  277. projectedGroundHeight: number;
  278. private _renderTargets;
  279. private _reflectionControls;
  280. private _white;
  281. private _primaryShadowColor;
  282. private _primaryHighlightColor;
  283. /**
  284. * Instantiates a Background Material in the given scene
  285. * @param name The friendly name of the material
  286. * @param scene The scene to add the material to
  287. */
  288. constructor(name: string, scene?: Scene);
  289. /**
  290. * Gets a boolean indicating that current material needs to register RTT
  291. */
  292. get hasRenderTargetTextures(): boolean;
  293. /**
  294. * The entire material has been created in order to prevent overdraw.
  295. * @returns false
  296. */
  297. needAlphaTesting(): boolean;
  298. /**
  299. * The entire material has been created in order to prevent overdraw.
  300. * @returns true if blending is enable
  301. */
  302. needAlphaBlending(): boolean;
  303. /**
  304. * Checks whether the material is ready to be rendered for a given mesh.
  305. * @param mesh The mesh to render
  306. * @param subMesh The submesh to check against
  307. * @param useInstances Specify wether or not the material is used with instances
  308. * @returns true if all the dependencies are ready (Textures, Effects...)
  309. */
  310. isReadyForSubMesh(mesh: AbstractMesh, subMesh: SubMesh, useInstances?: boolean): boolean;
  311. /**
  312. * Compute the primary color according to the chosen perceptual color.
  313. */
  314. private _computePrimaryColorFromPerceptualColor;
  315. /**
  316. * Compute the highlights and shadow colors according to their chosen levels.
  317. */
  318. private _computePrimaryColors;
  319. /**
  320. * Build the uniform buffer used in the material.
  321. */
  322. buildUniformLayout(): void;
  323. /**
  324. * Unbind the material.
  325. */
  326. unbind(): void;
  327. /**
  328. * Bind only the world matrix to the material.
  329. * @param world The world matrix to bind.
  330. */
  331. bindOnlyWorldMatrix(world: Matrix): void;
  332. /**
  333. * Bind the material for a dedicated submesh (every used meshes will be considered opaque).
  334. * @param world The world matrix to bind.
  335. * @param mesh the mesh to bind for.
  336. * @param subMesh The submesh to bind for.
  337. */
  338. bindForSubMesh(world: Matrix, mesh: Mesh, subMesh: SubMesh): void;
  339. /**
  340. * Checks to see if a texture is used in the material.
  341. * @param texture - Base texture to use.
  342. * @returns - Boolean specifying if a texture is used in the material.
  343. */
  344. hasTexture(texture: BaseTexture): boolean;
  345. /**
  346. * Dispose the material.
  347. * @param forceDisposeEffect Force disposal of the associated effect.
  348. * @param forceDisposeTextures Force disposal of the associated textures.
  349. */
  350. dispose(forceDisposeEffect?: boolean, forceDisposeTextures?: boolean): void;
  351. /**
  352. * Clones the material.
  353. * @param name The cloned name.
  354. * @returns The cloned material.
  355. */
  356. clone(name: string): BackgroundMaterial;
  357. /**
  358. * Serializes the current material to its JSON representation.
  359. * @returns The JSON representation.
  360. */
  361. serialize(): any;
  362. /**
  363. * Gets the class name of the material
  364. * @returns "BackgroundMaterial"
  365. */
  366. getClassName(): string;
  367. /**
  368. * Parse a JSON input to create back a background material.
  369. * @param source The JSON data to parse
  370. * @param scene The scene to create the parsed material in
  371. * @param rootUrl The root url of the assets the material depends upon
  372. * @returns the instantiated BackgroundMaterial.
  373. */
  374. static Parse(source: any, scene: Scene, rootUrl: string): BackgroundMaterial;
  375. }