Przeglądaj źródła

Put back the cache mechanism in Scene.setTransformMatrix for WebGPU

Popov72 4 lat temu
rodzic
commit
954f011f2e

+ 2 - 1
src/Engines/Extensions/engine.multiview.ts

@@ -127,8 +127,8 @@ Scene.prototype._createMultiviewUbo = function() {
     this._multiviewSceneUbo.addUniform("viewProjection", 16);
     this._multiviewSceneUbo.addUniform("viewProjectionR", 16);
     this._multiviewSceneUbo.addUniform("view", 16);
+    this._multiviewSceneUbo.addUniform("projection", 16);
     this._multiviewSceneUbo.addUniform("viewPosition", 4);
-
 };
 Scene.prototype._updateMultiviewUbo = function(viewR?: Matrix, projectionR?: Matrix) {
     if (viewR && projectionR) {
@@ -144,6 +144,7 @@ Scene.prototype._updateMultiviewUbo = function(viewR?: Matrix, projectionR?: Mat
         this._multiviewSceneUbo.updateMatrix("viewProjection", this.getTransformMatrix());
         this._multiviewSceneUbo.updateMatrix("viewProjectionR", this._transformMatrixR);
         this._multiviewSceneUbo.updateMatrix("view", this._viewMatrix);
+        this._multiviewSceneUbo.updateMatrix("projection", this._projectionMatrix);
     }
 };
 Scene.prototype._renderMultiviewToSingleView = function(camera: Camera) {

+ 7 - 0
src/Materials/uniformBuffer.ts

@@ -678,6 +678,13 @@ export class UniformBuffer {
         return true;
     }
 
+    /** @hidden */
+    public _getMatrixUpdateFlagFromCache(matrixName: string): number | undefined {
+        this._checkBuffers();
+
+        return this._valueCache[matrixName];
+    }
+
     // Update methods
 
     private _updateMatrix3x3ForUniform(name: string, matrix: Float32Array): void {

+ 11 - 2
src/scene.ts

@@ -1175,7 +1175,7 @@ export class Scene extends AbstractScene implements IAnimatable, IClipPlanesHold
 
     /** @hidden */
     public _viewMatrix: Matrix;
-    private _projectionMatrix: Matrix;
+    public _projectionMatrix: Matrix;
     /** @hidden */
     public _forcedViewPosition: Nullable<Vector3>;
 
@@ -1659,6 +1659,7 @@ export class Scene extends AbstractScene implements IAnimatable, IClipPlanesHold
         this._sceneUbo = new UniformBuffer(this._engine, undefined, !ThinEngine.Features.trackUbosInFrame, "scene");
         this._sceneUbo.addUniform("viewProjection", 16);
         this._sceneUbo.addUniform("view", 16);
+        this._sceneUbo.addUniform("projection", 16);
         this._sceneUbo.addUniform("viewPosition", 4);
     }
 
@@ -2003,7 +2004,14 @@ export class Scene extends AbstractScene implements IAnimatable, IClipPlanesHold
      * @param projectionR defines the right Projection matrix to use (if provided)
      */
     public setTransformMatrix(viewL: Matrix, projectionL: Matrix, viewR?: Matrix, projectionR?: Matrix): void {
-        if (!ThinEngine.Features.trackUbosInFrame && this._viewUpdateFlag === viewL.updateFlag && this._projectionUpdateFlag === projectionL.updateFlag) {
+        if (ThinEngine.Features.trackUbosInFrame) {
+            const viewLUpdateFlag = this._sceneUbo._getMatrixUpdateFlagFromCache("view");
+            const projectionLUpdateFlag = this._sceneUbo._getMatrixUpdateFlagFromCache("projection");
+
+            if (viewLUpdateFlag === viewL.updateFlag && projectionLUpdateFlag === projectionL.updateFlag) {
+                return;
+            }
+        } else if (this._viewUpdateFlag === viewL.updateFlag && this._projectionUpdateFlag === projectionL.updateFlag) {
             return;
         }
 
@@ -2026,6 +2034,7 @@ export class Scene extends AbstractScene implements IAnimatable, IClipPlanesHold
         } else if (this._sceneUbo.useUbo) {
             this._sceneUbo.updateMatrix("viewProjection", this._transformMatrix);
             this._sceneUbo.updateMatrix("view", this._viewMatrix);
+            this._sceneUbo.updateMatrix("projection", this._projectionMatrix);
         }
     }