giRSMManager.d.ts 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. /**
  2. * Reflective Shadow Maps were first described in http://www.klayge.org/material/3_12/GI/rsm.pdf by Carsten Dachsbacher and Marc Stamminger
  3. * Further explanations and implementations can be found in:
  4. * - Jaker video explaining RSM and its implementation: https://www.youtube.com/watch?v=LJQQdBsOYPM
  5. * - C++ implementation by Luis Angel: https://github.com/imyoungmin/RSM
  6. * - Javascript implementation by Erkaman: https://github.com/Erkaman/webgl-rsm
  7. */
  8. import type { Scene } from "../../scene.js";
  9. import type { GIRSM } from "./giRSM";
  10. import type { Material } from "../../Materials/material.js";
  11. import { MaterialPluginBase } from "../../Materials/materialPluginBase.js";
  12. import type { InternalTexture } from "../../Materials/Textures/internalTexture.js";
  13. import type { StandardMaterial } from "../../Materials/standardMaterial.js";
  14. import { PBRBaseMaterial } from "../../Materials/PBR/pbrBaseMaterial.js";
  15. import type { UniformBuffer } from "../../Materials/uniformBuffer.js";
  16. import { MaterialDefines } from "../../Materials/materialDefines.js";
  17. import "../../Shaders/bilateralBlur.fragment";
  18. import "../../Shaders/bilateralBlurQuality.fragment";
  19. import "../../Shaders/rsmGlobalIllumination.fragment";
  20. import "../../Shaders/rsmFullGlobalIllumination.fragment";
  21. /**
  22. * Class used to manage the global illumination contribution calculated from reflective shadow maps (RSM).
  23. */
  24. export declare class GIRSMManager {
  25. private _scene;
  26. private _engine;
  27. private _giRSM;
  28. private _materialsWithRenderPlugin;
  29. private _sampleTexture;
  30. private _maxSamples;
  31. private _blurRTT;
  32. private _blurPostProcesses;
  33. private _blurXPostprocess;
  34. private _blurYPostprocess;
  35. private _upsamplingXPostprocess;
  36. private _upsamplingYPostprocess;
  37. private _ppGlobalIllumination;
  38. private _drawPhaseObserver;
  39. private _debugLayer;
  40. private _counters;
  41. private _countersRTW;
  42. private _firstActivation;
  43. private _geomBufferEnabled;
  44. private _geomBufferEnablePosition;
  45. private _tempMatrix;
  46. private _enable;
  47. /**
  48. * Defines the default texture types and formats used by the geometry buffer renderer.
  49. */
  50. static GeometryBufferTextureTypesAndFormats: {
  51. [key: number]: {
  52. textureType: number;
  53. textureFormat: number;
  54. };
  55. };
  56. /**
  57. * Enables or disables the manager. Default is false.
  58. * If disabled, the global illumination won't be calculated and the scene will be rendered normally, without any global illumination contribution.
  59. */
  60. get enable(): boolean;
  61. set enable(enable: boolean);
  62. /**
  63. * Defines if the global illumination calculation is paused or not.
  64. * Use this setting to pause the global illumination calculation when you know that the scene (camera/mesh/light positions) is not changing anymore to save some GPU power.
  65. * The scene will still be rendered with the latest global illumination contribution.
  66. */
  67. pause: boolean;
  68. private _enableBlur;
  69. /**
  70. * Defines if the global illumination contribution should be blurred or not (using a bilateral blur). Default is true.
  71. */
  72. get enableBlur(): boolean;
  73. set enableBlur(enable: boolean);
  74. private _useQualityBlur;
  75. /**
  76. * Defines if the blur should be done with a better quality but slower or not. Default is false.
  77. */
  78. get useQualityBlur(): boolean;
  79. set useQualityBlur(enable: boolean);
  80. /**
  81. * Defines the depth threshold used by the bilateral blur post-processes (also used by the upsampling, if enabled).
  82. * You may have to change this value, depending on your scene.
  83. */
  84. blurDepthThreshold: number;
  85. /**
  86. * Defines the normal threshold used by the bilateral blur post-processes (also used by the upsampling, if enabled).
  87. * You may have to change this value, depending on your scene.
  88. */
  89. blurNormalThreshold: number;
  90. /**
  91. * Defines the kernel size used by the bilateral blur post-processes. Default is 12.
  92. */
  93. blurKernel: number;
  94. private _forceFullSizeBlur;
  95. /**
  96. * Defines if the blur should be done at full resolution or not. Default is false.
  97. * If this setting is enabled, upampling will be disabled (ignored) as it is not needed anymore.
  98. */
  99. get fullSizeBlur(): boolean;
  100. set fullSizeBlur(mode: boolean);
  101. private _useQualityUpsampling;
  102. /**
  103. * Defines if the upsampling should be done with a better quality but slower or not. Default is false.
  104. */
  105. get useQualityUpsampling(): boolean;
  106. set useQualityUpsampling(enable: boolean);
  107. /**
  108. * Defines the kernel size used by the bilateral upsampling post-processes. Default is 6.
  109. */
  110. upsamplerKernel: number;
  111. private _showOnlyGI;
  112. /**
  113. * Defines if the debug layer should be enabled or not. Default is false.
  114. * Use this setting for debugging purpose, to show the global illumination contribution only.
  115. */
  116. get showOnlyGI(): boolean;
  117. set showOnlyGI(show: boolean);
  118. private _outputDimensions;
  119. /**
  120. * Sets the output dimensions of the final process. It should normally be the same as the output dimensions of the screen.
  121. * @param dimensions The dimensions of the output texture (width and height)
  122. */
  123. setOutputDimensions(dimensions: {
  124. width: number;
  125. height: number;
  126. }): void;
  127. private _giTextureDimensions;
  128. /**
  129. * Sets the dimensions of the GI texture. Try to use the smallest size possible for better performance.
  130. * @param dimensions The dimensions of the GI texture (width and height)
  131. */
  132. setGITextureDimensions(dimensions: {
  133. width: number;
  134. height: number;
  135. }): void;
  136. private _giTextureType;
  137. /**
  138. * Gets or sets the texture type used by the GI texture. Default is Constants.TEXTURETYPE_UNSIGNED_INT_2_10_10_10_REV.
  139. */
  140. get giTextureType(): number;
  141. set giTextureType(textureType: number);
  142. /**
  143. * Gets the list of GIRSM used by the manager.
  144. */
  145. get giRSM(): GIRSM[];
  146. /**
  147. * Adds a (list of) GIRSM to the manager.
  148. * @param rsm The GIRSM (or array of GIRSM) to add to the manager
  149. */
  150. addGIRSM(rsm: GIRSM | GIRSM[]): void;
  151. /**
  152. * Removes a (list of) GIRSM from the manager.
  153. * @param rsm The GIRSM (or array of GIRSM) to remove from the manager
  154. */
  155. removeGIRSM(rsm: GIRSM | GIRSM[]): void;
  156. /**
  157. * Add a material to the manager. This will enable the global illumination contribution for the material.
  158. * @param material Material that will be affected by the global illumination contribution. If not provided, all materials of the scene will be affected.
  159. */
  160. addMaterial(material?: Material): void;
  161. /**
  162. * Gets the list of GPU counters used by the manager.
  163. * GPU timing measurements must be enabled for the counters to be filled (engine.enableGPUTimingMeasurements = true).
  164. * Only available with WebGPU. You will still get the list of counters with other engines but the values will always be 0.
  165. */
  166. get countersGPU(): Array<{
  167. name: string;
  168. value: number;
  169. }>;
  170. /**
  171. * Recreates the resources used by the manager.
  172. * You should normally not have to call this method manually, except if you change the useFullTexture property of a GIRSM, because the manager won't track this change.
  173. * @param disposeGeometryBufferRenderer Defines if the geometry buffer renderer should be disposed and recreated. Default is false.
  174. */
  175. recreateResources(disposeGeometryBufferRenderer?: boolean): void;
  176. /**
  177. * Generates the sample texture used by the the global illumination calculation process.
  178. * @param maxSamples The maximum number of samples to generate in the texture. Default value is 2048. The numSamples property of the GIRSM should be less than or equal to this value!
  179. */
  180. generateSampleTexture(maxSamples: number): void;
  181. /**
  182. * Disposes the manager.
  183. */
  184. dispose(): void;
  185. /**
  186. * Creates a new GIRSMManager
  187. * @param scene The scene
  188. * @param outputDimensions The dimensions of the output texture (width and height). Should normally be the same as the output dimensions of the screen.
  189. * @param giTextureDimensions The dimensions of the GI texture (width and height). Try to use the smallest size possible for better performance.
  190. * @param maxSamples The maximum number of samples to generate in the sample texture. Default value is 2048. The numSamples property of the GIRSM should be less than or equal to this value!
  191. * @param giTextureType The texture type used by the GI texture. Default is Constants.TEXTURETYPE_UNSIGNED_INT_2_10_10_10_REV.
  192. */
  193. constructor(scene: Scene, outputDimensions: {
  194. width: number;
  195. height: number;
  196. }, giTextureDimensions?: {
  197. width: number;
  198. height: number;
  199. }, maxSamples?: number, giTextureType?: number);
  200. protected _disposePostProcesses(disposeGeometryBufferRenderer?: boolean): void;
  201. protected _setPluginParameters(): void;
  202. protected _createPostProcesses(): void;
  203. protected _addGISupportToMaterial(material: Material): void;
  204. }
  205. /**
  206. * @internal
  207. */
  208. declare class MaterialGIRSMRenderDefines extends MaterialDefines {
  209. RENDER_WITH_GIRSM: boolean;
  210. RSMCREATE_PROJTEXTURE: boolean;
  211. }
  212. /**
  213. * Plugin used to render the global illumination contribution.
  214. */
  215. export declare class GIRSMRenderPluginMaterial extends MaterialPluginBase {
  216. private _isPBR;
  217. /**
  218. * Defines the name of the plugin.
  219. */
  220. static readonly Name = "GIRSMRender";
  221. /**
  222. * The texture containing the global illumination contribution.
  223. */
  224. textureGIContrib: InternalTexture;
  225. /**
  226. * The width of the output texture.
  227. */
  228. outputTextureWidth: number;
  229. /**
  230. * The height of the output texture.
  231. */
  232. outputTextureHeight: number;
  233. private _isEnabled;
  234. /**
  235. * Defines if the plugin is enabled in the material.
  236. */
  237. isEnabled: boolean;
  238. protected _markAllSubMeshesAsTexturesDirty(): void;
  239. private _internalMarkAllSubMeshesAsTexturesDirty;
  240. constructor(material: Material | StandardMaterial | PBRBaseMaterial);
  241. prepareDefines(defines: MaterialGIRSMRenderDefines): void;
  242. getClassName(): string;
  243. getUniforms(): {
  244. ubo: {
  245. name: string;
  246. size: number;
  247. type: string;
  248. }[];
  249. fragment: string;
  250. };
  251. getSamplers(samplers: string[]): void;
  252. bindForSubMesh(uniformBuffer: UniformBuffer): void;
  253. getCustomCode(shaderType: string): {
  254. [name: string]: string;
  255. } | null;
  256. }
  257. export {};