@babylonjs/core 7.22.3 → 7.22.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (180) hide show
  1. package/Animations/animationGroup.js +1 -1
  2. package/Animations/animationGroup.js.map +1 -1
  3. package/Engines/abstractEngine.js +2 -2
  4. package/Engines/abstractEngine.js.map +1 -1
  5. package/Engines/constants.d.ts +21 -1
  6. package/Engines/constants.js +21 -1
  7. package/Engines/constants.js.map +1 -1
  8. package/Engines/engineFeatures.d.ts +2 -0
  9. package/Engines/engineFeatures.js.map +1 -1
  10. package/Engines/nativeEngine.js +1 -0
  11. package/Engines/nativeEngine.js.map +1 -1
  12. package/Engines/nullEngine.js +1 -0
  13. package/Engines/nullEngine.js.map +1 -1
  14. package/Engines/thinEngine.js +2 -0
  15. package/Engines/thinEngine.js.map +1 -1
  16. package/Engines/webgpuEngine.js +1 -0
  17. package/Engines/webgpuEngine.js.map +1 -1
  18. package/Materials/Node/Blocks/Fragment/prePassOutputBlock.d.ts +12 -0
  19. package/Materials/Node/Blocks/Fragment/prePassOutputBlock.js +51 -0
  20. package/Materials/Node/Blocks/Fragment/prePassOutputBlock.js.map +1 -1
  21. package/Materials/Node/Blocks/Input/prePassTextureBlock.d.ts +27 -0
  22. package/Materials/Node/Blocks/Input/prePassTextureBlock.js +69 -0
  23. package/Materials/Node/Blocks/Input/prePassTextureBlock.js.map +1 -1
  24. package/Materials/Node/nodeMaterial.d.ts +12 -0
  25. package/Materials/Node/nodeMaterial.js +24 -0
  26. package/Materials/Node/nodeMaterial.js.map +1 -1
  27. package/Materials/PBR/pbrBaseMaterial.d.ts +8 -0
  28. package/Materials/PBR/pbrBaseMaterial.js +8 -0
  29. package/Materials/PBR/pbrBaseMaterial.js.map +1 -1
  30. package/Materials/Textures/Procedurals/proceduralTexture.d.ts +4 -0
  31. package/Materials/Textures/Procedurals/proceduralTexture.js +19 -5
  32. package/Materials/Textures/Procedurals/proceduralTexture.js.map +1 -1
  33. package/Materials/effectRenderer.d.ts +4 -0
  34. package/Materials/effectRenderer.js +10 -10
  35. package/Materials/effectRenderer.js.map +1 -1
  36. package/Materials/materialHelper.functions.js +20 -0
  37. package/Materials/materialHelper.functions.js.map +1 -1
  38. package/Materials/prePassConfiguration.js +2 -1
  39. package/Materials/prePassConfiguration.js.map +1 -1
  40. package/Materials/standardMaterial.d.ts +8 -0
  41. package/Materials/standardMaterial.js +8 -0
  42. package/Materials/standardMaterial.js.map +1 -1
  43. package/Misc/fileTools.js +1 -1
  44. package/Misc/fileTools.js.map +1 -1
  45. package/PostProcesses/postProcessManager.d.ts +2 -0
  46. package/PostProcesses/postProcessManager.js +3 -0
  47. package/PostProcesses/postProcessManager.js.map +1 -1
  48. package/PostProcesses/volumetricLightScatteringPostProcess.js +79 -8
  49. package/PostProcesses/volumetricLightScatteringPostProcess.js.map +1 -1
  50. package/Rendering/IBLShadows/iblShadowsAccumulationPass.d.ts +88 -0
  51. package/Rendering/IBLShadows/iblShadowsAccumulationPass.js +240 -0
  52. package/Rendering/IBLShadows/iblShadowsAccumulationPass.js.map +1 -0
  53. package/Rendering/IBLShadows/iblShadowsImportanceSamplingRenderer.d.ts +88 -0
  54. package/Rendering/IBLShadows/iblShadowsImportanceSamplingRenderer.js +231 -0
  55. package/Rendering/IBLShadows/iblShadowsImportanceSamplingRenderer.js.map +1 -0
  56. package/Rendering/IBLShadows/iblShadowsRenderPipeline.d.ts +340 -0
  57. package/Rendering/IBLShadows/iblShadowsRenderPipeline.js +884 -0
  58. package/Rendering/IBLShadows/iblShadowsRenderPipeline.js.map +1 -0
  59. package/Rendering/IBLShadows/iblShadowsSpatialBlurPass.d.ts +67 -0
  60. package/Rendering/IBLShadows/iblShadowsSpatialBlurPass.js +139 -0
  61. package/Rendering/IBLShadows/iblShadowsSpatialBlurPass.js.map +1 -0
  62. package/Rendering/IBLShadows/iblShadowsVoxelRenderer.d.ts +168 -0
  63. package/Rendering/IBLShadows/iblShadowsVoxelRenderer.js +597 -0
  64. package/Rendering/IBLShadows/iblShadowsVoxelRenderer.js.map +1 -0
  65. package/Rendering/IBLShadows/iblShadowsVoxelTracingPass.d.ts +151 -0
  66. package/Rendering/IBLShadows/iblShadowsVoxelTracingPass.js +291 -0
  67. package/Rendering/IBLShadows/iblShadowsVoxelTracingPass.js.map +1 -0
  68. package/Rendering/depthRenderer.js +44 -23
  69. package/Rendering/depthRenderer.js.map +1 -1
  70. package/Rendering/index.d.ts +1 -0
  71. package/Rendering/index.js +1 -0
  72. package/Rendering/index.js.map +1 -1
  73. package/Rendering/outlineRenderer.js +3 -3
  74. package/Rendering/outlineRenderer.js.map +1 -1
  75. package/Rendering/prePassRenderer.js +25 -1
  76. package/Rendering/prePassRenderer.js.map +1 -1
  77. package/Shaders/ShadersInclude/instancesDeclaration.js +4 -2
  78. package/Shaders/ShadersInclude/instancesDeclaration.js.map +1 -1
  79. package/Shaders/ShadersInclude/instancesVertex.js +8 -4
  80. package/Shaders/ShadersInclude/instancesVertex.js.map +1 -1
  81. package/Shaders/ShadersInclude/prePassDeclaration.js +4 -1
  82. package/Shaders/ShadersInclude/prePassDeclaration.js.map +1 -1
  83. package/Shaders/ShadersInclude/prePassVertex.js +5 -1
  84. package/Shaders/ShadersInclude/prePassVertex.js.map +1 -1
  85. package/Shaders/ShadersInclude/prePassVertexDeclaration.js +4 -1
  86. package/Shaders/ShadersInclude/prePassVertexDeclaration.js.map +1 -1
  87. package/Shaders/combineVoxelGrids.fragment.d.ts +5 -0
  88. package/Shaders/combineVoxelGrids.fragment.js +9 -0
  89. package/Shaders/combineVoxelGrids.fragment.js.map +1 -0
  90. package/Shaders/copyTexture3DLayerToTexture.fragment.d.ts +5 -0
  91. package/Shaders/copyTexture3DLayerToTexture.fragment.js +10 -0
  92. package/Shaders/copyTexture3DLayerToTexture.fragment.js.map +1 -0
  93. package/Shaders/default.fragment.js +31 -6
  94. package/Shaders/default.fragment.js.map +1 -1
  95. package/Shaders/default.vertex.js +6 -2
  96. package/Shaders/default.vertex.js.map +1 -1
  97. package/Shaders/generateVoxelMip.fragment.d.ts +5 -0
  98. package/Shaders/generateVoxelMip.fragment.js +25 -0
  99. package/Shaders/generateVoxelMip.fragment.js.map +1 -0
  100. package/Shaders/geometry.fragment.js +1 -1
  101. package/Shaders/geometry.fragment.js.map +1 -1
  102. package/Shaders/iblShadowAccumulation.fragment.d.ts +5 -0
  103. package/Shaders/iblShadowAccumulation.fragment.js +27 -0
  104. package/Shaders/iblShadowAccumulation.fragment.js.map +1 -0
  105. package/Shaders/iblShadowDebug.fragment.d.ts +5 -0
  106. package/Shaders/iblShadowDebug.fragment.js +18 -0
  107. package/Shaders/iblShadowDebug.fragment.js.map +1 -0
  108. package/Shaders/iblShadowGBufferDebug.fragment.d.ts +5 -0
  109. package/Shaders/iblShadowGBufferDebug.fragment.js +19 -0
  110. package/Shaders/iblShadowGBufferDebug.fragment.js.map +1 -0
  111. package/Shaders/iblShadowSpatialBlur.fragment.d.ts +5 -0
  112. package/Shaders/iblShadowSpatialBlur.fragment.js +21 -0
  113. package/Shaders/iblShadowSpatialBlur.fragment.js.map +1 -0
  114. package/Shaders/iblShadowVoxelTracing.fragment.d.ts +5 -0
  115. package/Shaders/iblShadowVoxelTracing.fragment.js +152 -0
  116. package/Shaders/iblShadowVoxelTracing.fragment.js.map +1 -0
  117. package/Shaders/iblShadowsCdfx.fragment.d.ts +5 -0
  118. package/Shaders/iblShadowsCdfx.fragment.js +12 -0
  119. package/Shaders/iblShadowsCdfx.fragment.js.map +1 -0
  120. package/Shaders/iblShadowsCdfy.fragment.d.ts +5 -0
  121. package/Shaders/iblShadowsCdfy.fragment.js +33 -0
  122. package/Shaders/iblShadowsCdfy.fragment.js.map +1 -0
  123. package/Shaders/iblShadowsCombine.fragment.d.ts +5 -0
  124. package/Shaders/iblShadowsCombine.fragment.js +10 -0
  125. package/Shaders/iblShadowsCombine.fragment.js.map +1 -0
  126. package/Shaders/iblShadowsIcdfx.fragment.d.ts +5 -0
  127. package/Shaders/iblShadowsIcdfx.fragment.js +19 -0
  128. package/Shaders/iblShadowsIcdfx.fragment.js.map +1 -0
  129. package/Shaders/iblShadowsIcdfy.fragment.d.ts +5 -0
  130. package/Shaders/iblShadowsIcdfy.fragment.js +19 -0
  131. package/Shaders/iblShadowsIcdfy.fragment.js.map +1 -0
  132. package/Shaders/iblShadowsImportanceSamplingDebug.fragment.d.ts +5 -0
  133. package/Shaders/iblShadowsImportanceSamplingDebug.fragment.js +48 -0
  134. package/Shaders/iblShadowsImportanceSamplingDebug.fragment.js.map +1 -0
  135. package/Shaders/pbr.fragment.js +32 -7
  136. package/Shaders/pbr.fragment.js.map +1 -1
  137. package/Shaders/pbr.vertex.js +3 -1
  138. package/Shaders/pbr.vertex.js.map +1 -1
  139. package/Shaders/voxelGrid.fragment.d.ts +5 -0
  140. package/Shaders/voxelGrid.fragment.js +14 -0
  141. package/Shaders/voxelGrid.fragment.js.map +1 -0
  142. package/Shaders/voxelGrid.vertex.d.ts +5 -0
  143. package/Shaders/voxelGrid.vertex.js +9 -0
  144. package/Shaders/voxelGrid.vertex.js.map +1 -0
  145. package/Shaders/voxelGrid2dArrayDebug.fragment.d.ts +5 -0
  146. package/Shaders/voxelGrid2dArrayDebug.fragment.js +9 -0
  147. package/Shaders/voxelGrid2dArrayDebug.fragment.js.map +1 -0
  148. package/Shaders/voxelGrid3dDebug.fragment.d.ts +5 -0
  149. package/Shaders/voxelGrid3dDebug.fragment.js +22 -0
  150. package/Shaders/voxelGrid3dDebug.fragment.js.map +1 -0
  151. package/Shaders/voxelSlabDebug.fragment.d.ts +5 -0
  152. package/Shaders/voxelSlabDebug.fragment.js +11 -0
  153. package/Shaders/voxelSlabDebug.fragment.js.map +1 -0
  154. package/Shaders/voxelSlabDebug.vertex.d.ts +5 -0
  155. package/Shaders/voxelSlabDebug.vertex.js +9 -0
  156. package/Shaders/voxelSlabDebug.vertex.js.map +1 -0
  157. package/ShadersWGSL/ShadersInclude/instancesDeclaration.js +4 -2
  158. package/ShadersWGSL/ShadersInclude/instancesDeclaration.js.map +1 -1
  159. package/ShadersWGSL/ShadersInclude/instancesVertex.js +9 -4
  160. package/ShadersWGSL/ShadersInclude/instancesVertex.js.map +1 -1
  161. package/ShadersWGSL/ShadersInclude/prePassDeclaration.js +4 -1
  162. package/ShadersWGSL/ShadersInclude/prePassDeclaration.js.map +1 -1
  163. package/ShadersWGSL/ShadersInclude/prePassVertex.js +5 -1
  164. package/ShadersWGSL/ShadersInclude/prePassVertex.js.map +1 -1
  165. package/ShadersWGSL/ShadersInclude/prePassVertexDeclaration.js +4 -1
  166. package/ShadersWGSL/ShadersInclude/prePassVertexDeclaration.js.map +1 -1
  167. package/ShadersWGSL/default.fragment.js +42 -16
  168. package/ShadersWGSL/default.fragment.js.map +1 -1
  169. package/ShadersWGSL/default.vertex.js +5 -2
  170. package/ShadersWGSL/default.vertex.js.map +1 -1
  171. package/ShadersWGSL/geometry.fragment.js +1 -1
  172. package/ShadersWGSL/geometry.fragment.js.map +1 -1
  173. package/ShadersWGSL/pbr.fragment.js +37 -20
  174. package/ShadersWGSL/pbr.fragment.js.map +1 -1
  175. package/ShadersWGSL/pbr.vertex.js +1 -1
  176. package/ShadersWGSL/pbr.vertex.js.map +1 -1
  177. package/package.json +1 -1
  178. package/sceneComponent.d.ts +1 -0
  179. package/sceneComponent.js +1 -0
  180. package/sceneComponent.js.map +1 -1
@@ -0,0 +1,88 @@
1
+ import type { Scene } from "../../scene";
2
+ import { ProceduralTexture } from "../../Materials/Textures/Procedurals/proceduralTexture";
3
+ import "../../Shaders/iblShadowsImportanceSamplingDebug.fragment";
4
+ import "../../Shaders/iblShadowsCdfx.fragment";
5
+ import "../../Shaders/iblShadowsIcdfx.fragment";
6
+ import "../../Shaders/iblShadowsCdfy.fragment";
7
+ import "../../Shaders/iblShadowsIcdfy.fragment";
8
+ import { PostProcess } from "../../PostProcesses/postProcess";
9
+ import type { BaseTexture } from "../../Materials/Textures/baseTexture";
10
+ import { Observable } from "../../Misc/observable";
11
+ /**
12
+ * Build cdf maps for IBL importance sampling during IBL shadow computation.
13
+ * This should not be instanciated directly, as it is part of a scene component
14
+ * @internal
15
+ */
16
+ export declare class _IblShadowsImportanceSamplingRenderer {
17
+ private _scene;
18
+ private _engine;
19
+ private _cdfyPT;
20
+ private _icdfyPT;
21
+ private _cdfxPT;
22
+ private _icdfxPT;
23
+ private _iblSource;
24
+ /**
25
+ * Gets the IBL source texture being used by the importance sampling renderer
26
+ */
27
+ get iblSource(): BaseTexture;
28
+ /**
29
+ * Sets the IBL source texture to be used by the importance sampling renderer.
30
+ * This will trigger recreation of the importance sampling assets.
31
+ */
32
+ set iblSource(source: BaseTexture);
33
+ private _recreateAssetsFromNewIbl;
34
+ /**
35
+ * Return the cumulative distribution function (CDF) Y texture
36
+ * @returns Return the cumulative distribution function (CDF) Y texture
37
+ */
38
+ getIcdfyTexture(): ProceduralTexture;
39
+ /**
40
+ * Return the cumulative distribution function (CDF) X texture
41
+ * @returns Return the cumulative distribution function (CDF) X texture
42
+ */
43
+ getIcdfxTexture(): ProceduralTexture;
44
+ /** Enable the debug view for this pass */
45
+ debugEnabled: boolean;
46
+ private _debugPass;
47
+ private _debugSizeParams;
48
+ /**
49
+ * Sets params that control the position and scaling of the debug display on the screen.
50
+ * @param x Screen X offset of the debug display (0-1)
51
+ * @param y Screen Y offset of the debug display (0-1)
52
+ * @param widthScale X scale of the debug display (0-1)
53
+ * @param heightScale Y scale of the debug display (0-1)
54
+ */
55
+ setDebugDisplayParams(x: number, y: number, widthScale: number, heightScale: number): void;
56
+ /**
57
+ * The name of the debug pass post process
58
+ */
59
+ get debugPassName(): string;
60
+ private _debugPassName;
61
+ /**
62
+ * Gets the debug pass post process
63
+ * @returns The post process
64
+ */
65
+ getDebugPassPP(): PostProcess;
66
+ /**
67
+ * Instanciates the importance sampling renderer
68
+ * @param scene Scene to attach to
69
+ * @returns The importance sampling renderer
70
+ */
71
+ constructor(scene: Scene);
72
+ /**
73
+ * Observable that triggers when the importance sampling renderer is ready
74
+ */
75
+ onReadyObservable: Observable<void>;
76
+ private _createTextures;
77
+ private _disposeTextures;
78
+ private _createDebugPass;
79
+ /**
80
+ * Checks if the importance sampling renderer is ready
81
+ * @returns true if the importance sampling renderer is ready
82
+ */
83
+ isReady(): boolean;
84
+ /**
85
+ * Disposes the importance sampling renderer and associated resources
86
+ */
87
+ dispose(): void;
88
+ }
@@ -0,0 +1,231 @@
1
+
2
+ import { Texture } from "../../Materials/Textures/texture.js";
3
+ import { ProceduralTexture } from "../../Materials/Textures/Procedurals/proceduralTexture.js";
4
+ import "../../Shaders/iblShadowsImportanceSamplingDebug.fragment.js";
5
+ import "../../Shaders/iblShadowsCdfx.fragment.js";
6
+ import "../../Shaders/iblShadowsIcdfx.fragment.js";
7
+ import "../../Shaders/iblShadowsCdfy.fragment.js";
8
+ import "../../Shaders/iblShadowsIcdfy.fragment.js";
9
+ import { PostProcess } from "../../PostProcesses/postProcess.js";
10
+ import { Vector4 } from "../../Maths/math.vector.js";
11
+ import { RawTexture } from "../../Materials/Textures/rawTexture.js";
12
+ import { Observable } from "../../Misc/observable.js";
13
+ import { HDRCubeTexture } from "../../Materials/Textures/hdrCubeTexture.js";
14
+ /**
15
+ * Build cdf maps for IBL importance sampling during IBL shadow computation.
16
+ * This should not be instanciated directly, as it is part of a scene component
17
+ * @internal
18
+ */
19
+ export class _IblShadowsImportanceSamplingRenderer {
20
+ /**
21
+ * Gets the IBL source texture being used by the importance sampling renderer
22
+ */
23
+ get iblSource() {
24
+ return this._iblSource;
25
+ }
26
+ /**
27
+ * Sets the IBL source texture to be used by the importance sampling renderer.
28
+ * This will trigger recreation of the importance sampling assets.
29
+ */
30
+ set iblSource(source) {
31
+ if (this._iblSource === source) {
32
+ return;
33
+ }
34
+ if (source instanceof Texture) {
35
+ if (source.isReady()) {
36
+ this._recreateAssetsFromNewIbl(source);
37
+ }
38
+ else {
39
+ source.onLoadObservable.addOnce(this._recreateAssetsFromNewIbl);
40
+ }
41
+ }
42
+ else if (source instanceof HDRCubeTexture) {
43
+ if (source.isReady()) {
44
+ this._recreateAssetsFromNewIbl(source);
45
+ }
46
+ else {
47
+ source.onLoadObservable.addOnce(this._recreateAssetsFromNewIbl.bind(this, source));
48
+ }
49
+ }
50
+ }
51
+ _recreateAssetsFromNewIbl(source) {
52
+ if (this._debugPass) {
53
+ this._debugPass.dispose();
54
+ }
55
+ this._disposeTextures();
56
+ this._iblSource = source;
57
+ this._createTextures();
58
+ if (this._debugPass) {
59
+ // Recreate the debug pass because of the new textures
60
+ this._createDebugPass();
61
+ }
62
+ // Once the textures are generated, notify that they are ready to use.
63
+ this._icdfxPT.onGeneratedObservable.addOnce(() => {
64
+ this.onReadyObservable.notifyObservers();
65
+ });
66
+ }
67
+ /**
68
+ * Return the cumulative distribution function (CDF) Y texture
69
+ * @returns Return the cumulative distribution function (CDF) Y texture
70
+ */
71
+ getIcdfyTexture() {
72
+ return this._icdfyPT;
73
+ }
74
+ /**
75
+ * Return the cumulative distribution function (CDF) X texture
76
+ * @returns Return the cumulative distribution function (CDF) X texture
77
+ */
78
+ getIcdfxTexture() {
79
+ return this._icdfxPT;
80
+ }
81
+ /**
82
+ * Sets params that control the position and scaling of the debug display on the screen.
83
+ * @param x Screen X offset of the debug display (0-1)
84
+ * @param y Screen Y offset of the debug display (0-1)
85
+ * @param widthScale X scale of the debug display (0-1)
86
+ * @param heightScale Y scale of the debug display (0-1)
87
+ */
88
+ setDebugDisplayParams(x, y, widthScale, heightScale) {
89
+ this._debugSizeParams.set(x, y, widthScale, heightScale);
90
+ }
91
+ /**
92
+ * The name of the debug pass post process
93
+ */
94
+ get debugPassName() {
95
+ return this._debugPassName;
96
+ }
97
+ /**
98
+ * Gets the debug pass post process
99
+ * @returns The post process
100
+ */
101
+ getDebugPassPP() {
102
+ if (!this._debugPass) {
103
+ this._createDebugPass();
104
+ }
105
+ return this._debugPass;
106
+ }
107
+ /**
108
+ * Instanciates the importance sampling renderer
109
+ * @param scene Scene to attach to
110
+ * @returns The importance sampling renderer
111
+ */
112
+ constructor(scene) {
113
+ /** Enable the debug view for this pass */
114
+ this.debugEnabled = false;
115
+ this._debugSizeParams = new Vector4(0.0, 0.0, 0.0, 0.0);
116
+ this._debugPassName = "Importance Sample Debug";
117
+ /**
118
+ * Observable that triggers when the importance sampling renderer is ready
119
+ */
120
+ this.onReadyObservable = new Observable();
121
+ this._scene = scene;
122
+ this._engine = scene.getEngine();
123
+ }
124
+ _createTextures() {
125
+ const size = this._iblSource ? this._iblSource.getSize() : { width: 1, height: 1 };
126
+ if (!this._iblSource) {
127
+ this._iblSource = RawTexture.CreateRTexture(new Uint8Array([255]), 1, 1, this._scene, false, false, 1, 0);
128
+ this._iblSource.name = "Placeholder IBL Source";
129
+ }
130
+ if (this._iblSource.isCube) {
131
+ size.width *= 4;
132
+ size.height *= 2;
133
+ }
134
+ // Create CDF maps (Cumulative Distribution Function) to assist in importance sampling
135
+ const cdfOptions = {
136
+ generateDepthBuffer: false,
137
+ generateMipMaps: false,
138
+ format: 6,
139
+ type: 1,
140
+ samplingMode: 1,
141
+ };
142
+ const icdfOptions = {
143
+ generateDepthBuffer: false,
144
+ generateMipMaps: false,
145
+ format: 6,
146
+ type: 2,
147
+ samplingMode: 1,
148
+ };
149
+ this._cdfyPT = new ProceduralTexture("cdfyTexture", { width: size.width, height: size.height + 1 }, "iblShadowsCdfy", this._scene, cdfOptions, false, false);
150
+ this._cdfyPT.autoClear = false;
151
+ this._cdfyPT.setTexture("iblSource", this._iblSource);
152
+ this._cdfyPT.setInt("iblHeight", size.height);
153
+ if (this._iblSource.isCube) {
154
+ this._cdfyPT.defines = "#define IBL_USE_CUBE_MAP\n";
155
+ }
156
+ this._cdfyPT.refreshRate = 0;
157
+ this._icdfyPT = new ProceduralTexture("icdfyTexture", { width: size.width, height: size.height }, "iblShadowsIcdfy", this._scene, icdfOptions, false, false);
158
+ this._icdfyPT.autoClear = false;
159
+ this._icdfyPT.setTexture("cdfy", this._cdfyPT);
160
+ this._icdfyPT.refreshRate = 0;
161
+ this._cdfxPT = new ProceduralTexture("cdfxTexture", { width: size.width + 1, height: 1 }, "iblShadowsCdfx", this._scene, cdfOptions, false, false);
162
+ this._cdfxPT.autoClear = false;
163
+ this._cdfxPT.setTexture("cdfy", this._cdfyPT);
164
+ this._cdfxPT.refreshRate = 0;
165
+ this._icdfxPT = new ProceduralTexture("icdfxTexture", { width: size.width, height: 1 }, "iblShadowsIcdfx", this._scene, icdfOptions, false, false);
166
+ this._icdfxPT.autoClear = false;
167
+ this._icdfxPT.setTexture("cdfx", this._cdfxPT);
168
+ this._icdfxPT.refreshRate = 0;
169
+ }
170
+ _disposeTextures() {
171
+ this._cdfyPT?.dispose();
172
+ this._icdfyPT?.dispose();
173
+ this._cdfxPT?.dispose();
174
+ this._icdfxPT?.dispose();
175
+ this._iblSource?.dispose();
176
+ }
177
+ _createDebugPass() {
178
+ if (this._debugPass) {
179
+ this._debugPass.dispose();
180
+ }
181
+ const debugOptions = {
182
+ width: this._scene.getEngine().getRenderWidth(),
183
+ height: this._scene.getEngine().getRenderHeight(),
184
+ samplingMode: Texture.BILINEAR_SAMPLINGMODE,
185
+ engine: this._engine,
186
+ textureType: 0,
187
+ uniforms: ["sizeParams"],
188
+ samplers: ["cdfy", "icdfy", "cdfx", "icdfx", "iblSource"],
189
+ defines: this._iblSource?.isCube ? "#define IBL_USE_CUBE_MAP\n" : "",
190
+ };
191
+ this._debugPass = new PostProcess(this._debugPassName, "iblShadowsImportanceSamplingDebug", debugOptions);
192
+ const debugEffect = this._debugPass.getEffect();
193
+ if (debugEffect) {
194
+ debugEffect.defines = this._iblSource?.isCube ? "#define IBL_USE_CUBE_MAP\n" : "";
195
+ }
196
+ if (this._iblSource?.isCube) {
197
+ this._debugPass.updateEffect("#define IBL_USE_CUBE_MAP\n");
198
+ }
199
+ this._debugPass.onApplyObservable.add((effect) => {
200
+ effect.setTexture("cdfy", this._cdfyPT);
201
+ effect.setTexture("icdfy", this._icdfyPT);
202
+ effect.setTexture("cdfx", this._cdfxPT);
203
+ effect.setTexture("icdfx", this._icdfxPT);
204
+ effect.setTexture("iblSource", this._iblSource);
205
+ effect.setFloat4("sizeParams", this._debugSizeParams.x, this._debugSizeParams.y, this._debugSizeParams.z, this._debugSizeParams.w);
206
+ });
207
+ }
208
+ /**
209
+ * Checks if the importance sampling renderer is ready
210
+ * @returns true if the importance sampling renderer is ready
211
+ */
212
+ isReady() {
213
+ return (this._iblSource &&
214
+ this._iblSource.name !== "Placeholder IBL Source" &&
215
+ this._iblSource.isReady() &&
216
+ this._cdfyPT.isReady() &&
217
+ this._icdfyPT.isReady() &&
218
+ this._cdfxPT.isReady() &&
219
+ this._icdfxPT.isReady());
220
+ }
221
+ /**
222
+ * Disposes the importance sampling renderer and associated resources
223
+ */
224
+ dispose() {
225
+ this._disposeTextures();
226
+ if (this._debugPass) {
227
+ this._debugPass.dispose();
228
+ }
229
+ }
230
+ }
231
+ //# sourceMappingURL=iblShadowsImportanceSamplingRenderer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"iblShadowsImportanceSamplingRenderer.js","sourceRoot":"","sources":["../../../../../dev/core/src/Rendering/IBLShadows/iblShadowsImportanceSamplingRenderer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAIpD,OAAO,EAAE,OAAO,EAAE,MAAM,kCAAkC,CAAC;AAE3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wDAAwD,CAAC;AAE3F,OAAO,0DAA0D,CAAC;AAClE,OAAO,uCAAuC,CAAC;AAC/C,OAAO,wCAAwC,CAAC;AAChD,OAAO,uCAAuC,CAAC;AAC/C,OAAO,wCAAwC,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAE9D,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,qCAAqC,CAAC;AAEjE,OAA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,IAAI,KAAK,wBAAwB;YACjD,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE;YACzB,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE;YACtB,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE;YACvB,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE;YACtB,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAC1B,CAAC;IACN,CAAC;IAED;;OAEG;IACI,OAAO;QACV,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACxB,IAAI,IAAI,CAAC,UAAU,EAAE;YACjB,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;SAC7B;IACL,CAAC;CACJ","sourcesContent":["import { Constants } from \"../../Engines/constants\";\r\nimport type { AbstractEngine } from \"../../Engines/abstractEngine\";\r\n\r\nimport type { Scene } from \"../../scene\";\r\nimport { Texture } from \"../../Materials/Textures/texture\";\r\nimport type { TextureSize } from \"../../Materials/Textures/textureCreationOptions\";\r\nimport { ProceduralTexture } from \"../../Materials/Textures/Procedurals/proceduralTexture\";\r\nimport type { IProceduralTextureCreationOptions } from \"../../Materials/Textures/Procedurals/proceduralTexture\";\r\nimport \"../../Shaders/iblShadowsImportanceSamplingDebug.fragment\";\r\nimport \"../../Shaders/iblShadowsCdfx.fragment\";\r\nimport \"../../Shaders/iblShadowsIcdfx.fragment\";\r\nimport \"../../Shaders/iblShadowsCdfy.fragment\";\r\nimport \"../../Shaders/iblShadowsIcdfy.fragment\";\r\nimport { PostProcess } from \"../../PostProcesses/postProcess\";\r\nimport type { PostProcessOptions } from \"../../PostProcesses/postProcess\";\r\nimport { Vector4 } from \"../../Maths/math.vector\";\r\nimport { RawTexture } from \"../../Materials/Textures/rawTexture\";\r\nimport type { BaseTexture } from \"../../Materials/Textures/baseTexture\";\r\nimport { Observable } from \"../../Misc/observable\";\r\nimport { HDRCubeTexture } from \"../../Materials/Textures/hdrCubeTexture\";\r\n\r\n/**\r\n * Build cdf maps for IBL importance sampling during IBL shadow computation.\r\n * This should not be instanciated directly, as it is part of a scene component\r\n * @internal\r\n */\r\nexport class _IblShadowsImportanceSamplingRenderer {\r\n private _scene: Scene;\r\n private _engine: AbstractEngine;\r\n\r\n private _cdfyPT: ProceduralTexture;\r\n private _icdfyPT: ProceduralTexture;\r\n private _cdfxPT: ProceduralTexture;\r\n private _icdfxPT: ProceduralTexture;\r\n private _iblSource: BaseTexture;\r\n\r\n /**\r\n * Gets the IBL source texture being used by the importance sampling renderer\r\n */\r\n public get iblSource(): BaseTexture {\r\n return this._iblSource;\r\n }\r\n\r\n /**\r\n * Sets the IBL source texture to be used by the importance sampling renderer.\r\n * This will trigger recreation of the importance sampling assets.\r\n */\r\n public set iblSource(source: BaseTexture) {\r\n if (this._iblSource === source) {\r\n return;\r\n }\r\n if (source instanceof Texture) {\r\n if (source.isReady()) {\r\n this._recreateAssetsFromNewIbl(source);\r\n } else {\r\n source.onLoadObservable.addOnce(this._recreateAssetsFromNewIbl);\r\n }\r\n } else if (source instanceof HDRCubeTexture) {\r\n if (source.isReady()) {\r\n this._recreateAssetsFromNewIbl(source);\r\n } else {\r\n source.onLoadObservable.addOnce(this._recreateAssetsFromNewIbl.bind(this, source));\r\n }\r\n }\r\n }\r\n\r\n private _recreateAssetsFromNewIbl(source: BaseTexture) {\r\n if (this._debugPass) {\r\n this._debugPass.dispose();\r\n }\r\n this._disposeTextures();\r\n this._iblSource = source;\r\n this._createTextures();\r\n\r\n if (this._debugPass) {\r\n // Recreate the debug pass because of the new textures\r\n this._createDebugPass();\r\n }\r\n\r\n // Once the textures are generated, notify that they are ready to use.\r\n this._icdfxPT.onGeneratedObservable.addOnce(() => {\r\n this.onReadyObservable.notifyObservers();\r\n });\r\n }\r\n\r\n /**\r\n * Return the cumulative distribution function (CDF) Y texture\r\n * @returns Return the cumulative distribution function (CDF) Y texture\r\n */\r\n public getIcdfyTexture(): ProceduralTexture {\r\n return this._icdfyPT;\r\n }\r\n\r\n /**\r\n * Return the cumulative distribution function (CDF) X texture\r\n * @returns Return the cumulative distribution function (CDF) X texture\r\n */\r\n public getIcdfxTexture(): ProceduralTexture {\r\n return this._icdfxPT;\r\n }\r\n\r\n /** Enable the debug view for this pass */\r\n public debugEnabled: boolean = false;\r\n private _debugPass: PostProcess;\r\n private _debugSizeParams: Vector4 = new Vector4(0.0, 0.0, 0.0, 0.0);\r\n\r\n /**\r\n * Sets params that control the position and scaling of the debug display on the screen.\r\n * @param x Screen X offset of the debug display (0-1)\r\n * @param y Screen Y offset of the debug display (0-1)\r\n * @param widthScale X scale of the debug display (0-1)\r\n * @param heightScale Y scale of the debug display (0-1)\r\n */\r\n public setDebugDisplayParams(x: number, y: number, widthScale: number, heightScale: number) {\r\n this._debugSizeParams.set(x, y, widthScale, heightScale);\r\n }\r\n\r\n /**\r\n * The name of the debug pass post process\r\n */\r\n public get debugPassName(): string {\r\n return this._debugPassName;\r\n }\r\n private _debugPassName: string = \"Importance Sample Debug\";\r\n\r\n /**\r\n * Gets the debug pass post process\r\n * @returns The post process\r\n */\r\n public getDebugPassPP(): PostProcess {\r\n if (!this._debugPass) {\r\n this._createDebugPass();\r\n }\r\n return this._debugPass;\r\n }\r\n\r\n /**\r\n * Instanciates the importance sampling renderer\r\n * @param scene Scene to attach to\r\n * @returns The importance sampling renderer\r\n */\r\n constructor(scene: Scene) {\r\n this._scene = scene;\r\n this._engine = scene.getEngine();\r\n }\r\n\r\n /**\r\n * Observable that triggers when the importance sampling renderer is ready\r\n */\r\n public onReadyObservable: Observable<void> = new Observable<void>();\r\n\r\n private _createTextures() {\r\n const size: TextureSize = this._iblSource ? this._iblSource.getSize() : { width: 1, height: 1 };\r\n if (!this._iblSource) {\r\n this._iblSource = RawTexture.CreateRTexture(\r\n new Uint8Array([255]),\r\n 1,\r\n 1,\r\n this._scene,\r\n false,\r\n false,\r\n Constants.TEXTURE_NEAREST_SAMPLINGMODE,\r\n Constants.TEXTURETYPE_UNSIGNED_BYTE\r\n );\r\n this._iblSource.name = \"Placeholder IBL Source\";\r\n }\r\n\r\n if (this._iblSource!.isCube) {\r\n size.width *= 4;\r\n size.height *= 2;\r\n }\r\n\r\n // Create CDF maps (Cumulative Distribution Function) to assist in importance sampling\r\n const cdfOptions: IProceduralTextureCreationOptions = {\r\n generateDepthBuffer: false,\r\n generateMipMaps: false,\r\n format: Constants.TEXTUREFORMAT_R,\r\n type: Constants.TEXTURETYPE_FLOAT,\r\n samplingMode: Constants.TEXTURE_NEAREST_SAMPLINGMODE,\r\n };\r\n const icdfOptions: IProceduralTextureCreationOptions = {\r\n generateDepthBuffer: false,\r\n generateMipMaps: false,\r\n format: Constants.TEXTUREFORMAT_R,\r\n type: Constants.TEXTURETYPE_HALF_FLOAT,\r\n samplingMode: Constants.TEXTURE_NEAREST_SAMPLINGMODE,\r\n };\r\n this._cdfyPT = new ProceduralTexture(\"cdfyTexture\", { width: size.width, height: size.height + 1 }, \"iblShadowsCdfy\", this._scene, cdfOptions, false, false);\r\n this._cdfyPT.autoClear = false;\r\n this._cdfyPT.setTexture(\"iblSource\", this._iblSource as Texture);\r\n this._cdfyPT.setInt(\"iblHeight\", size.height);\r\n if (this._iblSource.isCube) {\r\n this._cdfyPT.defines = \"#define IBL_USE_CUBE_MAP\\n\";\r\n }\r\n this._cdfyPT.refreshRate = 0;\r\n this._icdfyPT = new ProceduralTexture(\"icdfyTexture\", { width: size.width, height: size.height }, \"iblShadowsIcdfy\", this._scene, icdfOptions, false, false);\r\n this._icdfyPT.autoClear = false;\r\n this._icdfyPT.setTexture(\"cdfy\", this._cdfyPT);\r\n this._icdfyPT.refreshRate = 0;\r\n this._cdfxPT = new ProceduralTexture(\"cdfxTexture\", { width: size.width + 1, height: 1 }, \"iblShadowsCdfx\", this._scene, cdfOptions, false, false);\r\n this._cdfxPT.autoClear = false;\r\n this._cdfxPT.setTexture(\"cdfy\", this._cdfyPT);\r\n this._cdfxPT.refreshRate = 0;\r\n this._icdfxPT = new ProceduralTexture(\"icdfxTexture\", { width: size.width, height: 1 }, \"iblShadowsIcdfx\", this._scene, icdfOptions, false, false);\r\n this._icdfxPT.autoClear = false;\r\n this._icdfxPT.setTexture(\"cdfx\", this._cdfxPT);\r\n this._icdfxPT.refreshRate = 0;\r\n }\r\n\r\n private _disposeTextures() {\r\n this._cdfyPT?.dispose();\r\n this._icdfyPT?.dispose();\r\n this._cdfxPT?.dispose();\r\n this._icdfxPT?.dispose();\r\n this._iblSource?.dispose();\r\n }\r\n\r\n private _createDebugPass() {\r\n if (this._debugPass) {\r\n this._debugPass.dispose();\r\n }\r\n const debugOptions: PostProcessOptions = {\r\n width: this._scene.getEngine().getRenderWidth(),\r\n height: this._scene.getEngine().getRenderHeight(),\r\n samplingMode: Texture.BILINEAR_SAMPLINGMODE,\r\n engine: this._engine,\r\n textureType: Constants.TEXTURETYPE_UNSIGNED_INT,\r\n uniforms: [\"sizeParams\"],\r\n samplers: [\"cdfy\", \"icdfy\", \"cdfx\", \"icdfx\", \"iblSource\"],\r\n defines: this._iblSource?.isCube ? \"#define IBL_USE_CUBE_MAP\\n\" : \"\",\r\n };\r\n this._debugPass = new PostProcess(this._debugPassName, \"iblShadowsImportanceSamplingDebug\", debugOptions);\r\n const debugEffect = this._debugPass.getEffect();\r\n if (debugEffect) {\r\n debugEffect.defines = this._iblSource?.isCube ? \"#define IBL_USE_CUBE_MAP\\n\" : \"\";\r\n }\r\n if (this._iblSource?.isCube) {\r\n this._debugPass.updateEffect(\"#define IBL_USE_CUBE_MAP\\n\");\r\n }\r\n this._debugPass.onApplyObservable.add((effect) => {\r\n effect.setTexture(\"cdfy\", this._cdfyPT);\r\n effect.setTexture(\"icdfy\", this._icdfyPT);\r\n effect.setTexture(\"cdfx\", this._cdfxPT);\r\n effect.setTexture(\"icdfx\", this._icdfxPT);\r\n effect.setTexture(\"iblSource\", this._iblSource);\r\n effect.setFloat4(\"sizeParams\", this._debugSizeParams.x, this._debugSizeParams.y, this._debugSizeParams.z, this._debugSizeParams.w);\r\n });\r\n }\r\n\r\n /**\r\n * Checks if the importance sampling renderer is ready\r\n * @returns true if the importance sampling renderer is ready\r\n */\r\n public isReady() {\r\n return (\r\n this._iblSource &&\r\n this._iblSource.name !== \"Placeholder IBL Source\" &&\r\n this._iblSource.isReady() &&\r\n this._cdfyPT.isReady() &&\r\n this._icdfyPT.isReady() &&\r\n this._cdfxPT.isReady() &&\r\n this._icdfxPT.isReady()\r\n );\r\n }\r\n\r\n /**\r\n * Disposes the importance sampling renderer and associated resources\r\n */\r\n public dispose() {\r\n this._disposeTextures();\r\n if (this._debugPass) {\r\n this._debugPass.dispose();\r\n }\r\n }\r\n}\r\n"]}