fluidRenderingTargetRenderer.d.ts 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. import type { Camera } from "../../Cameras/camera.js";
  2. import type { AbstractEngine } from "../../Engines/abstractEngine.js";
  3. import type { BaseTexture } from "../../Materials/Textures/baseTexture.js";
  4. import type { InternalTexture } from "../../Materials/Textures/internalTexture.js";
  5. import { Color3, Color4 } from "../../Maths/math.color.js";
  6. import { Matrix, Vector3 } from "../../Maths/math.vector.js";
  7. import { Observable } from "../../Misc/observable.js";
  8. import { PostProcess } from "../../PostProcesses/postProcess.js";
  9. import type { Scene } from "../../scene.js";
  10. import type { Nullable } from "../../types.js";
  11. import type { FluidRenderingObject } from "./fluidRenderingObject";
  12. import { FluidRenderingTextures } from "./fluidRenderingTextures";
  13. /**
  14. * Textures that can be displayed as a debugging tool
  15. */
  16. export declare enum FluidRenderingDebug {
  17. DepthTexture = 0,
  18. DepthBlurredTexture = 1,
  19. ThicknessTexture = 2,
  20. ThicknessBlurredTexture = 3,
  21. DiffuseTexture = 4,
  22. Normals = 5,
  23. DiffuseRendering = 6
  24. }
  25. /**
  26. * Class used to render an object as a fluid thanks to different render target textures (depth, thickness, diffuse)
  27. */
  28. export declare class FluidRenderingTargetRenderer {
  29. protected _scene: Scene;
  30. protected _camera: Nullable<Camera>;
  31. protected _engine: AbstractEngine;
  32. protected _invProjectionMatrix: Matrix;
  33. protected _depthClearColor: Color4;
  34. protected _thicknessClearColor: Color4;
  35. protected _needInitialization: boolean;
  36. /**
  37. * Returns true if the class needs to be reinitialized (because of changes in parameterization)
  38. */
  39. get needInitialization(): boolean;
  40. private _generateDiffuseTexture;
  41. /**
  42. * Gets or sets a boolean indicating that the diffuse texture should be generated and used for the rendering
  43. */
  44. get generateDiffuseTexture(): boolean;
  45. set generateDiffuseTexture(generate: boolean);
  46. /**
  47. * Fluid color. Not used if generateDiffuseTexture is true
  48. */
  49. fluidColor: Color3;
  50. /**
  51. * Density of the fluid (positive number). The higher the value, the more opaque the fluid.
  52. */
  53. density: number;
  54. /**
  55. * Strength of the refraction (positive number, but generally between 0 and 0.3).
  56. */
  57. refractionStrength: number;
  58. /**
  59. * Strength of the fresnel effect (value between 0 and 1). Lower the value if you want to soften the specular effect
  60. */
  61. fresnelClamp: number;
  62. /**
  63. * Strength of the specular power (positive number). Increase the value to make the specular effect more concentrated
  64. */
  65. specularPower: number;
  66. /**
  67. * Minimum thickness of the particles (positive number). If useFixedThickness is true, minimumThickness is the thickness used
  68. */
  69. minimumThickness: number;
  70. /**
  71. * Direction of the light. The fluid is assumed to be lit by a directional light
  72. */
  73. dirLight: Vector3;
  74. private _debugFeature;
  75. /**
  76. * Gets or sets the feature (texture) to be debugged. Not used if debug is false
  77. */
  78. get debugFeature(): FluidRenderingDebug;
  79. set debugFeature(feature: FluidRenderingDebug);
  80. private _debug;
  81. /**
  82. * Gets or sets a boolean indicating if we should display a specific texture (given by debugFeature) for debugging purpose
  83. */
  84. get debug(): boolean;
  85. set debug(debug: boolean);
  86. private _environmentMap?;
  87. /**
  88. * Gets or sets the environment map used for the reflection part of the shading
  89. * If null, no map will be used. If undefined, the scene.environmentMap will be used (if defined)
  90. */
  91. get environmentMap(): Nullable<BaseTexture> | undefined;
  92. set environmentMap(map: Nullable<BaseTexture> | undefined);
  93. private _enableBlurDepth;
  94. /**
  95. * Gets or sets a boolean indicating that the depth texture should be blurred
  96. */
  97. get enableBlurDepth(): boolean;
  98. set enableBlurDepth(enable: boolean);
  99. private _blurDepthSizeDivisor;
  100. /**
  101. * Gets or sets the depth size divisor (positive number, generally between 1 and 4), which is used as a divisor when creating the texture used for blurring the depth
  102. * For eg. if blurDepthSizeDivisor=2, the texture used to blur the depth will be half the size of the depth texture
  103. */
  104. get blurDepthSizeDivisor(): number;
  105. set blurDepthSizeDivisor(scale: number);
  106. private _blurDepthFilterSize;
  107. /**
  108. * Size of the kernel used to filter the depth blur texture (positive number, generally between 1 and 20 - higher values will require more processing power from the GPU)
  109. */
  110. get blurDepthFilterSize(): number;
  111. set blurDepthFilterSize(filterSize: number);
  112. private _blurDepthNumIterations;
  113. /**
  114. * Number of blurring iterations used to generate the depth blur texture (positive number, generally between 1 and 10 - higher values will require more processing power from the GPU)
  115. */
  116. get blurDepthNumIterations(): number;
  117. set blurDepthNumIterations(numIterations: number);
  118. private _blurDepthMaxFilterSize;
  119. /**
  120. * Maximum size of the kernel used to blur the depth texture (positive number, generally between 1 and 200 - higher values will require more processing power from the GPU when the particles are larger on screen)
  121. */
  122. get blurDepthMaxFilterSize(): number;
  123. set blurDepthMaxFilterSize(maxFilterSize: number);
  124. private _blurDepthDepthScale;
  125. /**
  126. * Depth weight in the calculation when applying the bilateral blur to generate the depth blur texture (positive number, generally between 0 and 100)
  127. */
  128. get blurDepthDepthScale(): number;
  129. set blurDepthDepthScale(scale: number);
  130. private _enableBlurThickness;
  131. /**
  132. * Gets or sets a boolean indicating that the thickness texture should be blurred
  133. */
  134. get enableBlurThickness(): boolean;
  135. set enableBlurThickness(enable: boolean);
  136. private _blurThicknessSizeDivisor;
  137. /**
  138. * Gets or sets the thickness size divisor (positive number, generally between 1 and 4), which is used as a divisor when creating the texture used for blurring the thickness
  139. * For eg. if blurThicknessSizeDivisor=2, the texture used to blur the thickness will be half the size of the thickness texture
  140. */
  141. get blurThicknessSizeDivisor(): number;
  142. set blurThicknessSizeDivisor(scale: number);
  143. private _blurThicknessFilterSize;
  144. /**
  145. * Size of the kernel used to filter the thickness blur texture (positive number, generally between 1 and 20 - higher values will require more processing power from the GPU)
  146. */
  147. get blurThicknessFilterSize(): number;
  148. set blurThicknessFilterSize(filterSize: number);
  149. private _blurThicknessNumIterations;
  150. /**
  151. * Number of blurring iterations used to generate the thickness blur texture (positive number, generally between 1 and 10 - higher values will require more processing power from the GPU)
  152. */
  153. get blurThicknessNumIterations(): number;
  154. set blurThicknessNumIterations(numIterations: number);
  155. private _useFixedThickness;
  156. /**
  157. * Gets or sets a boolean indicating that a fixed thickness should be used instead of generating a thickness texture
  158. */
  159. get useFixedThickness(): boolean;
  160. set useFixedThickness(use: boolean);
  161. /** @internal */
  162. _bgDepthTexture: Nullable<InternalTexture>;
  163. /** @internal */
  164. _onUseVelocityChanged: Observable<FluidRenderingTargetRenderer>;
  165. private _useVelocity;
  166. /**
  167. * Gets or sets a boolean indicating that the velocity should be used when rendering the particles as a fluid.
  168. * Note: the vertex buffers must contain a "velocity" buffer for this to work!
  169. */
  170. get useVelocity(): boolean;
  171. set useVelocity(use: boolean);
  172. private _depthMapSize;
  173. /**
  174. * Defines the size of the depth texture.
  175. * If null, the texture will have the size of the screen
  176. */
  177. get depthMapSize(): Nullable<number>;
  178. set depthMapSize(size: Nullable<number>);
  179. private _thicknessMapSize;
  180. /**
  181. * Defines the size of the thickness texture.
  182. * If null, the texture will have the size of the screen
  183. */
  184. get thicknessMapSize(): Nullable<number>;
  185. set thicknessMapSize(size: Nullable<number>);
  186. private _diffuseMapSize;
  187. /**
  188. * Defines the size of the diffuse texture.
  189. * If null, the texture will have the size of the screen
  190. */
  191. get diffuseMapSize(): Nullable<number>;
  192. set diffuseMapSize(size: Nullable<number>);
  193. private _samples;
  194. /**
  195. * Gets or sets the number of samples used by MSAA
  196. * Note: changing this value in WebGL does not work because depth/stencil textures can't be created with MSAA (see https://github.com/BabylonJS/Babylon.js/issues/12444)
  197. */
  198. get samples(): number;
  199. set samples(samples: number);
  200. /**
  201. * Gets the camera used for the rendering
  202. */
  203. get camera(): Nullable<Camera>;
  204. /** @internal */
  205. _renderPostProcess: Nullable<PostProcess>;
  206. /** @internal */
  207. _depthRenderTarget: Nullable<FluidRenderingTextures>;
  208. /** @internal */
  209. _diffuseRenderTarget: Nullable<FluidRenderingTextures>;
  210. /** @internal */
  211. _thicknessRenderTarget: Nullable<FluidRenderingTextures>;
  212. /**
  213. * Creates an instance of the class
  214. * @param scene Scene used to render the fluid object into
  215. * @param camera Camera used to render the fluid object. If not provided, use the active camera of the scene instead
  216. */
  217. constructor(scene: Scene, camera?: Camera);
  218. /** @internal */
  219. _initialize(): void;
  220. protected _setBlurParameters(renderTarget?: Nullable<FluidRenderingTextures>): void;
  221. protected _setBlurDepthParameters(): void;
  222. protected _setBlurThicknessParameters(): void;
  223. protected _initializeRenderTarget(renderTarget: FluidRenderingTextures): void;
  224. protected _createLiquidRenderingPostProcess(): void;
  225. /** @internal */
  226. _clearTargets(): void;
  227. /** @internal */
  228. _render(fluidObject: FluidRenderingObject): void;
  229. /**
  230. * Releases all the ressources used by the class
  231. * @param onlyPostProcesses If true, releases only the ressources used by the render post processes
  232. */
  233. dispose(onlyPostProcesses?: boolean): void;
  234. }