@babylonjs/core 6.37.0 → 6.38.0

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 (147) hide show
  1. package/Behaviors/Cameras/bouncingBehavior.js +8 -6
  2. package/Behaviors/Cameras/bouncingBehavior.js.map +1 -1
  3. package/Behaviors/Cameras/framingBehavior.js +3 -3
  4. package/Behaviors/Cameras/framingBehavior.js.map +1 -1
  5. package/Behaviors/Meshes/baseSixDofDragBehavior.js +1 -1
  6. package/Behaviors/Meshes/baseSixDofDragBehavior.js.map +1 -1
  7. package/Behaviors/Meshes/sixDofDragBehavior.js +26 -6
  8. package/Behaviors/Meshes/sixDofDragBehavior.js.map +1 -1
  9. package/Bones/skeleton.js +2 -2
  10. package/Bones/skeleton.js.map +1 -1
  11. package/Buffers/buffer.align.js +4 -1
  12. package/Buffers/buffer.align.js.map +1 -1
  13. package/Buffers/buffer.d.ts +10 -3
  14. package/Buffers/buffer.js +34 -5
  15. package/Buffers/buffer.js.map +1 -1
  16. package/Cameras/arcRotateCamera.d.ts +9 -8
  17. package/Cameras/arcRotateCamera.js +5 -5
  18. package/Cameras/arcRotateCamera.js.map +1 -1
  19. package/Engines/Extensions/engine.cubeTexture.d.ts +1 -3
  20. package/Engines/Extensions/engine.cubeTexture.js +1 -3
  21. package/Engines/Extensions/engine.cubeTexture.js.map +1 -1
  22. package/Engines/Extensions/engine.renderTarget.js +6 -17
  23. package/Engines/Extensions/engine.renderTarget.js.map +1 -1
  24. package/Engines/WebGL/webGLRenderTargetWrapper.d.ts +11 -0
  25. package/Engines/WebGL/webGLRenderTargetWrapper.js +27 -0
  26. package/Engines/WebGL/webGLRenderTargetWrapper.js.map +1 -1
  27. package/Engines/WebGPU/Extensions/engine.cubeTexture.js +8 -4
  28. package/Engines/WebGPU/Extensions/engine.cubeTexture.js.map +1 -1
  29. package/Engines/WebGPU/Extensions/engine.renderTarget.js +1 -1
  30. package/Engines/WebGPU/Extensions/engine.renderTarget.js.map +1 -1
  31. package/Engines/WebGPU/webgpuTextureManager.js +3 -0
  32. package/Engines/WebGPU/webgpuTextureManager.js.map +1 -1
  33. package/Engines/renderTargetWrapper.js +7 -1
  34. package/Engines/renderTargetWrapper.js.map +1 -1
  35. package/Engines/thinEngine.d.ts +3 -3
  36. package/Engines/thinEngine.js +16 -8
  37. package/Engines/thinEngine.js.map +1 -1
  38. package/Engines/webgpuEngine.d.ts +2 -2
  39. package/Engines/webgpuEngine.js +7 -12
  40. package/Engines/webgpuEngine.js.map +1 -1
  41. package/Gizmos/boundingBoxGizmo.js +1 -1
  42. package/Gizmos/boundingBoxGizmo.js.map +1 -1
  43. package/Gizmos/cameraGizmo.d.ts +9 -2
  44. package/Gizmos/cameraGizmo.js +29 -10
  45. package/Gizmos/cameraGizmo.js.map +1 -1
  46. package/Lights/shadowLight.d.ts +2 -2
  47. package/Lights/shadowLight.js +1 -1
  48. package/Lights/shadowLight.js.map +1 -1
  49. package/Materials/Textures/baseTexture.d.ts +1 -1
  50. package/Materials/Textures/baseTexture.js +1 -1
  51. package/Materials/Textures/baseTexture.js.map +1 -1
  52. package/Materials/Textures/internalTexture.js +5 -0
  53. package/Materials/Textures/internalTexture.js.map +1 -1
  54. package/Materials/Textures/multiRenderTarget.d.ts +1 -1
  55. package/Materials/Textures/multiRenderTarget.js +4 -4
  56. package/Materials/Textures/multiRenderTarget.js.map +1 -1
  57. package/Materials/Textures/videoTexture.js +2 -0
  58. package/Materials/Textures/videoTexture.js.map +1 -1
  59. package/Materials/materialPluginManager.d.ts +1 -1
  60. package/Materials/materialPluginManager.js.map +1 -1
  61. package/Meshes/Builders/groundBuilder.d.ts +57 -91
  62. package/Meshes/Builders/groundBuilder.js +57 -91
  63. package/Meshes/Builders/groundBuilder.js.map +1 -1
  64. package/Meshes/Node/Blocks/geometryArcTan2Block.d.ts +30 -0
  65. package/Meshes/Node/Blocks/geometryArcTan2Block.js +81 -0
  66. package/Meshes/Node/Blocks/geometryArcTan2Block.js.map +1 -0
  67. package/Meshes/Node/Blocks/geometryClampBlock.d.ts +33 -0
  68. package/Meshes/Node/Blocks/geometryClampBlock.js +101 -0
  69. package/Meshes/Node/Blocks/geometryClampBlock.js.map +1 -0
  70. package/Meshes/Node/Blocks/geometryCrossBlock.d.ts +30 -0
  71. package/Meshes/Node/Blocks/geometryCrossBlock.js +76 -0
  72. package/Meshes/Node/Blocks/geometryCrossBlock.js.map +1 -0
  73. package/Meshes/Node/Blocks/geometryLerpBlock.d.ts +34 -0
  74. package/Meshes/Node/Blocks/geometryLerpBlock.js +90 -0
  75. package/Meshes/Node/Blocks/geometryLerpBlock.js.map +1 -0
  76. package/Meshes/Node/Blocks/geometryModBlock.d.ts +30 -0
  77. package/Meshes/Node/Blocks/geometryModBlock.js +82 -0
  78. package/Meshes/Node/Blocks/geometryModBlock.js.map +1 -0
  79. package/Meshes/Node/Blocks/geometryNLerpBlock.d.ts +34 -0
  80. package/Meshes/Node/Blocks/geometryNLerpBlock.js +96 -0
  81. package/Meshes/Node/Blocks/geometryNLerpBlock.js.map +1 -0
  82. package/Meshes/Node/Blocks/geometryPowBlock.d.ts +30 -0
  83. package/Meshes/Node/Blocks/geometryPowBlock.js +82 -0
  84. package/Meshes/Node/Blocks/geometryPowBlock.js.map +1 -0
  85. package/Meshes/Node/Blocks/geometrySmoothStepBlock.d.ts +34 -0
  86. package/Meshes/Node/Blocks/geometrySmoothStepBlock.js +91 -0
  87. package/Meshes/Node/Blocks/geometrySmoothStepBlock.js.map +1 -0
  88. package/Meshes/Node/Blocks/geometryStepBlock.d.ts +30 -0
  89. package/Meshes/Node/Blocks/geometryStepBlock.js +84 -0
  90. package/Meshes/Node/Blocks/geometryStepBlock.js.map +1 -0
  91. package/Meshes/Node/Blocks/geometryTrigonometryBlock.d.ts +19 -15
  92. package/Meshes/Node/Blocks/geometryTrigonometryBlock.js +37 -17
  93. package/Meshes/Node/Blocks/geometryTrigonometryBlock.js.map +1 -1
  94. package/Meshes/Node/index.d.ts +9 -0
  95. package/Meshes/Node/index.js +9 -0
  96. package/Meshes/Node/index.js.map +1 -1
  97. package/Meshes/geometry.js +8 -5
  98. package/Meshes/geometry.js.map +1 -1
  99. package/Meshes/thinInstanceMesh.d.ts +1 -1
  100. package/Meshes/thinInstanceMesh.js +2 -2
  101. package/Meshes/thinInstanceMesh.js.map +1 -1
  102. package/Particles/gpuParticleSystem.d.ts +1 -0
  103. package/Particles/gpuParticleSystem.js +10 -3
  104. package/Particles/gpuParticleSystem.js.map +1 -1
  105. package/Rendering/GaussianSplatting/gaussianSplatting.d.ts +6 -0
  106. package/Rendering/GaussianSplatting/gaussianSplatting.js +124 -39
  107. package/Rendering/GaussianSplatting/gaussianSplatting.js.map +1 -1
  108. package/Rendering/GlobalIllumination/giRSM.d.ts +54 -0
  109. package/Rendering/GlobalIllumination/giRSM.js +54 -0
  110. package/Rendering/GlobalIllumination/giRSM.js.map +1 -0
  111. package/Rendering/GlobalIllumination/giRSMManager.d.ts +256 -0
  112. package/Rendering/GlobalIllumination/giRSMManager.js +715 -0
  113. package/Rendering/GlobalIllumination/giRSMManager.js.map +1 -0
  114. package/Rendering/GlobalIllumination/index.d.ts +2 -0
  115. package/Rendering/GlobalIllumination/index.js +3 -0
  116. package/Rendering/GlobalIllumination/index.js.map +1 -0
  117. package/Rendering/fluidRenderer/fluidRenderer.js +20 -1
  118. package/Rendering/fluidRenderer/fluidRenderer.js.map +1 -1
  119. package/Rendering/index.d.ts +2 -0
  120. package/Rendering/index.js +2 -0
  121. package/Rendering/index.js.map +1 -1
  122. package/Rendering/prePassRendererSceneComponent.js +1 -4
  123. package/Rendering/prePassRendererSceneComponent.js.map +1 -1
  124. package/Rendering/reflectiveShadowMap.d.ts +152 -0
  125. package/Rendering/reflectiveShadowMap.js +389 -0
  126. package/Rendering/reflectiveShadowMap.js.map +1 -0
  127. package/Shaders/bilateralBlur.fragment.d.ts +5 -0
  128. package/Shaders/bilateralBlur.fragment.js +20 -0
  129. package/Shaders/bilateralBlur.fragment.js.map +1 -0
  130. package/Shaders/bilateralBlurQuality.fragment.d.ts +5 -0
  131. package/Shaders/bilateralBlurQuality.fragment.js +20 -0
  132. package/Shaders/bilateralBlurQuality.fragment.js.map +1 -0
  133. package/Shaders/rsmFullGlobalIllumination.fragment.d.ts +5 -0
  134. package/Shaders/rsmFullGlobalIllumination.fragment.js +28 -0
  135. package/Shaders/rsmFullGlobalIllumination.fragment.js.map +1 -0
  136. package/Shaders/rsmGlobalIllumination.fragment.d.ts +5 -0
  137. package/Shaders/rsmGlobalIllumination.fragment.js +33 -0
  138. package/Shaders/rsmGlobalIllumination.fragment.js.map +1 -0
  139. package/XR/features/WebXRControllerTeleportation.d.ts +9 -1
  140. package/XR/features/WebXRControllerTeleportation.js +3 -0
  141. package/XR/features/WebXRControllerTeleportation.js.map +1 -1
  142. package/XR/webXRCamera.d.ts +2 -0
  143. package/XR/webXRCamera.js +2 -0
  144. package/XR/webXRCamera.js.map +1 -1
  145. package/package.json +1 -1
  146. package/scene.js +1 -1
  147. package/scene.js.map +1 -1
@@ -0,0 +1,152 @@
1
+ import type { ShadowLight } from "../Lights/shadowLight.js";
2
+ import type { UniformBuffer } from "../Materials/uniformBuffer.js";
3
+ import { Matrix } from "../Maths/math.vector.js";
4
+ import type { AbstractMesh } from "../Meshes/abstractMesh.js";
5
+ import type { Scene } from "../scene.js";
6
+ import { MaterialPluginBase } from "../Materials/materialPluginBase.js";
7
+ import type { Material } from "../Materials/material.js";
8
+ import type { StandardMaterial } from "../Materials/standardMaterial.js";
9
+ import { MaterialDefines } from "../Materials/materialDefines.js";
10
+ import { PBRBaseMaterial } from "../Materials/PBR/pbrBaseMaterial.js";
11
+ /**
12
+ * Class used to generate the RSM (Reflective Shadow Map) textures for a given light.
13
+ * The textures are: position (in world space), normal (in world space) and flux (light intensity)
14
+ */
15
+ export declare class ReflectiveShadowMap {
16
+ private _scene;
17
+ private _light;
18
+ private _lightTransformMatrix;
19
+ private _mrt;
20
+ private _textureDimensions;
21
+ private _regularMatToMatWithPlugin;
22
+ private _counters;
23
+ private _enable;
24
+ /**
25
+ * Enables or disables the RSM generation.
26
+ */
27
+ get enable(): boolean;
28
+ set enable(value: boolean);
29
+ /**
30
+ * Gets the position texture generated by the RSM process.
31
+ */
32
+ get positionWorldTexture(): import("..").Texture;
33
+ /**
34
+ * Gets the normal texture generated by the RSM process.
35
+ */
36
+ get normalWorldTexture(): import("..").Texture;
37
+ /**
38
+ * Gets the flux texture generated by the RSM process.
39
+ */
40
+ get fluxTexture(): import("..").Texture;
41
+ /**
42
+ * Gets the render list used to generate the RSM textures.
43
+ */
44
+ get renderList(): import("..").Nullable<AbstractMesh[]>;
45
+ /**
46
+ * Gets the light used to generate the RSM textures.
47
+ */
48
+ get light(): ShadowLight;
49
+ /**
50
+ * Gets or sets a boolean indicating if the light parameters should be recomputed even if the light parameters (position, direction) did not change.
51
+ * You should not set this value to true, except for debugging purpose (if you want to see changes from the inspector, for eg).
52
+ * Instead, you should call updateLightParameters() explicitely at the right time (once the light parameters changed).
53
+ */
54
+ forceUpdateLightParameters: boolean;
55
+ /**
56
+ * Creates a new RSM for the given light.
57
+ * @param scene The scene
58
+ * @param light The light to use to generate the RSM textures
59
+ * @param textureDimensions The dimensions of the textures to generate. Default: \{ width: 512, height: 512 \}
60
+ */
61
+ constructor(scene: Scene, light: ShadowLight, textureDimensions?: {
62
+ width: number;
63
+ height: number;
64
+ });
65
+ /**
66
+ * Sets the dimensions of the textures to generate.
67
+ * @param dimensions The dimensions of the textures to generate.
68
+ */
69
+ setTextureDimensions(dimensions: {
70
+ width: number;
71
+ height: number;
72
+ }): void;
73
+ /**
74
+ * Adds the given mesh to the render list used to generate the RSM textures.
75
+ * @param mesh The mesh to add to the render list used to generate the RSM textures. If not provided, all scene meshes will be added to the render list.
76
+ */
77
+ addMesh(mesh?: AbstractMesh): void;
78
+ /**
79
+ * Recomputes the light transformation matrix. Call this method if you manually changed the light position / direction / etc. and you want to update the RSM textures accordingly.
80
+ */
81
+ updateLightParameters(): void;
82
+ /**
83
+ * Gets the light transformation matrix used to generate the RSM textures.
84
+ */
85
+ get lightTransformationMatrix(): Matrix;
86
+ /**
87
+ * Gets the GPU time spent to generate the RSM textures.
88
+ */
89
+ get countersGPU(): Array<{
90
+ name: string;
91
+ value: number;
92
+ }>;
93
+ /**
94
+ * Disposes the RSM.
95
+ */
96
+ dispose(): void;
97
+ protected _createMultiRenderTarget(): void;
98
+ protected _customRenderTarget(add: boolean): void;
99
+ protected _recomputeLightTransformationMatrix(): void;
100
+ protected _addMeshToMRT(mesh: AbstractMesh): void;
101
+ protected _disposeMultiRenderTarget(): void;
102
+ }
103
+ /**
104
+ * @internal
105
+ */
106
+ declare class MaterialRSMCreateDefines extends MaterialDefines {
107
+ RSMCREATE: boolean;
108
+ RSMCREATE_PROJTEXTURE: boolean;
109
+ RSMCREATE_LIGHT_IS_SPOT: boolean;
110
+ }
111
+ /**
112
+ * Plugin that implements the creation of the RSM textures
113
+ */
114
+ export declare class RSMCreatePluginMaterial extends MaterialPluginBase {
115
+ private _varAlbedoName;
116
+ private _lightColor;
117
+ private _hasProjectionTexture;
118
+ /**
119
+ * Defines the name of the plugin.
120
+ */
121
+ static readonly Name = "RSMCreate";
122
+ /**
123
+ * Defines the light that should be used to generate the RSM textures.
124
+ */
125
+ light: ShadowLight;
126
+ private _isEnabled;
127
+ /**
128
+ * Defines if the plugin is enabled in the material.
129
+ */
130
+ isEnabled: boolean;
131
+ protected _markAllSubMeshesAsTexturesDirty(): void;
132
+ private _internalMarkAllSubMeshesAsTexturesDirty;
133
+ constructor(material: Material | StandardMaterial | PBRBaseMaterial);
134
+ prepareDefines(defines: MaterialRSMCreateDefines): void;
135
+ getClassName(): string;
136
+ getUniforms(): {
137
+ ubo: {
138
+ name: string;
139
+ size: number;
140
+ type: string;
141
+ }[];
142
+ fragment: string;
143
+ };
144
+ getSamplers(samplers: string[]): void;
145
+ bindForSubMesh(uniformBuffer: UniformBuffer): void;
146
+ getCustomCode(shaderType: string): {
147
+ CUSTOM_FRAGMENT_BEGIN: string;
148
+ CUSTOM_FRAGMENT_DEFINITIONS: string;
149
+ CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR: string;
150
+ } | null;
151
+ }
152
+ export {};
@@ -0,0 +1,389 @@
1
+ import { __decorate } from "../tslib.es6.js";
2
+ /**
3
+ * Reflective Shadow Maps were first described in http://www.klayge.org/material/3_12/GI/rsm.pdf by Carsten Dachsbacher and Marc Stamminger
4
+ * The ReflectiveShadowMap class only implements the geometry buffer generation part.
5
+ * For the global illumination effect, see the GIRSMManager class.
6
+ */
7
+
8
+ import { MultiRenderTarget } from "../Materials/Textures/multiRenderTarget.js";
9
+ import { Color3, Color4 } from "../Maths/math.color.js";
10
+ import { Matrix, TmpVectors } from "../Maths/math.vector.js";
11
+ import { MaterialPluginBase } from "../Materials/materialPluginBase.js";
12
+ import { MaterialDefines } from "../Materials/materialDefines.js";
13
+ import { PBRBaseMaterial } from "../Materials/PBR/pbrBaseMaterial.js";
14
+ import { expandToProperty, serialize } from "../Misc/decorators.js";
15
+ import { RegisterClass } from "../Misc/typeStore.js";
16
+ import { Light } from "../Lights/light.js";
17
+ /**
18
+ * Class used to generate the RSM (Reflective Shadow Map) textures for a given light.
19
+ * The textures are: position (in world space), normal (in world space) and flux (light intensity)
20
+ */
21
+ export class ReflectiveShadowMap {
22
+ /**
23
+ * Enables or disables the RSM generation.
24
+ */
25
+ get enable() {
26
+ return this._enable;
27
+ }
28
+ set enable(value) {
29
+ if (this._enable === value) {
30
+ return;
31
+ }
32
+ this._enable = value;
33
+ this._customRenderTarget(value);
34
+ }
35
+ /**
36
+ * Gets the position texture generated by the RSM process.
37
+ */
38
+ get positionWorldTexture() {
39
+ return this._mrt.textures[0];
40
+ }
41
+ /**
42
+ * Gets the normal texture generated by the RSM process.
43
+ */
44
+ get normalWorldTexture() {
45
+ return this._mrt.textures[1];
46
+ }
47
+ /**
48
+ * Gets the flux texture generated by the RSM process.
49
+ */
50
+ get fluxTexture() {
51
+ return this._mrt.textures[2];
52
+ }
53
+ /**
54
+ * Gets the render list used to generate the RSM textures.
55
+ */
56
+ get renderList() {
57
+ return this._mrt.renderList;
58
+ }
59
+ /**
60
+ * Gets the light used to generate the RSM textures.
61
+ */
62
+ get light() {
63
+ return this._light;
64
+ }
65
+ /**
66
+ * Creates a new RSM for the given light.
67
+ * @param scene The scene
68
+ * @param light The light to use to generate the RSM textures
69
+ * @param textureDimensions The dimensions of the textures to generate. Default: \{ width: 512, height: 512 \}
70
+ */
71
+ constructor(scene, light, textureDimensions = { width: 512, height: 512 }) {
72
+ this._lightTransformMatrix = Matrix.Identity();
73
+ this._enable = false;
74
+ /**
75
+ * Gets or sets a boolean indicating if the light parameters should be recomputed even if the light parameters (position, direction) did not change.
76
+ * You should not set this value to true, except for debugging purpose (if you want to see changes from the inspector, for eg).
77
+ * Instead, you should call updateLightParameters() explicitely at the right time (once the light parameters changed).
78
+ */
79
+ this.forceUpdateLightParameters = false;
80
+ this._scene = scene;
81
+ this._light = light;
82
+ this._textureDimensions = textureDimensions;
83
+ this._regularMatToMatWithPlugin = new Map();
84
+ this._counters = [{ name: "RSM Generation " + light.name, value: 0 }];
85
+ this._createMultiRenderTarget();
86
+ this._recomputeLightTransformationMatrix();
87
+ this.enable = true;
88
+ }
89
+ /**
90
+ * Sets the dimensions of the textures to generate.
91
+ * @param dimensions The dimensions of the textures to generate.
92
+ */
93
+ setTextureDimensions(dimensions) {
94
+ const renderList = this._mrt.renderList;
95
+ this._textureDimensions = dimensions;
96
+ this._disposeMultiRenderTarget();
97
+ this._createMultiRenderTarget();
98
+ renderList === null || renderList === void 0 ? void 0 : renderList.forEach((mesh) => {
99
+ this._addMeshToMRT(mesh);
100
+ });
101
+ }
102
+ /**
103
+ * Adds the given mesh to the render list used to generate the RSM textures.
104
+ * @param mesh The mesh to add to the render list used to generate the RSM textures. If not provided, all scene meshes will be added to the render list.
105
+ */
106
+ addMesh(mesh) {
107
+ if (mesh) {
108
+ this._addMeshToMRT(mesh);
109
+ }
110
+ else {
111
+ this._scene.meshes.forEach((mesh) => {
112
+ this._addMeshToMRT(mesh);
113
+ });
114
+ }
115
+ }
116
+ /**
117
+ * Recomputes the light transformation matrix. Call this method if you manually changed the light position / direction / etc. and you want to update the RSM textures accordingly.
118
+ */
119
+ updateLightParameters() {
120
+ this._recomputeLightTransformationMatrix();
121
+ }
122
+ /**
123
+ * Gets the light transformation matrix used to generate the RSM textures.
124
+ */
125
+ get lightTransformationMatrix() {
126
+ if (this.forceUpdateLightParameters) {
127
+ this.updateLightParameters();
128
+ }
129
+ return this._lightTransformMatrix;
130
+ }
131
+ /**
132
+ * Gets the GPU time spent to generate the RSM textures.
133
+ */
134
+ get countersGPU() {
135
+ return this._counters;
136
+ }
137
+ /**
138
+ * Disposes the RSM.
139
+ */
140
+ dispose() {
141
+ this._disposeMultiRenderTarget();
142
+ }
143
+ _createMultiRenderTarget() {
144
+ const name = this._light.name;
145
+ const caps = this._scene.getEngine().getCaps();
146
+ const fluxTextureType = caps.rg11b10ufColorRenderable ? 13 : 2;
147
+ const fluxTextureFormat = caps.rg11b10ufColorRenderable ? 4 : 5;
148
+ this._mrt = new MultiRenderTarget("RSMmrt_" + name, this._textureDimensions, 3, // number of RTT - position / normal / flux
149
+ this._scene, {
150
+ types: [2, 11, fluxTextureType],
151
+ samplingModes: [2, 2, 2],
152
+ generateMipMaps: false,
153
+ targetTypes: [3553, 3553, 3553],
154
+ formats: [5, 5, fluxTextureFormat],
155
+ }, ["RSMPosition_" + name, "RSMNormal_" + name, "RSMFlux_" + name]);
156
+ this._mrt.renderList = [];
157
+ this._mrt.clearColor = new Color4(0, 0, 0, 1);
158
+ this._mrt.noPrePassRenderer = true;
159
+ let sceneUBO;
160
+ let currentSceneUBO;
161
+ const useUBO = this._scene.getEngine().supportsUniformBuffers;
162
+ if (useUBO) {
163
+ sceneUBO = this._scene.createSceneUniformBuffer(`Scene for RSM (light "${name}")`);
164
+ }
165
+ let shadowEnabled;
166
+ this._mrt.onBeforeBindObservable.add(() => {
167
+ currentSceneUBO = this._scene.getSceneUniformBuffer();
168
+ shadowEnabled = this._light.shadowEnabled;
169
+ this._light.shadowEnabled = false; // we render from the light point of view, so we won't have any shadow anyway!
170
+ });
171
+ this._mrt.onBeforeRenderObservable.add((faceIndex) => {
172
+ if (sceneUBO) {
173
+ this._scene.setSceneUniformBuffer(sceneUBO);
174
+ }
175
+ const viewMatrix = this._light.getViewMatrix(faceIndex);
176
+ const projectionMatrix = this._light.getProjectionMatrix(viewMatrix || undefined, this._mrt.renderList || undefined);
177
+ if (viewMatrix && projectionMatrix) {
178
+ this._scene.setTransformMatrix(viewMatrix, projectionMatrix);
179
+ }
180
+ if (useUBO) {
181
+ this._scene.getSceneUniformBuffer().unbindEffect();
182
+ this._scene.finalizeSceneUbo();
183
+ }
184
+ });
185
+ this._mrt.onAfterUnbindObservable.add(() => {
186
+ var _a, _b;
187
+ if (sceneUBO) {
188
+ this._scene.setSceneUniformBuffer(currentSceneUBO);
189
+ }
190
+ this._scene.updateTransformMatrix(); // restore the view/projection matrices of the active camera
191
+ this._light.shadowEnabled = shadowEnabled;
192
+ this._counters[0].value = (_b = (_a = this._mrt.renderTarget.gpuTimeInFrame) === null || _a === void 0 ? void 0 : _a.counter.lastSecAverage) !== null && _b !== void 0 ? _b : 0;
193
+ });
194
+ this._customRenderTarget(true);
195
+ }
196
+ _customRenderTarget(add) {
197
+ const idx = this._scene.customRenderTargets.indexOf(this._mrt);
198
+ if (add) {
199
+ if (idx === -1) {
200
+ this._scene.customRenderTargets.push(this._mrt);
201
+ }
202
+ }
203
+ else if (idx !== -1) {
204
+ this._scene.customRenderTargets.splice(idx, 1);
205
+ }
206
+ }
207
+ _recomputeLightTransformationMatrix() {
208
+ const viewMatrix = this._light.getViewMatrix();
209
+ const projectionMatrix = this._light.getProjectionMatrix(viewMatrix || undefined, this._mrt.renderList || undefined);
210
+ if (viewMatrix && projectionMatrix) {
211
+ viewMatrix.multiplyToRef(projectionMatrix, this._lightTransformMatrix);
212
+ }
213
+ }
214
+ _addMeshToMRT(mesh) {
215
+ var _a;
216
+ (_a = this._mrt.renderList) === null || _a === void 0 ? void 0 : _a.push(mesh);
217
+ const material = mesh.material;
218
+ if (mesh.getTotalVertices() === 0 || !material) {
219
+ return;
220
+ }
221
+ let rsmMaterial = this._regularMatToMatWithPlugin.get(material);
222
+ if (!rsmMaterial) {
223
+ rsmMaterial = material.clone("RSMCreate_" + material.name) || undefined;
224
+ if (rsmMaterial) {
225
+ // Disable the prepass renderer for this material
226
+ Object.defineProperty(rsmMaterial, "canRenderToMRT", {
227
+ get: function () {
228
+ return false;
229
+ },
230
+ enumerable: true,
231
+ configurable: true,
232
+ });
233
+ rsmMaterial.disableLighting = true;
234
+ const rsmCreatePlugin = new RSMCreatePluginMaterial(rsmMaterial);
235
+ rsmCreatePlugin.isEnabled = true;
236
+ rsmCreatePlugin.light = this._light;
237
+ this._regularMatToMatWithPlugin.set(material, rsmMaterial);
238
+ }
239
+ }
240
+ this._mrt.setMaterialForRendering(mesh, rsmMaterial);
241
+ }
242
+ _disposeMultiRenderTarget() {
243
+ this._customRenderTarget(false);
244
+ this._mrt.dispose();
245
+ }
246
+ }
247
+ /**
248
+ * @internal
249
+ */
250
+ class MaterialRSMCreateDefines extends MaterialDefines {
251
+ constructor() {
252
+ super(...arguments);
253
+ this.RSMCREATE = false;
254
+ this.RSMCREATE_PROJTEXTURE = false;
255
+ this.RSMCREATE_LIGHT_IS_SPOT = false;
256
+ }
257
+ }
258
+ /**
259
+ * Plugin that implements the creation of the RSM textures
260
+ */
261
+ export class RSMCreatePluginMaterial extends MaterialPluginBase {
262
+ _markAllSubMeshesAsTexturesDirty() {
263
+ this._enable(this._isEnabled);
264
+ this._internalMarkAllSubMeshesAsTexturesDirty();
265
+ }
266
+ constructor(material) {
267
+ super(material, RSMCreatePluginMaterial.Name, 300, new MaterialRSMCreateDefines());
268
+ this._lightColor = new Color3();
269
+ this._hasProjectionTexture = false;
270
+ this._isEnabled = false;
271
+ /**
272
+ * Defines if the plugin is enabled in the material.
273
+ */
274
+ this.isEnabled = false;
275
+ this._internalMarkAllSubMeshesAsTexturesDirty = material._dirtyCallbacks[1];
276
+ this._varAlbedoName = material instanceof PBRBaseMaterial ? "surfaceAlbedo" : "baseColor.rgb";
277
+ }
278
+ prepareDefines(defines) {
279
+ defines.RSMCREATE = this._isEnabled;
280
+ this._hasProjectionTexture = false;
281
+ const isSpot = this.light.getTypeID() === Light.LIGHTTYPEID_SPOTLIGHT;
282
+ if (isSpot) {
283
+ const spot = this.light;
284
+ this._hasProjectionTexture = spot.projectionTexture ? spot.projectionTexture.isReady() : false;
285
+ }
286
+ defines.RSMCREATE_PROJTEXTURE = this._hasProjectionTexture;
287
+ defines.RSMCREATE_LIGHT_IS_SPOT = isSpot;
288
+ }
289
+ getClassName() {
290
+ return "RSMCreatePluginMaterial";
291
+ }
292
+ getUniforms() {
293
+ return {
294
+ ubo: [
295
+ { name: "rsmTextureProjectionMatrix", size: 16, type: "mat4" },
296
+ { name: "rsmSpotInfo", size: 4, type: "vec4" },
297
+ { name: "rsmLightColor", size: 3, type: "vec3" },
298
+ { name: "rsmLightPosition", size: 3, type: "vec3" },
299
+ ],
300
+ fragment: `#ifdef RSMCREATE
301
+ uniform mat4 rsmTextureProjectionMatrix;
302
+ uniform vec4 rsmSpotInfo;
303
+ uniform vec3 rsmLightColor;
304
+ unfiorm vec3 rsmLightPosition;
305
+ #endif`,
306
+ };
307
+ }
308
+ getSamplers(samplers) {
309
+ samplers.push("rsmTextureProjectionSampler");
310
+ }
311
+ bindForSubMesh(uniformBuffer) {
312
+ if (!this._isEnabled) {
313
+ return;
314
+ }
315
+ this.light.diffuse.scaleToRef(this.light.getScaledIntensity(), this._lightColor);
316
+ uniformBuffer.updateColor3("rsmLightColor", this._lightColor);
317
+ if (this.light.getTypeID() === Light.LIGHTTYPEID_SPOTLIGHT) {
318
+ const spot = this.light;
319
+ if (this._hasProjectionTexture) {
320
+ uniformBuffer.updateMatrix("rsmTextureProjectionMatrix", spot.projectionTextureMatrix);
321
+ uniformBuffer.setTexture("rsmTextureProjectionSampler", spot.projectionTexture);
322
+ }
323
+ const normalizeDirection = TmpVectors.Vector3[0];
324
+ if (spot.computeTransformedInformation()) {
325
+ uniformBuffer.updateFloat3("rsmLightPosition", this.light.transformedPosition.x, this.light.transformedPosition.y, this.light.transformedPosition.z);
326
+ spot.transformedDirection.normalizeToRef(normalizeDirection);
327
+ }
328
+ else {
329
+ uniformBuffer.updateFloat3("rsmLightPosition", this.light.position.x, this.light.position.y, this.light.position.z);
330
+ spot.direction.normalizeToRef(normalizeDirection);
331
+ }
332
+ uniformBuffer.updateFloat4("rsmSpotInfo", normalizeDirection.x, normalizeDirection.y, normalizeDirection.z, Math.cos(spot.angle * 0.5));
333
+ }
334
+ }
335
+ getCustomCode(shaderType) {
336
+ return shaderType === "vertex"
337
+ ? null
338
+ : {
339
+ CUSTOM_FRAGMENT_BEGIN: `
340
+ #ifdef RSMCREATE
341
+ #extension GL_EXT_draw_buffers : require
342
+ #endif
343
+ `,
344
+ CUSTOM_FRAGMENT_DEFINITIONS: `
345
+ #ifdef RSMCREATE
346
+ #ifdef RSMCREATE_PROJTEXTURE
347
+ uniform highp sampler2D rsmTextureProjectionSampler;
348
+ #endif
349
+ layout(location = 0) out highp vec4 glFragData[3];
350
+ vec4 glFragColor;
351
+ #endif
352
+ `,
353
+ CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR: `
354
+ #ifdef RSMCREATE
355
+ vec3 rsmColor = ${this._varAlbedoName} * rsmLightColor;
356
+ #ifdef RSMCREATE_PROJTEXTURE
357
+ {
358
+ vec4 strq = rsmTextureProjectionMatrix * vec4(vPositionW, 1.0);
359
+ strq /= strq.w;
360
+ rsmColor *= texture2D(rsmTextureProjectionSampler, strq.xy).rgb;
361
+ }
362
+ #endif
363
+ #ifdef RSMCREATE_LIGHT_IS_SPOT
364
+ {
365
+ float cosAngle = max(0., dot(rsmSpotInfo.xyz, normalize(vPositionW - rsmLightPosition)));
366
+ rsmColor = sign(cosAngle - rsmSpotInfo.w) * rsmColor;
367
+ }
368
+ #endif
369
+ glFragData[0] = vec4(vPositionW, 1.);
370
+ glFragData[1] = vec4(normalize(normalW) * 0.5 + 0.5, 1.);
371
+ glFragData[2] = vec4(rsmColor, 1.);
372
+ #endif
373
+ `,
374
+ };
375
+ }
376
+ }
377
+ /**
378
+ * Defines the name of the plugin.
379
+ */
380
+ RSMCreatePluginMaterial.Name = "RSMCreate";
381
+ __decorate([
382
+ serialize()
383
+ ], RSMCreatePluginMaterial.prototype, "light", void 0);
384
+ __decorate([
385
+ serialize(),
386
+ expandToProperty("_markAllSubMeshesAsTexturesDirty")
387
+ ], RSMCreatePluginMaterial.prototype, "isEnabled", void 0);
388
+ RegisterClass(`BABYLON.RSMCreatePluginMaterial`, RSMCreatePluginMaterial);
389
+ //# sourceMappingURL=reflectiveShadowMap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reflectiveShadowMap.js","sourceRoot":"","sources":["../../../../dev/core/src/Rendering/reflectiveShadowMap.ts"],"names":[],"mappings":";AAAA;;;;GAIG;AACH,OAAO,EAAE,SAAS,EAAE,gCAA+B;AAEnD,OAAO,EAAE,iBAAiB,EAAE,mDAAkD;AAE9E,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,+BAA8B;AACvD,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,gCAA+B;AAI5D,OAAO,EAAE,kBAAkB,EAAE,2CAA0C;AAGvE,OAAO,EAAE,eAAe,EAAE,wCAAuC;AAEjE,OAAO,EAAE,eAAe,EAAE,4CAA2C;AACrE,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,8BAA6B;AACnE,OAAO,EAAE,aAAa,EAAE,6BAA4B;AACpD,OAAO,EAAE,KAAK,EAAE,2BAA0B;AAE1C;;;GAGG;AACH,MAAM,OAAO,mBAAmB;IAW5B;;OAEG;IACH,IAAW,MAAM;QACb,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;QACnC,OAAO,UAAU,KAAK,QAAQ;YAC1B,CAAC,CAAC,IAAI;YACN,CAAC,CAAC;gBACI,qBAAqB,EAAE;;;;aAI5B;gBAEK,2BAA2B,EAAE;;;;;;;;aAQlC;gBAEK,gCAAgC,EAAE;;sCAEd,IAAI,CAAC,cAAc;;;;;;;;;;;;;;;;;;aAkB5C;aACE,CAAC;IACZ,CAAC;;AAlJD;;GAEG;AACoB,4BAAI,GAAG,WAAW,AAAd,CAAe;AAMnC;IADN,SAAS,EAAE;sDACc;AAQnB;IAFN,SAAS,EAAE;IACX,gBAAgB,CAAC,kCAAkC,CAAC;0DAC5B;AAoI7B,aAAa,CAAC,iCAAiC,EAAE,uBAAuB,CAAC,CAAC","sourcesContent":["/**\r\n * Reflective Shadow Maps were first described in http://www.klayge.org/material/3_12/GI/rsm.pdf by Carsten Dachsbacher and Marc Stamminger\r\n * The ReflectiveShadowMap class only implements the geometry buffer generation part.\r\n * For the global illumination effect, see the GIRSMManager class.\r\n */\r\nimport { Constants } from \"core/Engines/constants\";\r\nimport type { ShadowLight } from \"core/Lights/shadowLight\";\r\nimport { MultiRenderTarget } from \"core/Materials/Textures/multiRenderTarget\";\r\nimport type { UniformBuffer } from \"core/Materials/uniformBuffer\";\r\nimport { Color3, Color4 } from \"core/Maths/math.color\";\r\nimport { Matrix, TmpVectors } from \"core/Maths/math.vector\";\r\nimport type { AbstractMesh } from \"core/Meshes/abstractMesh\";\r\nimport type { Scene } from \"core/scene\";\r\nimport type { WebGPURenderTargetWrapper } from \"core/Engines/WebGPU/webgpuRenderTargetWrapper\";\r\nimport { MaterialPluginBase } from \"core/Materials/materialPluginBase\";\r\nimport type { Material } from \"core/Materials/material\";\r\nimport type { StandardMaterial } from \"core/Materials/standardMaterial\";\r\nimport { MaterialDefines } from \"core/Materials/materialDefines\";\r\nimport type { SpotLight } from \"core/Lights/spotLight\";\r\nimport { PBRBaseMaterial } from \"core/Materials/PBR/pbrBaseMaterial\";\r\nimport { expandToProperty, serialize } from \"core/Misc/decorators\";\r\nimport { RegisterClass } from \"core/Misc/typeStore\";\r\nimport { Light } from \"core/Lights/light\";\r\n\r\n/**\r\n * Class used to generate the RSM (Reflective Shadow Map) textures for a given light.\r\n * The textures are: position (in world space), normal (in world space) and flux (light intensity)\r\n */\r\nexport class ReflectiveShadowMap {\r\n private _scene: Scene;\r\n private _light: ShadowLight;\r\n private _lightTransformMatrix: Matrix = Matrix.Identity();\r\n private _mrt: MultiRenderTarget;\r\n private _textureDimensions: { width: number; height: number };\r\n private _regularMatToMatWithPlugin: Map<Material, Material>;\r\n private _counters: Array<{ name: string; value: number }>;\r\n\r\n private _enable = false;\r\n\r\n /**\r\n * Enables or disables the RSM generation.\r\n */\r\n public get enable() {\r\n return this._enable;\r\n }\r\n\r\n public set enable(value: boolean) {\r\n if (this._enable === value) {\r\n return;\r\n }\r\n\r\n this._enable = value;\r\n this._customRenderTarget(value);\r\n }\r\n\r\n /**\r\n * Gets the position texture generated by the RSM process.\r\n */\r\n public get positionWorldTexture() {\r\n return this._mrt.textures[0];\r\n }\r\n\r\n /**\r\n * Gets the normal texture generated by the RSM process.\r\n */\r\n public get normalWorldTexture() {\r\n return this._mrt.textures[1];\r\n }\r\n\r\n /**\r\n * Gets the flux texture generated by the RSM process.\r\n */\r\n public get fluxTexture() {\r\n return this._mrt.textures[2];\r\n }\r\n\r\n /**\r\n * Gets the render list used to generate the RSM textures.\r\n */\r\n public get renderList() {\r\n return this._mrt.renderList;\r\n }\r\n\r\n /**\r\n * Gets the light used to generate the RSM textures.\r\n */\r\n public get light() {\r\n return this._light;\r\n }\r\n\r\n /**\r\n * Gets or sets a boolean indicating if the light parameters should be recomputed even if the light parameters (position, direction) did not change.\r\n * You should not set this value to true, except for debugging purpose (if you want to see changes from the inspector, for eg).\r\n * Instead, you should call updateLightParameters() explicitely at the right time (once the light parameters changed).\r\n */\r\n public forceUpdateLightParameters = false;\r\n\r\n /**\r\n * Creates a new RSM for the given light.\r\n * @param scene The scene\r\n * @param light The light to use to generate the RSM textures\r\n * @param textureDimensions The dimensions of the textures to generate. Default: \\{ width: 512, height: 512 \\}\r\n */\r\n constructor(scene: Scene, light: ShadowLight, textureDimensions = { width: 512, height: 512 }) {\r\n this._scene = scene;\r\n this._light = light;\r\n this._textureDimensions = textureDimensions;\r\n this._regularMatToMatWithPlugin = new Map();\r\n this._counters = [{ name: \"RSM Generation \" + light.name, value: 0 }];\r\n\r\n this._createMultiRenderTarget();\r\n this._recomputeLightTransformationMatrix();\r\n\r\n this.enable = true;\r\n }\r\n\r\n /**\r\n * Sets the dimensions of the textures to generate.\r\n * @param dimensions The dimensions of the textures to generate.\r\n */\r\n public setTextureDimensions(dimensions: { width: number; height: number }) {\r\n const renderList = this._mrt.renderList;\r\n\r\n this._textureDimensions = dimensions;\r\n this._disposeMultiRenderTarget();\r\n this._createMultiRenderTarget();\r\n\r\n renderList?.forEach((mesh) => {\r\n this._addMeshToMRT(mesh);\r\n });\r\n }\r\n\r\n /**\r\n * Adds the given mesh to the render list used to generate the RSM textures.\r\n * @param mesh The mesh to add to the render list used to generate the RSM textures. If not provided, all scene meshes will be added to the render list.\r\n */\r\n public addMesh(mesh?: AbstractMesh) {\r\n if (mesh) {\r\n this._addMeshToMRT(mesh);\r\n } else {\r\n this._scene.meshes.forEach((mesh) => {\r\n this._addMeshToMRT(mesh);\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * Recomputes the light transformation matrix. Call this method if you manually changed the light position / direction / etc. and you want to update the RSM textures accordingly.\r\n */\r\n public updateLightParameters() {\r\n this._recomputeLightTransformationMatrix();\r\n }\r\n\r\n /**\r\n * Gets the light transformation matrix used to generate the RSM textures.\r\n */\r\n public get lightTransformationMatrix() {\r\n if (this.forceUpdateLightParameters) {\r\n this.updateLightParameters();\r\n }\r\n return this._lightTransformMatrix;\r\n }\r\n\r\n /**\r\n * Gets the GPU time spent to generate the RSM textures.\r\n */\r\n public get countersGPU(): Array<{ name: string; value: number }> {\r\n return this._counters;\r\n }\r\n\r\n /**\r\n * Disposes the RSM.\r\n */\r\n public dispose() {\r\n this._disposeMultiRenderTarget();\r\n }\r\n\r\n protected _createMultiRenderTarget() {\r\n const name = this._light.name;\r\n\r\n const caps = this._scene.getEngine().getCaps();\r\n\r\n const fluxTextureType = caps.rg11b10ufColorRenderable ? Constants.TEXTURETYPE_UNSIGNED_INT_10F_11F_11F_REV : Constants.TEXTURETYPE_HALF_FLOAT;\r\n const fluxTextureFormat = caps.rg11b10ufColorRenderable ? Constants.TEXTUREFORMAT_RGB : Constants.TEXTUREFORMAT_RGBA;\r\n\r\n this._mrt = new MultiRenderTarget(\r\n \"RSMmrt_\" + name,\r\n this._textureDimensions,\r\n 3, // number of RTT - position / normal / flux\r\n this._scene,\r\n {\r\n types: [Constants.TEXTURETYPE_HALF_FLOAT, Constants.TEXTURETYPE_UNSIGNED_INT_2_10_10_10_REV, fluxTextureType],\r\n samplingModes: [Constants.TEXTURE_BILINEAR_SAMPLINGMODE, Constants.TEXTURE_BILINEAR_SAMPLINGMODE, Constants.TEXTURE_BILINEAR_SAMPLINGMODE],\r\n generateMipMaps: false,\r\n targetTypes: [Constants.TEXTURE_2D, Constants.TEXTURE_2D, Constants.TEXTURE_2D],\r\n formats: [Constants.TEXTUREFORMAT_RGBA, Constants.TEXTUREFORMAT_RGBA, fluxTextureFormat],\r\n },\r\n [\"RSMPosition_\" + name, \"RSMNormal_\" + name, \"RSMFlux_\" + name]\r\n );\r\n\r\n this._mrt.renderList = [];\r\n this._mrt.clearColor = new Color4(0, 0, 0, 1);\r\n this._mrt.noPrePassRenderer = true;\r\n\r\n let sceneUBO: UniformBuffer;\r\n let currentSceneUBO: UniformBuffer;\r\n\r\n const useUBO = this._scene.getEngine().supportsUniformBuffers;\r\n\r\n if (useUBO) {\r\n sceneUBO = this._scene.createSceneUniformBuffer(`Scene for RSM (light \"${name}\")`);\r\n }\r\n\r\n let shadowEnabled: boolean;\r\n\r\n this._mrt.onBeforeBindObservable.add(() => {\r\n currentSceneUBO = this._scene.getSceneUniformBuffer();\r\n shadowEnabled = this._light.shadowEnabled;\r\n this._light.shadowEnabled = false; // we render from the light point of view, so we won't have any shadow anyway!\r\n });\r\n\r\n this._mrt.onBeforeRenderObservable.add((faceIndex: number) => {\r\n if (sceneUBO) {\r\n this._scene.setSceneUniformBuffer(sceneUBO);\r\n }\r\n const viewMatrix = this._light.getViewMatrix(faceIndex);\r\n const projectionMatrix = this._light.getProjectionMatrix(viewMatrix || undefined, this._mrt.renderList || undefined);\r\n if (viewMatrix && projectionMatrix) {\r\n this._scene.setTransformMatrix(viewMatrix, projectionMatrix);\r\n }\r\n if (useUBO) {\r\n this._scene.getSceneUniformBuffer().unbindEffect();\r\n this._scene.finalizeSceneUbo();\r\n }\r\n });\r\n\r\n this._mrt.onAfterUnbindObservable.add(() => {\r\n if (sceneUBO) {\r\n this._scene.setSceneUniformBuffer(currentSceneUBO);\r\n }\r\n this._scene.updateTransformMatrix(); // restore the view/projection matrices of the active camera\r\n this._light.shadowEnabled = shadowEnabled;\r\n this._counters[0].value = (this._mrt.renderTarget as WebGPURenderTargetWrapper).gpuTimeInFrame?.counter.lastSecAverage ?? 0;\r\n });\r\n\r\n this._customRenderTarget(true);\r\n }\r\n\r\n protected _customRenderTarget(add: boolean) {\r\n const idx = this._scene.customRenderTargets.indexOf(this._mrt);\r\n if (add) {\r\n if (idx === -1) {\r\n this._scene.customRenderTargets.push(this._mrt);\r\n }\r\n } else if (idx !== -1) {\r\n this._scene.customRenderTargets.splice(idx, 1);\r\n }\r\n }\r\n\r\n protected _recomputeLightTransformationMatrix() {\r\n const viewMatrix = this._light.getViewMatrix();\r\n const projectionMatrix = this._light.getProjectionMatrix(viewMatrix || undefined, this._mrt.renderList || undefined);\r\n if (viewMatrix && projectionMatrix) {\r\n viewMatrix.multiplyToRef(projectionMatrix, this._lightTransformMatrix);\r\n }\r\n }\r\n\r\n protected _addMeshToMRT(mesh: AbstractMesh) {\r\n this._mrt.renderList?.push(mesh);\r\n\r\n const material = mesh.material;\r\n if (mesh.getTotalVertices() === 0 || !material) {\r\n return;\r\n }\r\n\r\n let rsmMaterial = this._regularMatToMatWithPlugin.get(material);\r\n if (!rsmMaterial) {\r\n rsmMaterial = material.clone(\"RSMCreate_\" + material.name) || undefined;\r\n if (rsmMaterial) {\r\n // Disable the prepass renderer for this material\r\n Object.defineProperty(rsmMaterial, \"canRenderToMRT\", {\r\n get: function () {\r\n return false;\r\n },\r\n enumerable: true,\r\n configurable: true,\r\n });\r\n\r\n (rsmMaterial as any).disableLighting = true;\r\n\r\n const rsmCreatePlugin = new RSMCreatePluginMaterial(rsmMaterial);\r\n\r\n rsmCreatePlugin.isEnabled = true;\r\n rsmCreatePlugin.light = this._light;\r\n\r\n this._regularMatToMatWithPlugin.set(material, rsmMaterial);\r\n }\r\n }\r\n\r\n this._mrt.setMaterialForRendering(mesh, rsmMaterial);\r\n }\r\n\r\n protected _disposeMultiRenderTarget() {\r\n this._customRenderTarget(false);\r\n this._mrt.dispose();\r\n }\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nclass MaterialRSMCreateDefines extends MaterialDefines {\r\n public RSMCREATE = false;\r\n public RSMCREATE_PROJTEXTURE = false;\r\n public RSMCREATE_LIGHT_IS_SPOT = false;\r\n}\r\n\r\n/**\r\n * Plugin that implements the creation of the RSM textures\r\n */\r\nexport class RSMCreatePluginMaterial extends MaterialPluginBase {\r\n private _varAlbedoName: string;\r\n private _lightColor = new Color3();\r\n private _hasProjectionTexture = false;\r\n\r\n /**\r\n * Defines the name of the plugin.\r\n */\r\n public static readonly Name = \"RSMCreate\";\r\n\r\n /**\r\n * Defines the light that should be used to generate the RSM textures.\r\n */\r\n @serialize()\r\n public light: ShadowLight;\r\n\r\n private _isEnabled = false;\r\n /**\r\n * Defines if the plugin is enabled in the material.\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public isEnabled = false;\r\n\r\n protected _markAllSubMeshesAsTexturesDirty(): void {\r\n this._enable(this._isEnabled);\r\n this._internalMarkAllSubMeshesAsTexturesDirty();\r\n }\r\n\r\n private _internalMarkAllSubMeshesAsTexturesDirty: () => void;\r\n\r\n constructor(material: Material | StandardMaterial | PBRBaseMaterial) {\r\n super(material, RSMCreatePluginMaterial.Name, 300, new MaterialRSMCreateDefines());\r\n\r\n this._internalMarkAllSubMeshesAsTexturesDirty = material._dirtyCallbacks[Constants.MATERIAL_TextureDirtyFlag];\r\n\r\n this._varAlbedoName = material instanceof PBRBaseMaterial ? \"surfaceAlbedo\" : \"baseColor.rgb\";\r\n }\r\n\r\n public prepareDefines(defines: MaterialRSMCreateDefines) {\r\n defines.RSMCREATE = this._isEnabled;\r\n\r\n this._hasProjectionTexture = false;\r\n\r\n const isSpot = this.light.getTypeID() === Light.LIGHTTYPEID_SPOTLIGHT;\r\n if (isSpot) {\r\n const spot = this.light as SpotLight;\r\n this._hasProjectionTexture = spot.projectionTexture ? spot.projectionTexture.isReady() : false;\r\n }\r\n\r\n defines.RSMCREATE_PROJTEXTURE = this._hasProjectionTexture;\r\n defines.RSMCREATE_LIGHT_IS_SPOT = isSpot;\r\n }\r\n\r\n public getClassName() {\r\n return \"RSMCreatePluginMaterial\";\r\n }\r\n\r\n public getUniforms() {\r\n return {\r\n ubo: [\r\n { name: \"rsmTextureProjectionMatrix\", size: 16, type: \"mat4\" },\r\n { name: \"rsmSpotInfo\", size: 4, type: \"vec4\" },\r\n { name: \"rsmLightColor\", size: 3, type: \"vec3\" },\r\n { name: \"rsmLightPosition\", size: 3, type: \"vec3\" },\r\n ],\r\n fragment: `#ifdef RSMCREATE\r\n uniform mat4 rsmTextureProjectionMatrix;\r\n uniform vec4 rsmSpotInfo;\r\n uniform vec3 rsmLightColor;\r\n unfiorm vec3 rsmLightPosition;\r\n #endif`,\r\n };\r\n }\r\n\r\n public getSamplers(samplers: string[]) {\r\n samplers.push(\"rsmTextureProjectionSampler\");\r\n }\r\n\r\n public bindForSubMesh(uniformBuffer: UniformBuffer) {\r\n if (!this._isEnabled) {\r\n return;\r\n }\r\n\r\n this.light.diffuse.scaleToRef(this.light.getScaledIntensity(), this._lightColor);\r\n uniformBuffer.updateColor3(\"rsmLightColor\", this._lightColor);\r\n\r\n if (this.light.getTypeID() === Light.LIGHTTYPEID_SPOTLIGHT) {\r\n const spot = this.light as SpotLight;\r\n\r\n if (this._hasProjectionTexture) {\r\n uniformBuffer.updateMatrix(\"rsmTextureProjectionMatrix\", spot.projectionTextureMatrix);\r\n uniformBuffer.setTexture(\"rsmTextureProjectionSampler\", spot.projectionTexture);\r\n }\r\n\r\n const normalizeDirection = TmpVectors.Vector3[0];\r\n\r\n if (spot.computeTransformedInformation()) {\r\n uniformBuffer.updateFloat3(\"rsmLightPosition\", this.light.transformedPosition.x, this.light.transformedPosition.y, this.light.transformedPosition.z);\r\n spot.transformedDirection.normalizeToRef(normalizeDirection);\r\n } else {\r\n uniformBuffer.updateFloat3(\"rsmLightPosition\", this.light.position.x, this.light.position.y, this.light.position.z);\r\n spot.direction.normalizeToRef(normalizeDirection);\r\n }\r\n\r\n uniformBuffer.updateFloat4(\"rsmSpotInfo\", normalizeDirection.x, normalizeDirection.y, normalizeDirection.z, Math.cos(spot.angle * 0.5));\r\n }\r\n }\r\n\r\n public getCustomCode(shaderType: string) {\r\n return shaderType === \"vertex\"\r\n ? null\r\n : {\r\n CUSTOM_FRAGMENT_BEGIN: `\r\n #ifdef RSMCREATE\r\n #extension GL_EXT_draw_buffers : require\r\n #endif\r\n `,\r\n\r\n CUSTOM_FRAGMENT_DEFINITIONS: `\r\n #ifdef RSMCREATE\r\n #ifdef RSMCREATE_PROJTEXTURE\r\n uniform highp sampler2D rsmTextureProjectionSampler; \r\n #endif\r\n layout(location = 0) out highp vec4 glFragData[3];\r\n vec4 glFragColor;\r\n #endif\r\n `,\r\n\r\n CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR: `\r\n #ifdef RSMCREATE\r\n vec3 rsmColor = ${this._varAlbedoName} * rsmLightColor;\r\n #ifdef RSMCREATE_PROJTEXTURE\r\n {\r\n vec4 strq = rsmTextureProjectionMatrix * vec4(vPositionW, 1.0);\r\n strq /= strq.w;\r\n rsmColor *= texture2D(rsmTextureProjectionSampler, strq.xy).rgb;\r\n }\r\n #endif\r\n #ifdef RSMCREATE_LIGHT_IS_SPOT\r\n {\r\n float cosAngle = max(0., dot(rsmSpotInfo.xyz, normalize(vPositionW - rsmLightPosition)));\r\n rsmColor = sign(cosAngle - rsmSpotInfo.w) * rsmColor;\r\n }\r\n #endif\r\n glFragData[0] = vec4(vPositionW, 1.);\r\n glFragData[1] = vec4(normalize(normalW) * 0.5 + 0.5, 1.);\r\n glFragData[2] = vec4(rsmColor, 1.);\r\n #endif\r\n `,\r\n };\r\n }\r\n}\r\n\r\nRegisterClass(`BABYLON.RSMCreatePluginMaterial`, RSMCreatePluginMaterial);\r\n"]}
@@ -0,0 +1,5 @@
1
+ /** @internal */
2
+ export declare const bilateralBlurPixelShader: {
3
+ name: string;
4
+ shader: string;
5
+ };
@@ -0,0 +1,20 @@
1
+ // Do not edit.
2
+ import { ShaderStore } from "../Engines/shaderStore.js";
3
+ const name = "bilateralBlurPixelShader";
4
+ const shader = `uniform sampler2D textureSampler;uniform sampler2D depthSampler;uniform sampler2D normalSampler;uniform int filterSize;uniform vec2 blurDir;uniform float depthThreshold;uniform float normalThreshold;varying vec2 vUV;void main(void) {vec3 color=textureLod(textureSampler,vUV,0.).rgb;float depth=textureLod(depthSampler,vUV,0.).x;if (depth>=1e6 || depth<=0.) {glFragColor=vec4(color,1.);return;}
5
+ vec3 normal=textureLod(normalSampler,vUV,0.).rgb;
6
+ #ifdef DECODE_NORMAL
7
+ normal=normal*2.0-1.0;
8
+ #endif
9
+ float sigma=float(filterSize);float two_sigma2=2.0*sigma*sigma;float sigmaDepth=depthThreshold;float two_sigmaDepth2=2.0*sigmaDepth*sigmaDepth;float sigmaNormal=normalThreshold;float two_sigmaNormal2=2.0*sigmaNormal*sigmaNormal;vec3 sum=vec3(0.);float wsum=0.;for (int x=-filterSize; x<=filterSize; ++x) {vec2 coords=vec2(x);vec3 sampleColor=textureLod(textureSampler,vUV+coords*blurDir,0.).rgb;float sampleDepth=textureLod(depthSampler,vUV+coords*blurDir,0.).r;vec3 sampleNormal=textureLod(normalSampler,vUV+coords*blurDir,0.).rgb;
10
+ #ifdef DECODE_NORMAL
11
+ sampleNormal=sampleNormal*2.0-1.0;
12
+ #endif
13
+ float r=dot(coords,coords);float w=exp(-r/two_sigma2);float depthDelta=abs(sampleDepth-depth);float wd=step(depthDelta,depthThreshold);vec3 normalDelta=abs(sampleNormal-normal);float wn=step(normalDelta.x+normalDelta.y+normalDelta.z,normalThreshold);sum+=sampleColor*w*wd*wn;wsum+=w*wd*wn;}
14
+ glFragColor=vec4(sum/wsum,1.);}
15
+ `;
16
+ // Sideeffect
17
+ ShaderStore.ShadersStore[name] = shader;
18
+ /** @internal */
19
+ export const bilateralBlurPixelShader = { name, shader };
20
+ //# sourceMappingURL=bilateralBlur.fragment.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bilateralBlur.fragment.js","sourceRoot":"","sources":["../../../../dev/core/src/Shaders/bilateralBlur.fragment.ts"],"names":[],"mappings":"AAAA,eAAe;AACf,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAErD,MAAM,IAAI,GAAG,0BAA0B,CAAC;AACxC,MAAM,MAAM,GAAG;;;;;;;;;;;CAWd,CAAC;AACF,aAAa;AACb,WAAW,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC;AACxC,gBAAgB;AAChB,MAAM,CAAC,MAAM,wBAAwB,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC","sourcesContent":["// Do not edit.\nimport { ShaderStore } from \"../Engines/shaderStore\";\n\nconst name = \"bilateralBlurPixelShader\";\nconst shader = `uniform sampler2D textureSampler;uniform sampler2D depthSampler;uniform sampler2D normalSampler;uniform int filterSize;uniform vec2 blurDir;uniform float depthThreshold;uniform float normalThreshold;varying vec2 vUV;void main(void) {vec3 color=textureLod(textureSampler,vUV,0.).rgb;float depth=textureLod(depthSampler,vUV,0.).x;if (depth>=1e6 || depth<=0.) {glFragColor=vec4(color,1.);return;}\nvec3 normal=textureLod(normalSampler,vUV,0.).rgb;\n#ifdef DECODE_NORMAL\nnormal=normal*2.0-1.0;\n#endif\nfloat sigma=float(filterSize);float two_sigma2=2.0*sigma*sigma;float sigmaDepth=depthThreshold;float two_sigmaDepth2=2.0*sigmaDepth*sigmaDepth;float sigmaNormal=normalThreshold;float two_sigmaNormal2=2.0*sigmaNormal*sigmaNormal;vec3 sum=vec3(0.);float wsum=0.;for (int x=-filterSize; x<=filterSize; ++x) {vec2 coords=vec2(x);vec3 sampleColor=textureLod(textureSampler,vUV+coords*blurDir,0.).rgb;float sampleDepth=textureLod(depthSampler,vUV+coords*blurDir,0.).r;vec3 sampleNormal=textureLod(normalSampler,vUV+coords*blurDir,0.).rgb;\n#ifdef DECODE_NORMAL\nsampleNormal=sampleNormal*2.0-1.0;\n#endif\nfloat r=dot(coords,coords);float w=exp(-r/two_sigma2);float depthDelta=abs(sampleDepth-depth);float wd=step(depthDelta,depthThreshold);vec3 normalDelta=abs(sampleNormal-normal);float wn=step(normalDelta.x+normalDelta.y+normalDelta.z,normalThreshold);sum+=sampleColor*w*wd*wn;wsum+=w*wd*wn;}\nglFragColor=vec4(sum/wsum,1.);}\n`;\n// Sideeffect\nShaderStore.ShadersStore[name] = shader;\n/** @internal */\nexport const bilateralBlurPixelShader = { name, shader };\n"]}
@@ -0,0 +1,5 @@
1
+ /** @internal */
2
+ export declare const bilateralBlurQualityPixelShader: {
3
+ name: string;
4
+ shader: string;
5
+ };