@babylonjs/core 7.31.0 → 7.31.1

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.
@@ -13,6 +13,7 @@ export class SnapshotRenderingHelper {
13
13
  */
14
14
  constructor(scene, options) {
15
15
  this._disableRenderingRefCount = 0;
16
+ this._currentPerformancePriorityMode = 0 /* ScenePerformancePriority.BackwardCompatible */;
16
17
  this._scene = scene;
17
18
  this._engine = scene.getEngine();
18
19
  if (!this._engine.isWebGPU) {
@@ -25,14 +26,12 @@ export class SnapshotRenderingHelper {
25
26
  this._engine.snapshotRenderingMode = 1;
26
27
  this.fixMeshes();
27
28
  this._onResizeObserver = this._engine.onResizeObservable.add(() => {
28
- const save = this._engine.snapshotRendering;
29
- this._engine.snapshotRendering = false;
30
- if (save) {
31
- this.enableSnapshotRendering();
32
- }
29
+ // enableSnapshotRendering() will delay the actual enabling of snapshot rendering by at least a frame, so these two lines are not redundant!
30
+ this.disableSnapshotRendering();
31
+ this.enableSnapshotRendering();
33
32
  });
34
33
  this._scene.onBeforeRenderObservable.add(() => {
35
- if (!this._engine.snapshotRendering || this._engine.snapshotRenderingMode !== 1) {
34
+ if (!this._fastSnapshotRenderingEnabled) {
36
35
  return;
37
36
  }
38
37
  // Animate skeletons
@@ -76,6 +75,9 @@ export class SnapshotRenderingHelper {
76
75
  return;
77
76
  }
78
77
  this._disableRenderingRefCount = 0;
78
+ this._currentPerformancePriorityMode = this._pendingCurrentPerformancePriorityMode ?? this._scene.performancePriority;
79
+ this._pendingCurrentPerformancePriorityMode = undefined;
80
+ this._scene.performancePriority = 0 /* ScenePerformancePriority.BackwardCompatible */;
79
81
  this._scene.executeWhenReady(() => {
80
82
  if (this._disableRenderingRefCount > 0) {
81
83
  return;
@@ -94,6 +96,24 @@ export class SnapshotRenderingHelper {
94
96
  if (!this._engine.isWebGPU) {
95
97
  return;
96
98
  }
99
+ if (this._disableRenderingRefCount === 0) {
100
+ // Snapshot rendering switches from enabled to disabled
101
+ // We reset the performance priority mode to that which it was before enabling snapshot rendering, but first set it to “BackwardCompatible” to allow the system to regenerate resources that may have been optimized for snapshot rendering.
102
+ // We'll then restore the original mode at the next frame.
103
+ this._scene.performancePriority = 0 /* ScenePerformancePriority.BackwardCompatible */;
104
+ if (this._currentPerformancePriorityMode !== 0 /* ScenePerformancePriority.BackwardCompatible */) {
105
+ this._pendingCurrentPerformancePriorityMode = this._currentPerformancePriorityMode;
106
+ this._scene.executeWhenReady(() => {
107
+ this._executeAtFrame(this._engine.frameId + 2, () => {
108
+ // if this._disableRenderingRefCount === 0, snapshot rendering has been enabled in the meantime, so do nothing
109
+ if (this._disableRenderingRefCount > 0 && this._pendingCurrentPerformancePriorityMode !== undefined) {
110
+ this._scene.performancePriority = this._pendingCurrentPerformancePriorityMode;
111
+ }
112
+ this._pendingCurrentPerformancePriorityMode = undefined;
113
+ }, true);
114
+ });
115
+ }
116
+ }
97
117
  this._engine.snapshotRendering = false;
98
118
  this._disableRenderingRefCount++;
99
119
  }
@@ -114,6 +134,22 @@ export class SnapshotRenderingHelper {
114
134
  }
115
135
  }
116
136
  }
137
+ /**
138
+ * Call this method to update a mesh on the GPU after some properties have changed (position, rotation, scaling, visibility).
139
+ * @param mesh The mesh to update. Can be a single mesh or an array of meshes to update.
140
+ */
141
+ updateMesh(mesh) {
142
+ if (!this._fastSnapshotRenderingEnabled) {
143
+ return;
144
+ }
145
+ if (Array.isArray(mesh)) {
146
+ for (const m of mesh) {
147
+ m.transferToEffect(m.computeWorldMatrix(true));
148
+ }
149
+ return;
150
+ }
151
+ mesh.transferToEffect(mesh.computeWorldMatrix(true));
152
+ }
117
153
  /**
118
154
  * Update the meshes used in an effect layer to ensure that snapshot rendering works correctly for these meshes in this layer.
119
155
  * @param effectLayer The effect layer
@@ -144,7 +180,13 @@ export class SnapshotRenderingHelper {
144
180
  this._scene.onBeforeRenderObservable.remove(this._onBeforeRenderObserverUpdateLayer);
145
181
  this._engine.onResizeObservable.remove(this._onResizeObserver);
146
182
  }
183
+ get _fastSnapshotRenderingEnabled() {
184
+ return this._engine.snapshotRendering && this._engine.snapshotRenderingMode === 1;
185
+ }
147
186
  _updateMeshMatricesForRenderPassId(renderPassId) {
187
+ if (!this._fastSnapshotRenderingEnabled) {
188
+ return;
189
+ }
148
190
  const sceneTransformationMatrix = this._scene.getTransformMatrix();
149
191
  for (let i = 0; i < this._scene.meshes.length; ++i) {
150
192
  const mesh = this._scene.meshes[i];
@@ -166,9 +208,9 @@ export class SnapshotRenderingHelper {
166
208
  }
167
209
  }
168
210
  }
169
- _executeAtFrame(frameId, func) {
211
+ _executeAtFrame(frameId, func, executeWhenModeIsDisabled = false) {
170
212
  const obs = this._engine.onEndFrameObservable.add(() => {
171
- if (this._disableRenderingRefCount > 0) {
213
+ if ((this._disableRenderingRefCount > 0 && !executeWhenModeIsDisabled) || (this._disableRenderingRefCount === 0 && executeWhenModeIsDisabled)) {
172
214
  this._engine.onEndFrameObservable.remove(obs);
173
215
  return;
174
216
  }
@@ -1 +1 @@
1
- {"version":3,"file":"snapshotRenderingHelper.js","sourceRoot":"","sources":["../../../../dev/core/src/Misc/snapshotRenderingHelper.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,gCAA+B;AACnD,OAAO,EAAE,yBAAyB,EAAE,iDAAgD;AAgBpF;;GAEG;AACH,MAAM,OAAO,uBAAuB;IAShC;;;;;;OAMG;IACH,YAAY,KAAY,EAAE,OAAyC;QAT3D,8BAAyB,GAAG,CAAC,CAAC;QAUlC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,SAAS,EAAE,CAAC;QAEjC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE;YACxB,OAAO;SACV;QAED,IAAI,CAAC,QAAQ,GAAG;YACZ,4BAA4B,EAAE,EAAE;YAChC,GAAG,OAAO;SACb,CAAC;QAEF,IAAI,CAAC,OAAO,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;SACJ;IACL,CAAC;IAEO,eAAe,CAAC,OAAe,EAAE,IAAgB;QACrD,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,GAAG,CAAC,GAAG,EAAE;YACnD,IAAI,IAAI,CAAC,yBAAyB,GAAG,CAAC,EAAE;gBACpC,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;gBAC9C,OAAO;aACV;YACD,IAAI,IAAI,CAAC,OAAO,CAAC,OAAO,IAAI,OAAO,EAAE;gBACjC,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;gBAC9C,IAAI,EAAE,CAAC;aACV;QACL,CAAC,CAAC,CAAC;IACP,CAAC;CACJ","sourcesContent":["// eslint-disable-next-line import/no-internal-modules\r\nimport type { AbstractEngine, AbstractMesh, EffectLayer, Mesh, Nullable, Observer, Scene, WebGPUDrawContext, WebGPUShaderProcessor, WebGPUPipelineContext } from \"core/index\";\r\n\r\nimport { Constants } from \"core/Engines/constants\";\r\nimport { BindMorphTargetParameters } from \"core/Materials/materialHelper.functions\";\r\n\r\n/**\r\n * Options for the snapshot rendering helper\r\n */\r\nexport interface SnapshotRenderingHelpersOptions {\r\n /**\r\n * Maximum number of influences for morph target managers\r\n * In FAST snapshot mode, the number of influences must be fixed and cannot change from one frame to the next.\r\n * morphTargetsNumMaxInfluences is the maximum number of non-zero influences allowed in a morph target manager.\r\n * The final value defined for a morph target manager is: Math.min(morphTargetManager.numTargets, morphTargetsNumMaxInfluences)\r\n * Default: 20\r\n */\r\n morphTargetsNumMaxInfluences?: number;\r\n}\r\n\r\n/**\r\n * A helper class to simplify work with FAST snapshot mode (WebGPU only - can be used in WebGL too, but won't do anything).\r\n */\r\nexport class SnapshotRenderingHelper {\r\n private readonly _engine: AbstractEngine;\r\n private readonly _scene: Scene;\r\n private readonly _options: SnapshotRenderingHelpersOptions;\r\n private readonly _onBeforeRenderObserver: Nullable<Observer<Scene>>;\r\n private _onBeforeRenderObserverUpdateLayer: Nullable<Observer<Scene>>;\r\n private readonly _onResizeObserver: Nullable<Observer<AbstractEngine>>;\r\n private _disableRenderingRefCount = 0;\r\n\r\n /**\r\n * Creates a new snapshot rendering helper\r\n * Note that creating an instance of the helper will set the snapshot rendering mode to SNAPSHOTRENDERING_FAST but will not enable snapshot rendering (engine.snapshotRendering is not updated).\r\n * Note also that fixMeshes() is called as part of the construction\r\n * @param scene The scene to use the helper in\r\n * @param options The options for the helper\r\n */\r\n constructor(scene: Scene, options?: SnapshotRenderingHelpersOptions) {\r\n this._scene = scene;\r\n this._engine = scene.getEngine();\r\n\r\n if (!this._engine.isWebGPU) {\r\n return;\r\n }\r\n\r\n this._options = {\r\n morphTargetsNumMaxInfluences: 20,\r\n ...options,\r\n };\r\n\r\n this._engine.snapshotRenderingMode = Constants.SNAPSHOTRENDERING_FAST;\r\n\r\n this.fixMeshes();\r\n\r\n this._onResizeObserver = this._engine.onResizeObservable.add(() => {\r\n const save = this._engine.snapshotRendering;\r\n this._engine.snapshotRendering = false;\r\n if (save) {\r\n this.enableSnapshotRendering();\r\n }\r\n });\r\n\r\n this._scene.onBeforeRenderObservable.add(() => {\r\n if (!this._engine.snapshotRendering || this._engine.snapshotRenderingMode !== Constants.SNAPSHOTRENDERING_FAST) {\r\n return;\r\n }\r\n\r\n // Animate skeletons\r\n scene.skeletons.forEach((skeleton) => skeleton.prepare(true));\r\n\r\n for (const mesh of scene.meshes) {\r\n if (mesh.infiniteDistance) {\r\n mesh.transferToEffect(mesh.computeWorldMatrix(true));\r\n }\r\n\r\n if (mesh.skeleton) {\r\n mesh.transferToEffect(mesh.computeWorldMatrix(true));\r\n }\r\n\r\n if (mesh.morphTargetManager && mesh.subMeshes) {\r\n // Make sure morph target animations work\r\n for (const subMesh of mesh.subMeshes) {\r\n const dw = subMesh._drawWrapper;\r\n const effect = dw.effect;\r\n if (effect) {\r\n const dataBuffer = (dw.drawContext as WebGPUDrawContext).buffers[\"LeftOver\" satisfies (typeof WebGPUShaderProcessor)[\"LeftOvertUBOName\"]];\r\n const ubLeftOver = (effect._pipelineContext as WebGPUPipelineContext)?.uniformBuffer;\r\n if (dataBuffer && ubLeftOver && ubLeftOver.setDataBuffer(dataBuffer)) {\r\n mesh.morphTargetManager._bind(effect);\r\n BindMorphTargetParameters(mesh, effect);\r\n ubLeftOver.update();\r\n }\r\n }\r\n }\r\n }\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Enable snapshot rendering\r\n * Use this method instead of engine.snapshotRendering=true, to make sure everything is ready before enabling snapshot rendering.\r\n * Note that this method is ref-counted and works in pair with disableSnapshotRendering(): you should call enableSnapshotRendering() as many times as you call disableSnapshotRendering().\r\n */\r\n public enableSnapshotRendering() {\r\n if (!this._engine.isWebGPU) {\r\n return;\r\n }\r\n\r\n if (--this._disableRenderingRefCount > 0) {\r\n return;\r\n }\r\n\r\n this._disableRenderingRefCount = 0;\r\n\r\n this._scene.executeWhenReady(() => {\r\n if (this._disableRenderingRefCount > 0) {\r\n return;\r\n }\r\n\r\n // Make sure a full frame is rendered before enabling snapshot rendering, so use \"+2\" instead of \"+1\"\r\n this._executeAtFrame(this._engine.frameId + 2, () => {\r\n this._engine.snapshotRendering = true;\r\n });\r\n });\r\n }\r\n\r\n /**\r\n * Disable snapshot rendering\r\n * Note that this method is ref-counted and works in pair with disableSnapshotRendering(): you should call enableSnapshotRendering() as many times as you call disableSnapshotRendering().\r\n */\r\n public disableSnapshotRendering() {\r\n if (!this._engine.isWebGPU) {\r\n return;\r\n }\r\n\r\n this._engine.snapshotRendering = false;\r\n this._disableRenderingRefCount++;\r\n }\r\n\r\n /**\r\n * Fix meshes for snapshot rendering.\r\n * This method will make sure that some features are disabled or fixed to make sure snapshot rendering works correctly.\r\n * @param meshes List of meshes to fix. If not provided, all meshes in the scene will be fixed.\r\n */\r\n public fixMeshes(meshes?: AbstractMesh[]) {\r\n if (!this._engine.isWebGPU) {\r\n return;\r\n }\r\n\r\n meshes = meshes || this._scene.meshes;\r\n\r\n for (const mesh of meshes) {\r\n (mesh as Mesh).ignoreCameraMaxZ = false;\r\n if (mesh.morphTargetManager) {\r\n mesh.morphTargetManager.numMaxInfluencers = Math.min(mesh.morphTargetManager.numTargets, this._options.morphTargetsNumMaxInfluences!);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Update the meshes used in an effect layer to ensure that snapshot rendering works correctly for these meshes in this layer.\r\n * @param effectLayer The effect layer\r\n * @param autoUpdate If true, the helper will automatically update the effect layer meshes with each frame. If false, you'll need to call this method manually when the camera or layer meshes move or rotate.\r\n */\r\n public updateMeshesForEffectLayer(effectLayer: EffectLayer, autoUpdate = true) {\r\n if (!this._engine.isWebGPU) {\r\n return;\r\n }\r\n\r\n const renderPassId = effectLayer.mainTexture.renderPassId;\r\n\r\n if (autoUpdate) {\r\n this._onBeforeRenderObserverUpdateLayer = this._scene.onBeforeRenderObservable.add(() => {\r\n this._updateMeshMatricesForRenderPassId(renderPassId);\r\n });\r\n } else {\r\n this._updateMeshMatricesForRenderPassId(renderPassId);\r\n }\r\n }\r\n\r\n /**\r\n * Dispose the helper\r\n */\r\n public dispose() {\r\n if (!this._engine.isWebGPU) {\r\n return;\r\n }\r\n\r\n this._scene.onBeforeRenderObservable.remove(this._onBeforeRenderObserver);\r\n this._scene.onBeforeRenderObservable.remove(this._onBeforeRenderObserverUpdateLayer);\r\n this._engine.onResizeObservable.remove(this._onResizeObserver);\r\n }\r\n\r\n private _updateMeshMatricesForRenderPassId(renderPassId: number) {\r\n const sceneTransformationMatrix = this._scene.getTransformMatrix();\r\n\r\n for (let i = 0; i < this._scene.meshes.length; ++i) {\r\n const mesh = this._scene.meshes[i];\r\n if (!mesh.subMeshes) {\r\n continue;\r\n }\r\n\r\n for (let j = 0; j < mesh.subMeshes.length; ++j) {\r\n const dw = mesh.subMeshes[j]._getDrawWrapper(renderPassId);\r\n const effect = dw?.effect;\r\n if (effect) {\r\n const dataBuffer = (dw.drawContext as WebGPUDrawContext).buffers[\"LeftOver\" satisfies (typeof WebGPUShaderProcessor)[\"LeftOvertUBOName\"]];\r\n const ubLeftOver = (effect._pipelineContext as WebGPUPipelineContext)?.uniformBuffer;\r\n if (dataBuffer && ubLeftOver && ubLeftOver.setDataBuffer(dataBuffer)) {\r\n effect.setMatrix(\"viewProjection\", sceneTransformationMatrix);\r\n effect.setMatrix(\"world\", mesh.computeWorldMatrix());\r\n ubLeftOver.update();\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n private _executeAtFrame(frameId: number, func: () => void) {\r\n const obs = this._engine.onEndFrameObservable.add(() => {\r\n if (this._disableRenderingRefCount > 0) {\r\n this._engine.onEndFrameObservable.remove(obs);\r\n return;\r\n }\r\n if (this._engine.frameId >= frameId) {\r\n this._engine.onEndFrameObservable.remove(obs);\r\n func();\r\n }\r\n });\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"snapshotRenderingHelper.js","sourceRoot":"","sources":["../../../../dev/core/src/Misc/snapshotRenderingHelper.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,gCAA+B;AACnD,OAAO,EAAE,yBAAyB,EAAE,iDAAgD;AAiBpF;;GAEG;AACH,MAAM,OAAO,uBAAuB;IAWhC;;;;;;OAMG;IACH,YAAY,KAAY,EAAE,OAAyC;QAX3D,8BAAyB,GAAG,CAAC,CAAC;QAC9B,oCAA+B,uDAA+C;QAWlF,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,SAAS,EAAE,CAAC;QAEjC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE;YACxB,OAAO;SACV;QAED,IAAI,CAAC,QAAQ,GAAG;YACZ,4BAA4B,EAAE,EAAE;YAChC,GAAG,OAAO;SACb,CAAC;QAEF,IAAI,CAAC,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,sBAAsB,CAAC;QAEtE,IA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CAAC,MAAM,EAAE,CAAC;qBACvB;iBACJ;aACJ;SACJ;IACL,CAAC;IAEO,eAAe,CAAC,OAAe,EAAE,IAAgB,EAAE,yBAAyB,GAAG,KAAK;QACxF,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,GAAG,CAAC,GAAG,EAAE;YACnD,IAAI,CAAC,IAAI,CAAC,yBAAyB,GAAG,CAAC,IAAI,CAAC,yBAAyB,CAAC,IAAI,CAAC,IAAI,CAAC,yBAAyB,KAAK,CAAC,IAAI,yBAAyB,CAAC,EAAE;gBAC3I,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;gBAC9C,OAAO;aACV;YACD,IAAI,IAAI,CAAC,OAAO,CAAC,OAAO,IAAI,OAAO,EAAE;gBACjC,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;gBAC9C,IAAI,EAAE,CAAC;aACV;QACL,CAAC,CAAC,CAAC;IACP,CAAC;CACJ","sourcesContent":["// eslint-disable-next-line import/no-internal-modules\r\nimport type { AbstractEngine, AbstractMesh, EffectLayer, Mesh, Nullable, Observer, Scene, WebGPUDrawContext, WebGPUShaderProcessor, WebGPUPipelineContext } from \"core/index\";\r\n\r\nimport { Constants } from \"core/Engines/constants\";\r\nimport { BindMorphTargetParameters } from \"core/Materials/materialHelper.functions\";\r\nimport { ScenePerformancePriority } from \"core/scene\";\r\n\r\n/**\r\n * Options for the snapshot rendering helper\r\n */\r\nexport interface SnapshotRenderingHelpersOptions {\r\n /**\r\n * Maximum number of influences for morph target managers\r\n * In FAST snapshot mode, the number of influences must be fixed and cannot change from one frame to the next.\r\n * morphTargetsNumMaxInfluences is the maximum number of non-zero influences allowed in a morph target manager.\r\n * The final value defined for a morph target manager is: Math.min(morphTargetManager.numTargets, morphTargetsNumMaxInfluences)\r\n * Default: 20\r\n */\r\n morphTargetsNumMaxInfluences?: number;\r\n}\r\n\r\n/**\r\n * A helper class to simplify work with FAST snapshot mode (WebGPU only - can be used in WebGL too, but won't do anything).\r\n */\r\nexport class SnapshotRenderingHelper {\r\n private readonly _engine: AbstractEngine;\r\n private readonly _scene: Scene;\r\n private readonly _options: SnapshotRenderingHelpersOptions;\r\n private readonly _onBeforeRenderObserver: Nullable<Observer<Scene>>;\r\n private _onBeforeRenderObserverUpdateLayer: Nullable<Observer<Scene>>;\r\n private readonly _onResizeObserver: Nullable<Observer<AbstractEngine>>;\r\n private _disableRenderingRefCount = 0;\r\n private _currentPerformancePriorityMode = ScenePerformancePriority.BackwardCompatible;\r\n private _pendingCurrentPerformancePriorityMode?: ScenePerformancePriority;\r\n\r\n /**\r\n * Creates a new snapshot rendering helper\r\n * Note that creating an instance of the helper will set the snapshot rendering mode to SNAPSHOTRENDERING_FAST but will not enable snapshot rendering (engine.snapshotRendering is not updated).\r\n * Note also that fixMeshes() is called as part of the construction\r\n * @param scene The scene to use the helper in\r\n * @param options The options for the helper\r\n */\r\n constructor(scene: Scene, options?: SnapshotRenderingHelpersOptions) {\r\n this._scene = scene;\r\n this._engine = scene.getEngine();\r\n\r\n if (!this._engine.isWebGPU) {\r\n return;\r\n }\r\n\r\n this._options = {\r\n morphTargetsNumMaxInfluences: 20,\r\n ...options,\r\n };\r\n\r\n this._engine.snapshotRenderingMode = Constants.SNAPSHOTRENDERING_FAST;\r\n\r\n this.fixMeshes();\r\n\r\n this._onResizeObserver = this._engine.onResizeObservable.add(() => {\r\n // enableSnapshotRendering() will delay the actual enabling of snapshot rendering by at least a frame, so these two lines are not redundant!\r\n this.disableSnapshotRendering();\r\n this.enableSnapshotRendering();\r\n });\r\n\r\n this._scene.onBeforeRenderObservable.add(() => {\r\n if (!this._fastSnapshotRenderingEnabled) {\r\n return;\r\n }\r\n\r\n // Animate skeletons\r\n scene.skeletons.forEach((skeleton) => skeleton.prepare(true));\r\n\r\n for (const mesh of scene.meshes) {\r\n if (mesh.infiniteDistance) {\r\n mesh.transferToEffect(mesh.computeWorldMatrix(true));\r\n }\r\n\r\n if (mesh.skeleton) {\r\n mesh.transferToEffect(mesh.computeWorldMatrix(true));\r\n }\r\n\r\n if (mesh.morphTargetManager && mesh.subMeshes) {\r\n // Make sure morph target animations work\r\n for (const subMesh of mesh.subMeshes) {\r\n const dw = subMesh._drawWrapper;\r\n const effect = dw.effect;\r\n if (effect) {\r\n const dataBuffer = (dw.drawContext as WebGPUDrawContext).buffers[\"LeftOver\" satisfies (typeof WebGPUShaderProcessor)[\"LeftOvertUBOName\"]];\r\n const ubLeftOver = (effect._pipelineContext as WebGPUPipelineContext)?.uniformBuffer;\r\n if (dataBuffer && ubLeftOver && ubLeftOver.setDataBuffer(dataBuffer)) {\r\n mesh.morphTargetManager._bind(effect);\r\n BindMorphTargetParameters(mesh, effect);\r\n ubLeftOver.update();\r\n }\r\n }\r\n }\r\n }\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Enable snapshot rendering\r\n * Use this method instead of engine.snapshotRendering=true, to make sure everything is ready before enabling snapshot rendering.\r\n * Note that this method is ref-counted and works in pair with disableSnapshotRendering(): you should call enableSnapshotRendering() as many times as you call disableSnapshotRendering().\r\n */\r\n public enableSnapshotRendering() {\r\n if (!this._engine.isWebGPU) {\r\n return;\r\n }\r\n\r\n if (--this._disableRenderingRefCount > 0) {\r\n return;\r\n }\r\n\r\n this._disableRenderingRefCount = 0;\r\n\r\n this._currentPerformancePriorityMode = this._pendingCurrentPerformancePriorityMode ?? this._scene.performancePriority;\r\n this._pendingCurrentPerformancePriorityMode = undefined;\r\n this._scene.performancePriority = ScenePerformancePriority.BackwardCompatible;\r\n\r\n this._scene.executeWhenReady(() => {\r\n if (this._disableRenderingRefCount > 0) {\r\n return;\r\n }\r\n\r\n // Make sure a full frame is rendered before enabling snapshot rendering, so use \"+2\" instead of \"+1\"\r\n this._executeAtFrame(this._engine.frameId + 2, () => {\r\n this._engine.snapshotRendering = true;\r\n });\r\n });\r\n }\r\n\r\n /**\r\n * Disable snapshot rendering\r\n * Note that this method is ref-counted and works in pair with disableSnapshotRendering(): you should call enableSnapshotRendering() as many times as you call disableSnapshotRendering().\r\n */\r\n public disableSnapshotRendering() {\r\n if (!this._engine.isWebGPU) {\r\n return;\r\n }\r\n\r\n if (this._disableRenderingRefCount === 0) {\r\n // Snapshot rendering switches from enabled to disabled\r\n // We reset the performance priority mode to that which it was before enabling snapshot rendering, but first set it to “BackwardCompatible” to allow the system to regenerate resources that may have been optimized for snapshot rendering.\r\n // We'll then restore the original mode at the next frame.\r\n this._scene.performancePriority = ScenePerformancePriority.BackwardCompatible;\r\n if (this._currentPerformancePriorityMode !== ScenePerformancePriority.BackwardCompatible) {\r\n this._pendingCurrentPerformancePriorityMode = this._currentPerformancePriorityMode;\r\n this._scene.executeWhenReady(() => {\r\n this._executeAtFrame(\r\n this._engine.frameId + 2,\r\n () => {\r\n // if this._disableRenderingRefCount === 0, snapshot rendering has been enabled in the meantime, so do nothing\r\n if (this._disableRenderingRefCount > 0 && this._pendingCurrentPerformancePriorityMode !== undefined) {\r\n this._scene.performancePriority = this._pendingCurrentPerformancePriorityMode;\r\n }\r\n this._pendingCurrentPerformancePriorityMode = undefined;\r\n },\r\n true\r\n );\r\n });\r\n }\r\n }\r\n\r\n this._engine.snapshotRendering = false;\r\n this._disableRenderingRefCount++;\r\n }\r\n\r\n /**\r\n * Fix meshes for snapshot rendering.\r\n * This method will make sure that some features are disabled or fixed to make sure snapshot rendering works correctly.\r\n * @param meshes List of meshes to fix. If not provided, all meshes in the scene will be fixed.\r\n */\r\n public fixMeshes(meshes?: AbstractMesh[]) {\r\n if (!this._engine.isWebGPU) {\r\n return;\r\n }\r\n\r\n meshes = meshes || this._scene.meshes;\r\n\r\n for (const mesh of meshes) {\r\n (mesh as Mesh).ignoreCameraMaxZ = false;\r\n if (mesh.morphTargetManager) {\r\n mesh.morphTargetManager.numMaxInfluencers = Math.min(mesh.morphTargetManager.numTargets, this._options.morphTargetsNumMaxInfluences!);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Call this method to update a mesh on the GPU after some properties have changed (position, rotation, scaling, visibility).\r\n * @param mesh The mesh to update. Can be a single mesh or an array of meshes to update.\r\n */\r\n public updateMesh(mesh: AbstractMesh | AbstractMesh[]) {\r\n if (!this._fastSnapshotRenderingEnabled) {\r\n return;\r\n }\r\n\r\n if (Array.isArray(mesh)) {\r\n for (const m of mesh) {\r\n m.transferToEffect(m.computeWorldMatrix(true));\r\n }\r\n return;\r\n }\r\n\r\n mesh.transferToEffect(mesh.computeWorldMatrix(true));\r\n }\r\n\r\n /**\r\n * Update the meshes used in an effect layer to ensure that snapshot rendering works correctly for these meshes in this layer.\r\n * @param effectLayer The effect layer\r\n * @param autoUpdate If true, the helper will automatically update the effect layer meshes with each frame. If false, you'll need to call this method manually when the camera or layer meshes move or rotate.\r\n */\r\n public updateMeshesForEffectLayer(effectLayer: EffectLayer, autoUpdate = true) {\r\n if (!this._engine.isWebGPU) {\r\n return;\r\n }\r\n\r\n const renderPassId = effectLayer.mainTexture.renderPassId;\r\n\r\n if (autoUpdate) {\r\n this._onBeforeRenderObserverUpdateLayer = this._scene.onBeforeRenderObservable.add(() => {\r\n this._updateMeshMatricesForRenderPassId(renderPassId);\r\n });\r\n } else {\r\n this._updateMeshMatricesForRenderPassId(renderPassId);\r\n }\r\n }\r\n\r\n /**\r\n * Dispose the helper\r\n */\r\n public dispose() {\r\n if (!this._engine.isWebGPU) {\r\n return;\r\n }\r\n\r\n this._scene.onBeforeRenderObservable.remove(this._onBeforeRenderObserver);\r\n this._scene.onBeforeRenderObservable.remove(this._onBeforeRenderObserverUpdateLayer);\r\n this._engine.onResizeObservable.remove(this._onResizeObserver);\r\n }\r\n\r\n private get _fastSnapshotRenderingEnabled() {\r\n return this._engine.snapshotRendering && this._engine.snapshotRenderingMode === Constants.SNAPSHOTRENDERING_FAST;\r\n }\r\n\r\n private _updateMeshMatricesForRenderPassId(renderPassId: number) {\r\n if (!this._fastSnapshotRenderingEnabled) {\r\n return;\r\n }\r\n\r\n const sceneTransformationMatrix = this._scene.getTransformMatrix();\r\n\r\n for (let i = 0; i < this._scene.meshes.length; ++i) {\r\n const mesh = this._scene.meshes[i];\r\n if (!mesh.subMeshes) {\r\n continue;\r\n }\r\n\r\n for (let j = 0; j < mesh.subMeshes.length; ++j) {\r\n const dw = mesh.subMeshes[j]._getDrawWrapper(renderPassId);\r\n const effect = dw?.effect;\r\n if (effect) {\r\n const dataBuffer = (dw.drawContext as WebGPUDrawContext).buffers[\"LeftOver\" satisfies (typeof WebGPUShaderProcessor)[\"LeftOvertUBOName\"]];\r\n const ubLeftOver = (effect._pipelineContext as WebGPUPipelineContext)?.uniformBuffer;\r\n if (dataBuffer && ubLeftOver && ubLeftOver.setDataBuffer(dataBuffer)) {\r\n effect.setMatrix(\"viewProjection\", sceneTransformationMatrix);\r\n effect.setMatrix(\"world\", mesh.computeWorldMatrix());\r\n ubLeftOver.update();\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n private _executeAtFrame(frameId: number, func: () => void, executeWhenModeIsDisabled = false) {\r\n const obs = this._engine.onEndFrameObservable.add(() => {\r\n if ((this._disableRenderingRefCount > 0 && !executeWhenModeIsDisabled) || (this._disableRenderingRefCount === 0 && executeWhenModeIsDisabled)) {\r\n this._engine.onEndFrameObservable.remove(obs);\r\n return;\r\n }\r\n if (this._engine.frameId >= frameId) {\r\n this._engine.onEndFrameObservable.remove(obs);\r\n func();\r\n }\r\n });\r\n }\r\n}\r\n"]}
@@ -1,7 +1,11 @@
1
1
  // Do not edit.
2
2
  import { ShaderStore } from "../../Engines/shaderStore.js";
3
3
  const name = "backgroundVertexDeclaration";
4
- const shader = `uniform mat4 view;uniform mat4 viewProjection;uniform float shadowLevel;
4
+ const shader = `uniform mat4 view;uniform mat4 viewProjection;
5
+ #ifdef MULTIVIEW
6
+ uniform mat4 viewProjectionR;
7
+ #endif
8
+ uniform float shadowLevel;
5
9
  #ifdef DIFFUSE
6
10
  uniform mat4 diffuseMatrix;uniform vec2 vDiffuseInfos;
7
11
  #endif
@@ -1 +1 @@
1
- {"version":3,"file":"backgroundVertexDeclaration.js","sourceRoot":"","sources":["../../../../../dev/core/src/Shaders/ShadersInclude/backgroundVertexDeclaration.ts"],"names":[],"mappings":"AAAA,eAAe;AACf,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAExD,MAAM,IAAI,GAAG,6BAA6B,CAAC;AAC3C,MAAM,MAAM,GAAG;;;;;;;;;;CAUd,CAAC;AACF,aAAa;AACb,WAAW,CAAC,oBAAoB,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC;AAChD,gBAAgB;AAChB,MAAM,CAAC,MAAM,2BAA2B,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC","sourcesContent":["// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"backgroundVertexDeclaration\";\nconst shader = `uniform mat4 view;uniform mat4 viewProjection;uniform float shadowLevel;\n#ifdef DIFFUSE\nuniform mat4 diffuseMatrix;uniform vec2 vDiffuseInfos;\n#endif\n#ifdef REFLECTION\nuniform vec2 vReflectionInfos;uniform mat4 reflectionMatrix;uniform vec3 vReflectionMicrosurfaceInfos;uniform float fFovMultiplier;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const backgroundVertexDeclaration = { name, shader };\n"]}
1
+ {"version":3,"file":"backgroundVertexDeclaration.js","sourceRoot":"","sources":["../../../../../dev/core/src/Shaders/ShadersInclude/backgroundVertexDeclaration.ts"],"names":[],"mappings":"AAAA,eAAe;AACf,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAExD,MAAM,IAAI,GAAG,6BAA6B,CAAC;AAC3C,MAAM,MAAM,GAAG;;;;;;;;;;;;;;CAcd,CAAC;AACF,aAAa;AACb,WAAW,CAAC,oBAAoB,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC;AAChD,gBAAgB;AAChB,MAAM,CAAC,MAAM,2BAA2B,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC","sourcesContent":["// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"backgroundVertexDeclaration\";\nconst shader = `uniform mat4 view;uniform mat4 viewProjection;\n#ifdef MULTIVIEW\nuniform mat4 viewProjectionR;\n#endif\nuniform float shadowLevel;\n#ifdef DIFFUSE\nuniform mat4 diffuseMatrix;uniform vec2 vDiffuseInfos;\n#endif\n#ifdef REFLECTION\nuniform vec2 vReflectionInfos;uniform mat4 reflectionMatrix;uniform vec3 vReflectionMicrosurfaceInfos;uniform float fFovMultiplier;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const backgroundVertexDeclaration = { name, shader };\n"]}
@@ -2,7 +2,11 @@
2
2
  import { ShaderStore } from "../../Engines/shaderStore.js";
3
3
  import "./decalVertexDeclaration.js";
4
4
  const name = "defaultVertexDeclaration";
5
- const shader = `uniform mat4 viewProjection;uniform mat4 view;
5
+ const shader = `uniform mat4 viewProjection;
6
+ #ifdef MULTIVIEW
7
+ mat4 viewProjectionR;
8
+ #endif
9
+ uniform mat4 view;
6
10
  #ifdef DIFFUSE
7
11
  uniform mat4 diffuseMatrix;uniform vec2 vDiffuseInfos;
8
12
  #endif
@@ -1 +1 @@
1
- {"version":3,"file":"defaultVertexDeclaration.js","sourceRoot":"","sources":["../../../../../dev/core/src/Shaders/ShadersInclude/defaultVertexDeclaration.ts"],"names":[],"mappings":"AAAA,eAAe;AACf,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,0BAA0B,CAAC;AAElC,MAAM,IAAI,GAAG,0BAA0B,CAAC;AACxC,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiCd,CAAC;AACF,aAAa;AACb,WAAW,CAAC,oBAAoB,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC;AAChD,gBAAgB;AAChB,MAAM,CAAC,MAAM,wBAAwB,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC","sourcesContent":["// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\nimport \"./decalVertexDeclaration\";\n\nconst name = \"defaultVertexDeclaration\";\nconst shader = `uniform mat4 viewProjection;uniform mat4 view;\n#ifdef DIFFUSE\nuniform mat4 diffuseMatrix;uniform vec2 vDiffuseInfos;\n#endif\n#ifdef AMBIENT\nuniform mat4 ambientMatrix;uniform vec2 vAmbientInfos;\n#endif\n#ifdef OPACITY\nuniform mat4 opacityMatrix;uniform vec2 vOpacityInfos;\n#endif\n#ifdef EMISSIVE\nuniform vec2 vEmissiveInfos;uniform mat4 emissiveMatrix;\n#endif\n#ifdef LIGHTMAP\nuniform vec2 vLightmapInfos;uniform mat4 lightmapMatrix;\n#endif\n#if defined(SPECULAR) && defined(SPECULARTERM)\nuniform vec2 vSpecularInfos;uniform mat4 specularMatrix;\n#endif\n#ifdef BUMP\nuniform vec3 vBumpInfos;uniform mat4 bumpMatrix;\n#endif\n#ifdef REFLECTION\nuniform mat4 reflectionMatrix;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n#ifdef DETAIL\nuniform vec4 vDetailInfos;uniform mat4 detailMatrix;\n#endif\n#include<decalVertexDeclaration>\n#define ADDITIONAL_VERTEX_DECLARATION\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const defaultVertexDeclaration = { name, shader };\n"]}
1
+ {"version":3,"file":"defaultVertexDeclaration.js","sourceRoot":"","sources":["../../../../../dev/core/src/Shaders/ShadersInclude/defaultVertexDeclaration.ts"],"names":[],"mappings":"AAAA,eAAe;AACf,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,0BAA0B,CAAC;AAElC,MAAM,IAAI,GAAG,0BAA0B,CAAC;AACxC,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqCd,CAAC;AACF,aAAa;AACb,WAAW,CAAC,oBAAoB,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC;AAChD,gBAAgB;AAChB,MAAM,CAAC,MAAM,wBAAwB,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC","sourcesContent":["// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\nimport \"./decalVertexDeclaration\";\n\nconst name = \"defaultVertexDeclaration\";\nconst shader = `uniform mat4 viewProjection;\n#ifdef MULTIVIEW\nmat4 viewProjectionR;\n#endif \nuniform mat4 view;\n#ifdef DIFFUSE\nuniform mat4 diffuseMatrix;uniform vec2 vDiffuseInfos;\n#endif\n#ifdef AMBIENT\nuniform mat4 ambientMatrix;uniform vec2 vAmbientInfos;\n#endif\n#ifdef OPACITY\nuniform mat4 opacityMatrix;uniform vec2 vOpacityInfos;\n#endif\n#ifdef EMISSIVE\nuniform vec2 vEmissiveInfos;uniform mat4 emissiveMatrix;\n#endif\n#ifdef LIGHTMAP\nuniform vec2 vLightmapInfos;uniform mat4 lightmapMatrix;\n#endif\n#if defined(SPECULAR) && defined(SPECULARTERM)\nuniform vec2 vSpecularInfos;uniform mat4 specularMatrix;\n#endif\n#ifdef BUMP\nuniform vec3 vBumpInfos;uniform mat4 bumpMatrix;\n#endif\n#ifdef REFLECTION\nuniform mat4 reflectionMatrix;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n#ifdef DETAIL\nuniform vec4 vDetailInfos;uniform mat4 detailMatrix;\n#endif\n#include<decalVertexDeclaration>\n#define ADDITIONAL_VERTEX_DECLARATION\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const defaultVertexDeclaration = { name, shader };\n"]}
@@ -3,6 +3,9 @@ import { ShaderStore } from "../../Engines/shaderStore.js";
3
3
  import "./decalVertexDeclaration.js";
4
4
  const name = "pbrVertexDeclaration";
5
5
  const shader = `uniform mat4 view;uniform mat4 viewProjection;
6
+ #ifdef MULTIVIEW
7
+ mat4 viewProjectionR;
8
+ #endif
6
9
  #ifdef ALBEDO
7
10
  uniform mat4 albedoMatrix;uniform vec2 vAlbedoInfos;
8
11
  #endif
@@ -1 +1 @@
1
- {"version":3,"file":"pbrVertexDeclaration.js","sourceRoot":"","sources":["../../../../../dev/core/src/Shaders/ShadersInclude/pbrVertexDeclaration.ts"],"names":[],"mappings":"AAAA,eAAe;AACf,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,0BAA0B,CAAC;AAElC,MAAM,IAAI,GAAG,sBAAsB,CAAC;AACpC,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkHd,CAAC;AACF,aAAa;AACb,WAAW,CAAC,oBAAoB,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC;AAChD,gBAAgB;AAChB,MAAM,CAAC,MAAM,oBAAoB,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC","sourcesContent":["// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\nimport \"./decalVertexDeclaration\";\n\nconst name = \"pbrVertexDeclaration\";\nconst shader = `uniform mat4 view;uniform mat4 viewProjection;\n#ifdef ALBEDO\nuniform mat4 albedoMatrix;uniform vec2 vAlbedoInfos;\n#endif\n#ifdef AMBIENT\nuniform mat4 ambientMatrix;uniform vec4 vAmbientInfos;\n#endif\n#ifdef OPACITY\nuniform mat4 opacityMatrix;uniform vec2 vOpacityInfos;\n#endif\n#ifdef EMISSIVE\nuniform vec2 vEmissiveInfos;uniform mat4 emissiveMatrix;\n#endif\n#ifdef LIGHTMAP\nuniform vec2 vLightmapInfos;uniform mat4 lightmapMatrix;\n#endif\n#ifdef REFLECTIVITY \nuniform vec3 vReflectivityInfos;uniform mat4 reflectivityMatrix;\n#endif\n#ifdef METALLIC_REFLECTANCE\nuniform vec2 vMetallicReflectanceInfos;uniform mat4 metallicReflectanceMatrix;\n#endif\n#ifdef REFLECTANCE\nuniform vec2 vReflectanceInfos;uniform mat4 reflectanceMatrix;\n#endif\n#ifdef MICROSURFACEMAP\nuniform vec2 vMicroSurfaceSamplerInfos;uniform mat4 microSurfaceSamplerMatrix;\n#endif\n#ifdef BUMP\nuniform vec3 vBumpInfos;uniform mat4 bumpMatrix;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n#ifdef REFLECTION\nuniform vec2 vReflectionInfos;uniform mat4 reflectionMatrix;\n#endif\n#ifdef CLEARCOAT\n#if defined(CLEARCOAT_TEXTURE) || defined(CLEARCOAT_TEXTURE_ROUGHNESS)\nuniform vec4 vClearCoatInfos;\n#endif\n#ifdef CLEARCOAT_TEXTURE\nuniform mat4 clearCoatMatrix;\n#endif\n#ifdef CLEARCOAT_TEXTURE_ROUGHNESS\nuniform mat4 clearCoatRoughnessMatrix;\n#endif\n#ifdef CLEARCOAT_BUMP\nuniform vec2 vClearCoatBumpInfos;uniform mat4 clearCoatBumpMatrix;\n#endif\n#ifdef CLEARCOAT_TINT_TEXTURE\nuniform vec2 vClearCoatTintInfos;uniform mat4 clearCoatTintMatrix;\n#endif\n#endif\n#ifdef IRIDESCENCE\n#if defined(IRIDESCENCE_TEXTURE) || defined(IRIDESCENCE_THICKNESS_TEXTURE)\nuniform vec4 vIridescenceInfos;\n#endif\n#ifdef IRIDESCENCE_TEXTURE\nuniform mat4 iridescenceMatrix;\n#endif\n#ifdef IRIDESCENCE_THICKNESS_TEXTURE\nuniform mat4 iridescenceThicknessMatrix;\n#endif\n#endif\n#ifdef ANISOTROPIC\n#ifdef ANISOTROPIC_TEXTURE\nuniform vec2 vAnisotropyInfos;uniform mat4 anisotropyMatrix;\n#endif\n#endif\n#ifdef SHEEN\n#if defined(SHEEN_TEXTURE) || defined(SHEEN_TEXTURE_ROUGHNESS)\nuniform vec4 vSheenInfos;\n#endif\n#ifdef SHEEN_TEXTURE\nuniform mat4 sheenMatrix;\n#endif\n#ifdef SHEEN_TEXTURE_ROUGHNESS\nuniform mat4 sheenRoughnessMatrix;\n#endif\n#endif\n#ifdef SUBSURFACE\n#ifdef SS_REFRACTION\nuniform vec4 vRefractionInfos;uniform mat4 refractionMatrix;\n#endif\n#ifdef SS_THICKNESSANDMASK_TEXTURE\nuniform vec2 vThicknessInfos;uniform mat4 thicknessMatrix;\n#endif\n#ifdef SS_REFRACTIONINTENSITY_TEXTURE\nuniform vec2 vRefractionIntensityInfos;uniform mat4 refractionIntensityMatrix;\n#endif\n#ifdef SS_TRANSLUCENCYINTENSITY_TEXTURE\nuniform vec2 vTranslucencyIntensityInfos;uniform mat4 translucencyIntensityMatrix;\n#endif\n#ifdef SS_TRANSLUCENCYCOLOR_TEXTURE\nuniform vec2 vTranslucencyColorInfos;uniform mat4 translucencyColorMatrix;\n#endif\n#endif\n#ifdef NORMAL\n#if defined(USESPHERICALFROMREFLECTIONMAP) && defined(USESPHERICALINVERTEX)\n#ifdef USESPHERICALFROMREFLECTIONMAP\n#ifdef SPHERICAL_HARMONICS\nuniform vec3 vSphericalL00;uniform vec3 vSphericalL1_1;uniform vec3 vSphericalL10;uniform vec3 vSphericalL11;uniform vec3 vSphericalL2_2;uniform vec3 vSphericalL2_1;uniform vec3 vSphericalL20;uniform vec3 vSphericalL21;uniform vec3 vSphericalL22;\n#else\nuniform vec3 vSphericalX;uniform vec3 vSphericalY;uniform vec3 vSphericalZ;uniform vec3 vSphericalXX_ZZ;uniform vec3 vSphericalYY_ZZ;uniform vec3 vSphericalZZ;uniform vec3 vSphericalXY;uniform vec3 vSphericalYZ;uniform vec3 vSphericalZX;\n#endif\n#endif\n#endif\n#endif\n#ifdef DETAIL\nuniform vec4 vDetailInfos;uniform mat4 detailMatrix;\n#endif\n#include<decalVertexDeclaration>\n#define ADDITIONAL_VERTEX_DECLARATION\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const pbrVertexDeclaration = { name, shader };\n"]}
1
+ {"version":3,"file":"pbrVertexDeclaration.js","sourceRoot":"","sources":["../../../../../dev/core/src/Shaders/ShadersInclude/pbrVertexDeclaration.ts"],"names":[],"mappings":"AAAA,eAAe;AACf,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,0BAA0B,CAAC;AAElC,MAAM,IAAI,GAAG,sBAAsB,CAAC;AACpC,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqHd,CAAC;AACF,aAAa;AACb,WAAW,CAAC,oBAAoB,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC;AAChD,gBAAgB;AAChB,MAAM,CAAC,MAAM,oBAAoB,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC","sourcesContent":["// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\nimport \"./decalVertexDeclaration\";\n\nconst name = \"pbrVertexDeclaration\";\nconst shader = `uniform mat4 view;uniform mat4 viewProjection;\n#ifdef MULTIVIEW\nmat4 viewProjectionR;\n#endif \n#ifdef ALBEDO\nuniform mat4 albedoMatrix;uniform vec2 vAlbedoInfos;\n#endif\n#ifdef AMBIENT\nuniform mat4 ambientMatrix;uniform vec4 vAmbientInfos;\n#endif\n#ifdef OPACITY\nuniform mat4 opacityMatrix;uniform vec2 vOpacityInfos;\n#endif\n#ifdef EMISSIVE\nuniform vec2 vEmissiveInfos;uniform mat4 emissiveMatrix;\n#endif\n#ifdef LIGHTMAP\nuniform vec2 vLightmapInfos;uniform mat4 lightmapMatrix;\n#endif\n#ifdef REFLECTIVITY \nuniform vec3 vReflectivityInfos;uniform mat4 reflectivityMatrix;\n#endif\n#ifdef METALLIC_REFLECTANCE\nuniform vec2 vMetallicReflectanceInfos;uniform mat4 metallicReflectanceMatrix;\n#endif\n#ifdef REFLECTANCE\nuniform vec2 vReflectanceInfos;uniform mat4 reflectanceMatrix;\n#endif\n#ifdef MICROSURFACEMAP\nuniform vec2 vMicroSurfaceSamplerInfos;uniform mat4 microSurfaceSamplerMatrix;\n#endif\n#ifdef BUMP\nuniform vec3 vBumpInfos;uniform mat4 bumpMatrix;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n#ifdef REFLECTION\nuniform vec2 vReflectionInfos;uniform mat4 reflectionMatrix;\n#endif\n#ifdef CLEARCOAT\n#if defined(CLEARCOAT_TEXTURE) || defined(CLEARCOAT_TEXTURE_ROUGHNESS)\nuniform vec4 vClearCoatInfos;\n#endif\n#ifdef CLEARCOAT_TEXTURE\nuniform mat4 clearCoatMatrix;\n#endif\n#ifdef CLEARCOAT_TEXTURE_ROUGHNESS\nuniform mat4 clearCoatRoughnessMatrix;\n#endif\n#ifdef CLEARCOAT_BUMP\nuniform vec2 vClearCoatBumpInfos;uniform mat4 clearCoatBumpMatrix;\n#endif\n#ifdef CLEARCOAT_TINT_TEXTURE\nuniform vec2 vClearCoatTintInfos;uniform mat4 clearCoatTintMatrix;\n#endif\n#endif\n#ifdef IRIDESCENCE\n#if defined(IRIDESCENCE_TEXTURE) || defined(IRIDESCENCE_THICKNESS_TEXTURE)\nuniform vec4 vIridescenceInfos;\n#endif\n#ifdef IRIDESCENCE_TEXTURE\nuniform mat4 iridescenceMatrix;\n#endif\n#ifdef IRIDESCENCE_THICKNESS_TEXTURE\nuniform mat4 iridescenceThicknessMatrix;\n#endif\n#endif\n#ifdef ANISOTROPIC\n#ifdef ANISOTROPIC_TEXTURE\nuniform vec2 vAnisotropyInfos;uniform mat4 anisotropyMatrix;\n#endif\n#endif\n#ifdef SHEEN\n#if defined(SHEEN_TEXTURE) || defined(SHEEN_TEXTURE_ROUGHNESS)\nuniform vec4 vSheenInfos;\n#endif\n#ifdef SHEEN_TEXTURE\nuniform mat4 sheenMatrix;\n#endif\n#ifdef SHEEN_TEXTURE_ROUGHNESS\nuniform mat4 sheenRoughnessMatrix;\n#endif\n#endif\n#ifdef SUBSURFACE\n#ifdef SS_REFRACTION\nuniform vec4 vRefractionInfos;uniform mat4 refractionMatrix;\n#endif\n#ifdef SS_THICKNESSANDMASK_TEXTURE\nuniform vec2 vThicknessInfos;uniform mat4 thicknessMatrix;\n#endif\n#ifdef SS_REFRACTIONINTENSITY_TEXTURE\nuniform vec2 vRefractionIntensityInfos;uniform mat4 refractionIntensityMatrix;\n#endif\n#ifdef SS_TRANSLUCENCYINTENSITY_TEXTURE\nuniform vec2 vTranslucencyIntensityInfos;uniform mat4 translucencyIntensityMatrix;\n#endif\n#ifdef SS_TRANSLUCENCYCOLOR_TEXTURE\nuniform vec2 vTranslucencyColorInfos;uniform mat4 translucencyColorMatrix;\n#endif\n#endif\n#ifdef NORMAL\n#if defined(USESPHERICALFROMREFLECTIONMAP) && defined(USESPHERICALINVERTEX)\n#ifdef USESPHERICALFROMREFLECTIONMAP\n#ifdef SPHERICAL_HARMONICS\nuniform vec3 vSphericalL00;uniform vec3 vSphericalL1_1;uniform vec3 vSphericalL10;uniform vec3 vSphericalL11;uniform vec3 vSphericalL2_2;uniform vec3 vSphericalL2_1;uniform vec3 vSphericalL20;uniform vec3 vSphericalL21;uniform vec3 vSphericalL22;\n#else\nuniform vec3 vSphericalX;uniform vec3 vSphericalY;uniform vec3 vSphericalZ;uniform vec3 vSphericalXX_ZZ;uniform vec3 vSphericalYY_ZZ;uniform vec3 vSphericalZZ;uniform vec3 vSphericalXY;uniform vec3 vSphericalYZ;uniform vec3 vSphericalZX;\n#endif\n#endif\n#endif\n#endif\n#ifdef DETAIL\nuniform vec4 vDetailInfos;uniform mat4 detailMatrix;\n#endif\n#include<decalVertexDeclaration>\n#define ADDITIONAL_VERTEX_DECLARATION\n`;\n// Sideeffect\nShaderStore.IncludesShadersStore[name] = shader;\n/** @internal */\nexport const pbrVertexDeclaration = { name, shader };\n"]}
@@ -16,24 +16,24 @@ const shader = `#ifdef LOGARITHMICDEPTH
16
16
  precision highp float;varying vec3 vPosition;varying vec2 vUV;varying vec2 tUV;uniform float time;uniform float spriteCount;uniform sampler2D spriteSheet;uniform vec2 spriteMapSize;uniform vec2 outputSize;uniform vec2 stageSize;uniform sampler2D frameMap;uniform sampler2D tileMaps[LAYERS];uniform sampler2D animationMap;uniform vec3 colorMul;
17
17
  #include<fogFragmentDeclaration>
18
18
  #include<logDepthDeclaration>
19
- float mt;const float fdStep=1./4.;const float aFrameSteps=MAX_ANIMATION_FRAMES==0. ? 0. : 1./MAX_ANIMATION_FRAMES;mat4 getFrameData(float frameID){float fX=frameID/spriteCount;return mat4(
20
- texture2D(frameMap,vec2(fX,0.),0.),
21
- texture2D(frameMap,vec2(fX,fdStep*1.),0.),
22
- texture2D(frameMap,vec2(fX,fdStep*2.),0.),
23
- vec4(0.)
19
+ float mt;const float fdStep=1.0*0.25;const float aFrameSteps=MAX_ANIMATION_FRAMES==0.0 ? 0.0 : 1.0/MAX_ANIMATION_FRAMES;mat4 getFrameData(float frameID) {float fX=frameID/spriteCount;return mat4(
20
+ TEXTUREFUNC(frameMap,vec2(fX,0.0),0.0),
21
+ TEXTUREFUNC(frameMap,vec2(fX,fdStep*1.0),0.0),
22
+ TEXTUREFUNC(frameMap,vec2(fX,fdStep*2.0),0.0),
23
+ vec4(0.0)
24
24
  );}
25
- void main(){vec4 color=vec4(0.);vec2 tileUV=fract(tUV);vec2 tileID=floor(tUV);vec2 sheetUnits=1./spriteMapSize;float spriteUnits=1./spriteCount;vec2 stageUnits=1./stageSize;for(int i=0; i<LAYERS; i++) {float frameID;
25
+ void main() {vec4 color=vec4(0.0);vec2 tileUV=fract(tUV);vec2 tileID=floor(tUV);vec2 sheetUnits=1.0/spriteMapSize;float spriteUnits=1.0/spriteCount;vec2 stageUnits=1.0/stageSize;for(int i=0; i<LAYERS; i++) {float frameID;
26
26
  #define LAYER_ID_SWITCH
27
- vec4 animationData=TEXTUREFUNC(animationMap,vec2((frameID+0.5)/spriteCount,0.),0.);if(animationData.y>0.) {mt=mod(time*animationData.z,1.0);for(float f=0.; f<MAX_ANIMATION_FRAMES; f++){if(animationData.y>mt){frameID=animationData.x;break;}
28
- animationData=TEXTUREFUNC(animationMap,vec2((frameID+0.5)/spriteCount,aFrameSteps*f),0.);}}
27
+ vec4 animationData=TEXTUREFUNC(animationMap,vec2((frameID+0.5)/spriteCount,0.0),0.0);if(animationData.y>0.0) {mt=mod(time*animationData.z,1.0);for(float f=0.0; f<MAX_ANIMATION_FRAMES; f++) {if(animationData.y>mt) {frameID=animationData.x;break;}
28
+ animationData=TEXTUREFUNC(animationMap,vec2((frameID+0.5)/spriteCount,aFrameSteps*f),0.0);}}
29
29
  mat4 frameData=getFrameData(frameID+0.5);vec2 frameSize=(frameData[0].zw)/spriteMapSize;vec2 offset=frameData[0].xy*sheetUnits;vec2 ratio=frameData[2].xy/frameData[0].zw;
30
30
  #ifdef FR_CW
31
- if (frameData[2].z==1.){tileUV.xy=tileUV.yx;} else {tileUV.xy=fract(tUV).xy;}
31
+ if (frameData[2].z==1.0) {tileUV.xy=tileUV.yx;} else {tileUV.xy=fract(tUV).xy;}
32
32
  #ifdef FLIPU
33
33
  tileUV.y=1.0-tileUV.y;
34
34
  #endif
35
35
  #else
36
- if (frameData[2].z==1.){
36
+ if (frameData[2].z==1.0) {
37
37
  #ifdef FLIPU
38
38
  tileUV.y=1.0-tileUV.y;
39
39
  #endif
@@ -43,12 +43,11 @@ tileUV.y=1.0-tileUV.y;
43
43
  #endif
44
44
  }
45
45
  #endif
46
- vec4 nc=texture2D(spriteSheet,tileUV*frameSize+offset);if (i==0){color=nc;} else {float alpha=min(color.a+nc.a,1.0);vec3 mixed=mix(color.xyz,nc.xyz,nc.a);color=vec4(mixed,alpha);}}
46
+ vec4 nc=TEXTUREFUNC(spriteSheet,tileUV*frameSize+offset,0.0);if (i==0) {color=nc;} else {float alpha=min(color.a+nc.a,1.0);vec3 mixed=mix(color.xyz,nc.xyz,nc.a);color=vec4(mixed,alpha);}}
47
47
  color.xyz*=colorMul;
48
48
  #include<logDepthFragment>
49
49
  #include<fogFragment>
50
- gl_FragColor=color;}
51
- `;
50
+ gl_FragColor=color;}`;
52
51
  // Sideeffect
53
52
  ShaderStore.ShadersStore[name] = shader;
54
53
  /** @internal */
@@ -1 +1 @@
1
- {"version":3,"file":"spriteMap.fragment.js","sourceRoot":"","sources":["../../../../dev/core/src/Shaders/spriteMap.fragment.ts"],"names":[],"mappings":"AAAA,eAAe;AACf,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,yCAAyC,CAAC;AACjD,OAAO,sCAAsC,CAAC;AAC9C,OAAO,mCAAmC,CAAC;AAC3C,OAAO,8BAA8B,CAAC;AAEtC,MAAM,IAAI,GAAG,sBAAsB,CAAC;AACpC,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2Cd,CAAC;AACF,aAAa;AACb,WAAW,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC;AACxC,gBAAgB;AAChB,MAAM,CAAC,MAAM,oBAAoB,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC","sourcesContent":["// Do not edit.\nimport { ShaderStore } from \"../Engines/shaderStore\";\nimport \"./ShadersInclude/fogFragmentDeclaration\";\nimport \"./ShadersInclude/logDepthDeclaration\";\nimport \"./ShadersInclude/logDepthFragment\";\nimport \"./ShadersInclude/fogFragment\";\n\nconst name = \"spriteMapPixelShader\";\nconst shader = `#ifdef LOGARITHMICDEPTH\n#extension GL_EXT_frag_depth : enable\n#endif\n#if defined(WEBGL2) || defined(WEBGPU) || defined(NATIVE)\n#define TEXTUREFUNC(s,c,l) texture2DLodEXT(s,c,l)\n#else\n#define TEXTUREFUNC(s,c,b) texture2D(s,c,b)\n#endif\nprecision highp float;varying vec3 vPosition;varying vec2 vUV;varying vec2 tUV;uniform float time;uniform float spriteCount;uniform sampler2D spriteSheet;uniform vec2 spriteMapSize;uniform vec2 outputSize;uniform vec2 stageSize;uniform sampler2D frameMap;uniform sampler2D tileMaps[LAYERS];uniform sampler2D animationMap;uniform vec3 colorMul;\n#include<fogFragmentDeclaration>\n#include<logDepthDeclaration>\nfloat mt;const float fdStep=1./4.;const float aFrameSteps=MAX_ANIMATION_FRAMES==0. ? 0. : 1./MAX_ANIMATION_FRAMES;mat4 getFrameData(float frameID){float fX=frameID/spriteCount;return mat4(\ntexture2D(frameMap,vec2(fX,0.),0.),\ntexture2D(frameMap,vec2(fX,fdStep*1.),0.),\ntexture2D(frameMap,vec2(fX,fdStep*2.),0.),\nvec4(0.)\n);}\nvoid main(){vec4 color=vec4(0.);vec2 tileUV=fract(tUV);vec2 tileID=floor(tUV);vec2 sheetUnits=1./spriteMapSize;float spriteUnits=1./spriteCount;vec2 stageUnits=1./stageSize;for(int i=0; i<LAYERS; i++) {float frameID;\n#define LAYER_ID_SWITCH\nvec4 animationData=TEXTUREFUNC(animationMap,vec2((frameID+0.5)/spriteCount,0.),0.);if(animationData.y>0.) {mt=mod(time*animationData.z,1.0);for(float f=0.; f<MAX_ANIMATION_FRAMES; f++){if(animationData.y>mt){frameID=animationData.x;break;}\nanimationData=TEXTUREFUNC(animationMap,vec2((frameID+0.5)/spriteCount,aFrameSteps*f),0.);}}\nmat4 frameData=getFrameData(frameID+0.5);vec2 frameSize=(frameData[0].zw)/spriteMapSize;vec2 offset=frameData[0].xy*sheetUnits;vec2 ratio=frameData[2].xy/frameData[0].zw;\n#ifdef FR_CW\nif (frameData[2].z==1.){tileUV.xy=tileUV.yx;} else {tileUV.xy=fract(tUV).xy;}\n#ifdef FLIPU\ntileUV.y=1.0-tileUV.y;\n#endif\n#else\nif (frameData[2].z==1.){\n#ifdef FLIPU\ntileUV.y=1.0-tileUV.y;\n#endif\ntileUV.xy=tileUV.yx;} else {tileUV.xy=fract(tUV).xy;\n#ifdef FLIPU\ntileUV.y=1.0-tileUV.y;\n#endif\n}\n#endif\nvec4 nc=texture2D(spriteSheet,tileUV*frameSize+offset);if (i==0){color=nc;} else {float alpha=min(color.a+nc.a,1.0);vec3 mixed=mix(color.xyz,nc.xyz,nc.a);color=vec4(mixed,alpha);}}\ncolor.xyz*=colorMul;\n#include<logDepthFragment>\n#include<fogFragment>\ngl_FragColor=color;}\n`;\n// Sideeffect\nShaderStore.ShadersStore[name] = shader;\n/** @internal */\nexport const spriteMapPixelShader = { name, shader };\n"]}
1
+ {"version":3,"file":"spriteMap.fragment.js","sourceRoot":"","sources":["../../../../dev/core/src/Shaders/spriteMap.fragment.ts"],"names":[],"mappings":"AAAA,eAAe;AACf,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,yCAAyC,CAAC;AACjD,OAAO,sCAAsC,CAAC;AAC9C,OAAO,mCAAmC,CAAC;AAC3C,OAAO,8BAA8B,CAAC;AAEtC,MAAM,IAAI,GAAG,sBAAsB,CAAC;AACpC,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBA0CM,CAAC;AACtB,aAAa;AACb,WAAW,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC;AACxC,gBAAgB;AAChB,MAAM,CAAC,MAAM,oBAAoB,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC","sourcesContent":["// Do not edit.\nimport { ShaderStore } from \"../Engines/shaderStore\";\nimport \"./ShadersInclude/fogFragmentDeclaration\";\nimport \"./ShadersInclude/logDepthDeclaration\";\nimport \"./ShadersInclude/logDepthFragment\";\nimport \"./ShadersInclude/fogFragment\";\n\nconst name = \"spriteMapPixelShader\";\nconst shader = `#ifdef LOGARITHMICDEPTH\n#extension GL_EXT_frag_depth : enable\n#endif\n#if defined(WEBGL2) || defined(WEBGPU) || defined(NATIVE)\n#define TEXTUREFUNC(s,c,l) texture2DLodEXT(s,c,l)\n#else\n#define TEXTUREFUNC(s,c,b) texture2D(s,c,b)\n#endif\nprecision highp float;varying vec3 vPosition;varying vec2 vUV;varying vec2 tUV;uniform float time;uniform float spriteCount;uniform sampler2D spriteSheet;uniform vec2 spriteMapSize;uniform vec2 outputSize;uniform vec2 stageSize;uniform sampler2D frameMap;uniform sampler2D tileMaps[LAYERS];uniform sampler2D animationMap;uniform vec3 colorMul;\n#include<fogFragmentDeclaration>\n#include<logDepthDeclaration>\nfloat mt;const float fdStep=1.0*0.25;const float aFrameSteps=MAX_ANIMATION_FRAMES==0.0 ? 0.0 : 1.0/MAX_ANIMATION_FRAMES;mat4 getFrameData(float frameID) {float fX=frameID/spriteCount;return mat4(\nTEXTUREFUNC(frameMap,vec2(fX,0.0),0.0),\nTEXTUREFUNC(frameMap,vec2(fX,fdStep*1.0),0.0),\nTEXTUREFUNC(frameMap,vec2(fX,fdStep*2.0),0.0),\nvec4(0.0)\n);}\nvoid main() {vec4 color=vec4(0.0);vec2 tileUV=fract(tUV);vec2 tileID=floor(tUV);vec2 sheetUnits=1.0/spriteMapSize;float spriteUnits=1.0/spriteCount;vec2 stageUnits=1.0/stageSize;for(int i=0; i<LAYERS; i++) {float frameID;\n#define LAYER_ID_SWITCH\nvec4 animationData=TEXTUREFUNC(animationMap,vec2((frameID+0.5)/spriteCount,0.0),0.0);if(animationData.y>0.0) {mt=mod(time*animationData.z,1.0);for(float f=0.0; f<MAX_ANIMATION_FRAMES; f++) {if(animationData.y>mt) {frameID=animationData.x;break;}\nanimationData=TEXTUREFUNC(animationMap,vec2((frameID+0.5)/spriteCount,aFrameSteps*f),0.0);}}\nmat4 frameData=getFrameData(frameID+0.5);vec2 frameSize=(frameData[0].zw)/spriteMapSize;vec2 offset=frameData[0].xy*sheetUnits;vec2 ratio=frameData[2].xy/frameData[0].zw;\n#ifdef FR_CW\nif (frameData[2].z==1.0) {tileUV.xy=tileUV.yx;} else {tileUV.xy=fract(tUV).xy;}\n#ifdef FLIPU\ntileUV.y=1.0-tileUV.y;\n#endif\n#else\nif (frameData[2].z==1.0) {\n#ifdef FLIPU\ntileUV.y=1.0-tileUV.y;\n#endif\ntileUV.xy=tileUV.yx;} else {tileUV.xy=fract(tUV).xy;\n#ifdef FLIPU\ntileUV.y=1.0-tileUV.y;\n#endif\n}\n#endif\nvec4 nc=TEXTUREFUNC(spriteSheet,tileUV*frameSize+offset,0.0);if (i==0) {color=nc;} else {float alpha=min(color.a+nc.a,1.0);vec3 mixed=mix(color.xyz,nc.xyz,nc.a);color=vec4(mixed,alpha);}}\ncolor.xyz*=colorMul;\n#include<logDepthFragment>\n#include<fogFragment>\ngl_FragColor=color;}`;\n// Sideeffect\nShaderStore.ShadersStore[name] = shader;\n/** @internal */\nexport const spriteMapPixelShader = { name, shader };\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babylonjs/core",
3
- "version": "7.31.0",
3
+ "version": "7.31.1",
4
4
  "main": "index.js",
5
5
  "module": "index.js",
6
6
  "types": "index.d.ts",