fluidRenderer.d.ts 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. import { Scene } from "../../scene.js";
  2. import type { FloatArray, Nullable } from "../../types.js";
  3. import type { Camera } from "../../Cameras/camera.js";
  4. import type { IParticleSystem } from "../../Particles/IParticleSystem.js";
  5. import type { ISceneComponent } from "../../sceneComponent.js";
  6. import type { FluidRenderingObject } from "./fluidRenderingObject";
  7. import { FluidRenderingTargetRenderer } from "./fluidRenderingTargetRenderer";
  8. import "../../Shaders/fluidRenderingParticleDepth.vertex";
  9. import "../../Shaders/fluidRenderingParticleDepth.fragment";
  10. import "../../Shaders/fluidRenderingParticleThickness.vertex";
  11. import "../../Shaders/fluidRenderingParticleThickness.fragment";
  12. import "../../Shaders/fluidRenderingParticleDiffuse.vertex";
  13. import "../../Shaders/fluidRenderingParticleDiffuse.fragment";
  14. import "../../Shaders/fluidRenderingBilateralBlur.fragment";
  15. import "../../Shaders/fluidRenderingStandardBlur.fragment";
  16. import "../../Shaders/fluidRenderingRender.fragment";
  17. declare module "../../abstractScene" {
  18. interface AbstractScene {
  19. /** @internal (Backing field) */
  20. _fluidRenderer: Nullable<FluidRenderer>;
  21. /**
  22. * Gets or Sets the fluid renderer associated to the scene.
  23. */
  24. fluidRenderer: Nullable<FluidRenderer>;
  25. /**
  26. * Enables the fluid renderer and associates it with the scene
  27. * @returns the FluidRenderer
  28. */
  29. enableFluidRenderer(): Nullable<FluidRenderer>;
  30. /**
  31. * Disables the fluid renderer associated with the scene
  32. */
  33. disableFluidRenderer(): void;
  34. }
  35. }
  36. /**
  37. * Defines the fluid renderer scene component responsible to render objects as fluids
  38. */
  39. export declare class FluidRendererSceneComponent implements ISceneComponent {
  40. /**
  41. * The component name helpful to identify the component in the list of scene components.
  42. */
  43. readonly name = "FluidRenderer";
  44. /**
  45. * The scene the component belongs to.
  46. */
  47. scene: Scene;
  48. /**
  49. * Creates a new instance of the component for the given scene
  50. * @param scene Defines the scene to register the component in
  51. */
  52. constructor(scene: Scene);
  53. /**
  54. * Registers the component in a given scene
  55. */
  56. register(): void;
  57. private _gatherActiveCameraRenderTargets;
  58. private _afterCameraDraw;
  59. /**
  60. * Rebuilds the elements related to this component in case of
  61. * context lost for instance.
  62. */
  63. rebuild(): void;
  64. /**
  65. * Disposes the component and the associated resources
  66. */
  67. dispose(): void;
  68. }
  69. /**
  70. * An object rendered as a fluid.
  71. * It consists of the object itself as well as the render target renderer (which is used to generate the textures (render target) needed for fluid rendering)
  72. */
  73. export interface IFluidRenderingRenderObject {
  74. /** object rendered as a fluid */
  75. object: FluidRenderingObject;
  76. /** target renderer used to render the fluid object */
  77. targetRenderer: FluidRenderingTargetRenderer;
  78. }
  79. /**
  80. * Class responsible for fluid rendering.
  81. * It is implementing the method described in https://developer.download.nvidia.com/presentations/2010/gdc/Direct3D_Effects.pdf
  82. */
  83. export declare class FluidRenderer {
  84. /** @internal */
  85. static _SceneComponentInitialization(scene: Scene): void;
  86. private _scene;
  87. private _engine;
  88. private _onEngineResizeObserver;
  89. private _cameras;
  90. /** Retrieves all the render objects managed by the class */
  91. readonly renderObjects: Array<IFluidRenderingRenderObject>;
  92. /** Retrieves all the render target renderers managed by the class */
  93. readonly targetRenderers: FluidRenderingTargetRenderer[];
  94. /**
  95. * Initializes the class
  96. * @param scene Scene in which the objects are part of
  97. */
  98. constructor(scene: Scene);
  99. /**
  100. * Reinitializes the class
  101. * Can be used if you change the object priority (FluidRenderingObject.priority), to make sure the objects are rendered in the right order
  102. */
  103. recreate(): void;
  104. /**
  105. * Gets the render object corresponding to a particle system (null if the particle system is not rendered as a fluid)
  106. * @param ps The particle system
  107. * @returns the render object corresponding to this particle system if any, otherwise null
  108. */
  109. getRenderObjectFromParticleSystem(ps: IParticleSystem): Nullable<IFluidRenderingRenderObject>;
  110. /**
  111. * Adds a particle system to the fluid renderer.
  112. * @param ps particle system
  113. * @param generateDiffuseTexture True if you want to generate a diffuse texture from the particle system and use it as part of the fluid rendering (default: false)
  114. * @param targetRenderer The target renderer used to display the particle system as a fluid. If not provided, the method will create a new one
  115. * @param camera The camera used by the target renderer (if the target renderer is created by the method)
  116. * @returns the render object corresponding to the particle system
  117. */
  118. addParticleSystem(ps: IParticleSystem, generateDiffuseTexture?: boolean, targetRenderer?: FluidRenderingTargetRenderer, camera?: Camera): IFluidRenderingRenderObject;
  119. /**
  120. * Adds a custom particle set to the fluid renderer.
  121. * @param buffers The list of buffers (should contain at least a "position" buffer!)
  122. * @param numParticles Number of particles in each buffer
  123. * @param generateDiffuseTexture True if you want to generate a diffuse texture from buffers and use it as part of the fluid rendering (default: false). For the texture to be generated correctly, you need a "color" buffer in the set!
  124. * @param targetRenderer The target renderer used to display the particle system as a fluid. If not provided, the method will create a new one
  125. * @param camera The camera used by the target renderer (if the target renderer is created by the method)
  126. * @returns the render object corresponding to the custom particle set
  127. */
  128. addCustomParticles(buffers: {
  129. [key: string]: FloatArray;
  130. }, numParticles: number, generateDiffuseTexture?: boolean, targetRenderer?: FluidRenderingTargetRenderer, camera?: Camera): IFluidRenderingRenderObject;
  131. /**
  132. * Removes a render object from the fluid renderer
  133. * @param renderObject the render object to remove
  134. * @param removeUnusedTargetRenderer True to remove/dispose of the target renderer if it's not used anymore (default: true)
  135. * @returns True if the render object has been found and released, else false
  136. */
  137. removeRenderObject(renderObject: IFluidRenderingRenderObject, removeUnusedTargetRenderer?: boolean): boolean;
  138. private _sortRenderingObjects;
  139. private _removeUnusedTargetRenderers;
  140. private _getParticleSystemIndex;
  141. private _initialize;
  142. private _setParticleSizeForRenderTargets;
  143. private _setUseVelocityForRenderObject;
  144. /** @internal */
  145. _prepareRendering(): void;
  146. /** @internal */
  147. _render(forCamera?: Camera): void;
  148. /**
  149. * Disposes of all the ressources used by the class
  150. */
  151. dispose(): void;
  152. }