Selaa lähdekoodia

remove alternate camera

Trevor Baron 6 vuotta sitten
vanhempi
commit
c00aedefe5
4 muutettua tiedostoa jossa 25 lisäystä ja 111 poistoa
  1. 0 5
      src/Cameras/RigModes/webVRRigMode.ts
  2. 1 9
      src/Cameras/camera.ts
  3. 1 18
      src/Meshes/mesh.ts
  4. 23 79
      src/scene.ts

+ 0 - 5
src/Cameras/RigModes/webVRRigMode.ts

@@ -29,10 +29,5 @@ Camera._setWebVRRigMode = function(camera: Camera, rigParams: any) {
         camera._rigCameras[1].getProjectionMatrix = camera._getWebVRProjectionMatrix;
         camera._rigCameras[1].parent = camera;
         camera._rigCameras[1]._getViewMatrix = camera._getWebVRViewMatrix;
-
-        if (Camera.UseAlternateWebVRRendering) {
-            camera._rigCameras[1]._skipRendering = true;
-            camera._rigCameras[0]._alternateCamera = camera._rigCameras[1];
-        }
     }
 };

+ 1 - 9
src/Cameras/camera.ts

@@ -94,12 +94,6 @@ export class Camera extends Node {
     public static ForceAttachControlToAlwaysPreventDefault = false;
 
     /**
-     * @hidden
-     * Might be removed once multiview will be a thing
-     */
-    public static UseAlternateWebVRRendering = false;
-
-    /**
      * Define the input manager associated with the camera.
      */
     public inputs: CameraInputsManager<Camera>;
@@ -257,7 +251,7 @@ export class Camera extends Node {
      * @param width height to set on the multiview texture
      * @param height width to set on the multiview texture
      */
-    public _resizeorCreateMultiviewTexture(width: number, height: number) {
+    public _resizeOrCreateMultiviewTexture(width: number, height: number) {
         if (!this._multiviewTexture) {
             this._multiviewTexture = new MultiviewRenderTarget(this.getScene(), {width: width, height: height});
         }else if (this._multiviewTexture.getRenderWidth() != width || this._multiviewTexture.getRenderHeight() != height) {
@@ -293,8 +287,6 @@ export class Camera extends Node {
     protected _webvrViewMatrix = Matrix.Identity();
     /** @hidden */
     public _skipRendering = false;
-    /** @hidden */
-    public _alternateCamera: Camera;
 
     /** @hidden */
     public _projectionMatrix = new Matrix();

+ 1 - 18
src/Meshes/mesh.ts

@@ -1296,7 +1296,7 @@ export class Mesh extends AbstractMesh implements IGetSetVerticesData {
     }
 
     /** @hidden */
-    public _draw(subMesh: SubMesh, fillMode: number, instancesCount?: number, alternate = false): Mesh {
+    public _draw(subMesh: SubMesh, fillMode: number, instancesCount?: number): Mesh {
         if (!this._geometry || !this._geometry.getVertexBuffers() || (!this._unIndexed && !this._geometry.getIndexBuffer())) {
             return this;
         }
@@ -1318,23 +1318,6 @@ export class Mesh extends AbstractMesh implements IGetSetVerticesData {
             engine.drawElementsType(fillMode, subMesh.indexStart, subMesh.indexCount, instancesCount);
         }
 
-        if (scene._isAlternateRenderingEnabled && !alternate) {
-            let effect = subMesh.effect || this._effectiveMaterial.getEffect();
-            if (!effect || !scene.activeCamera) {
-                return this;
-            }
-            scene._switchToAlternateCameraConfiguration(true);
-            this._effectiveMaterial.bindView(effect);
-            this._effectiveMaterial.bindViewProjection(effect);
-
-            engine.setViewport(scene.activeCamera._alternateCamera.viewport);
-            this._draw(subMesh, fillMode, instancesCount, true);
-            engine.setViewport(scene.activeCamera.viewport);
-
-            scene._switchToAlternateCameraConfiguration(false);
-            this._effectiveMaterial.bindView(effect);
-            this._effectiveMaterial.bindViewProjection(effect);
-        }
         return this;
     }
 

+ 23 - 79
src/scene.ts

@@ -1078,8 +1078,6 @@ export class Scene extends AbstractScene implements IAnimatable {
 
     private _viewUpdateFlag = -1;
     private _projectionUpdateFlag = -1;
-    private _alternateViewUpdateFlag = -1;
-    private _alternateProjectionUpdateFlag = -1;
 
     /** @hidden */
     public _toBeDisposed = new Array<Nullable<IDisposable>>(256);
@@ -1110,24 +1108,14 @@ export class Scene extends AbstractScene implements IAnimatable {
     private _transformMatrix = Matrix.Zero();
     private _transformMatrixR = Matrix.Zero();
     private _sceneUbo: UniformBuffer;
-    private _alternateSceneUbo: UniformBuffer;
+    private _multiviewSceneUbo: UniformBuffer;
 
     private _viewMatrix: Matrix;
     private _projectionMatrix: Matrix;
-    private _alternateViewMatrix: Matrix;
-    private _alternateProjectionMatrix: Matrix;
-    private _alternateTransformMatrix: Matrix;
-    private _useAlternateCameraConfiguration = false;
-    private _alternateRendering = false;
     private _wheelEventName = "";
     /** @hidden */
     public _forcedViewPosition: Nullable<Vector3>;
 
-    /** @hidden */
-    public get _isAlternateRenderingEnabled(): boolean {
-        return this._alternateRendering;
-    }
-
     private _frustumPlanes: Plane[];
     /**
      * Gets the list of frustum planes (built from the active camera)
@@ -1600,14 +1588,14 @@ export class Scene extends AbstractScene implements IAnimatable {
     private _createUbo(): void {
         this._sceneUbo = new UniformBuffer(this._engine, undefined, true);
         this._sceneUbo.addUniform("viewProjection", 16);
-        this._sceneUbo.addUniform("viewProjectionR", 16);
         this._sceneUbo.addUniform("view", 16);
     }
 
-    private _createAlternateUbo(): void {
-        this._alternateSceneUbo = new UniformBuffer(this._engine, undefined, true);
-        this._alternateSceneUbo.addUniform("viewProjection", 16);
-        this._alternateSceneUbo.addUniform("view", 16);
+    private _createMultiviewUbo(): void {
+        this._multiviewSceneUbo = new UniformBuffer(this._engine, undefined, true);
+        this._multiviewSceneUbo.addUniform("viewProjection", 16);
+        this._multiviewSceneUbo.addUniform("viewProjectionR", 16);
+        this._multiviewSceneUbo.addUniform("view", 16);
     }
 
     // Pointers handling
@@ -2528,17 +2516,13 @@ export class Scene extends AbstractScene implements IAnimatable {
     }
 
     // Matrix
-    /** @hidden */
-    public _switchToAlternateCameraConfiguration(active: boolean): void {
-        this._useAlternateCameraConfiguration = active;
-    }
 
     /**
      * Gets the current view matrix
      * @returns a Matrix
      */
     public getViewMatrix(): Matrix {
-        return this._useAlternateCameraConfiguration ? this._alternateViewMatrix : this._viewMatrix;
+        return this._viewMatrix;
     }
 
     /**
@@ -2546,7 +2530,7 @@ export class Scene extends AbstractScene implements IAnimatable {
      * @returns a Matrix
      */
     public getProjectionMatrix(): Matrix {
-        return this._useAlternateCameraConfiguration ? this._alternateProjectionMatrix : this._projectionMatrix;
+        return this._projectionMatrix;
     }
 
     /**
@@ -2554,7 +2538,7 @@ export class Scene extends AbstractScene implements IAnimatable {
      * @returns a Matrix made of View * Projection
      */
     public getTransformMatrix(): Matrix {
-        return this._useAlternateCameraConfiguration ? this._alternateTransformMatrix : this._transformMatrix;
+        return this._transformMatrix;
     }
 
     /**
@@ -2586,57 +2570,29 @@ export class Scene extends AbstractScene implements IAnimatable {
             Frustum.GetPlanesToRef(this._transformMatrix, this._frustumPlanes);
         }
 
-        if (this.activeCamera && this.activeCamera._alternateCamera) {
-            let otherCamera = this.activeCamera._alternateCamera;
-            otherCamera.getViewMatrix().multiplyToRef(otherCamera.getProjectionMatrix(), Tmp.Matrix[0]);
-            Frustum.GetRightPlaneToRef(Tmp.Matrix[0], this._frustumPlanes[3]); // Replace right plane by second camera right plane
-        } else if (viewR && projectionR) {
+        if (viewR && projectionR) {
             viewR.multiplyToRef(projectionR, Tmp.Matrix[0]);
             Frustum.GetRightPlaneToRef(Tmp.Matrix[0], this._frustumPlanes[3]); // Replace right plane by second camera right plane
         }
 
-        if (this._sceneUbo.useUbo) {
+        if (this._multiviewSceneUbo && this._multiviewSceneUbo.useUbo) {
+            this._multiviewSceneUbo.updateMatrix("viewProjection", this._transformMatrix);
+            this._multiviewSceneUbo.updateMatrix("viewProjectionR", this._transformMatrixR);
+            this._multiviewSceneUbo.updateMatrix("view", this._viewMatrix);
+            this._multiviewSceneUbo.update();
+        }else if (this._sceneUbo.useUbo) {
             this._sceneUbo.updateMatrix("viewProjection", this._transformMatrix);
-            this._sceneUbo.updateMatrix("viewProjectionR", this._transformMatrixR);
             this._sceneUbo.updateMatrix("view", this._viewMatrix);
             this._sceneUbo.update();
         }
     }
 
-    /** @hidden */
-    public _setAlternateTransformMatrix(view: Matrix, projection: Matrix): void {
-        if (this._alternateViewUpdateFlag === view.updateFlag && this._alternateProjectionUpdateFlag === projection.updateFlag) {
-            return;
-        }
-
-        this._alternateViewUpdateFlag = view.updateFlag;
-        this._alternateProjectionUpdateFlag = projection.updateFlag;
-        this._alternateViewMatrix = view;
-        this._alternateProjectionMatrix = projection;
-
-        if (!this._alternateTransformMatrix) {
-            this._alternateTransformMatrix = Matrix.Zero();
-        }
-
-        this._alternateViewMatrix.multiplyToRef(this._alternateProjectionMatrix, this._alternateTransformMatrix);
-
-        if (!this._alternateSceneUbo) {
-            this._createAlternateUbo();
-        }
-
-        if (this._alternateSceneUbo.useUbo) {
-            this._alternateSceneUbo.updateMatrix("viewProjection", this._alternateTransformMatrix);
-            this._alternateSceneUbo.updateMatrix("view", this._alternateViewMatrix);
-            this._alternateSceneUbo.update();
-        }
-    }
-
     /**
      * Gets the uniform buffer used to store scene data
      * @returns a UniformBuffer
      */
     public getSceneUniformBuffer(): UniformBuffer {
-        return this._useAlternateCameraConfiguration ? this._alternateSceneUbo : this._sceneUbo;
+        return this._multiviewSceneUbo ? this._multiviewSceneUbo : this._sceneUbo;
     }
 
     /**
@@ -4008,14 +3964,6 @@ export class Scene extends AbstractScene implements IAnimatable {
         this.setTransformMatrix(this.activeCamera.getViewMatrix(), this.activeCamera.getProjectionMatrix(force));
     }
 
-    /**
-     * Defines an alternate camera (used mostly in VR-like scenario where two cameras can render the same scene from a slightly different point of view)
-     * @param alternateCamera defines the camera to use
-     */
-    public updateAlternateTransformMatrix(alternateCamera: Camera): void {
-        this._setAlternateTransformMatrix(alternateCamera.getViewMatrix(), alternateCamera.getProjectionMatrix());
-    }
-
     private _bindFrameBuffer() {
         if (this.activeCamera && this.activeCamera._multiviewTexture) {
             this.activeCamera._multiviewTexture._bindFrameBuffer();
@@ -4063,11 +4011,6 @@ export class Scene extends AbstractScene implements IAnimatable {
             this.setTransformMatrix(camera._rigCameras[0].getViewMatrix(), camera._rigCameras[0].getProjectionMatrix(), camera._rigCameras[1].getViewMatrix(), camera._rigCameras[1].getProjectionMatrix());
         }else {
             this.updateTransformMatrix();
-
-            if (camera._alternateCamera) {
-                this.updateAlternateTransformMatrix(camera._alternateCamera);
-                this._alternateRendering = true;
-            }
         }
 
         this.onBeforeCameraRenderObservable.notifyObservers(this.activeCamera);
@@ -4156,8 +4099,6 @@ export class Scene extends AbstractScene implements IAnimatable {
         // Reset some special arrays
         this._renderTargets.reset();
 
-        this._alternateRendering = false;
-
         this.onAfterCameraRenderObservable.notifyObservers(this.activeCamera);
     }
 
@@ -4173,7 +4114,10 @@ export class Scene extends AbstractScene implements IAnimatable {
             // copying the result into the sub cameras instead of rendering them and proceeding as normal from there
 
             // Render to a multiview texture
-            camera._resizeorCreateMultiviewTexture(this.getEngine().getRenderWidth(true) / 2, this.getEngine().getRenderHeight(true));
+            camera._resizeOrCreateMultiviewTexture(this.getEngine().getRenderWidth(true) / 2, this.getEngine().getRenderHeight(true));
+            if (!this._multiviewSceneUbo) {
+                this._createMultiviewUbo();
+            }
             camera.outputRenderTarget = camera._multiviewTexture;
             this._renderForCamera(camera);
             camera.outputRenderTarget = null;
@@ -4670,8 +4614,8 @@ export class Scene extends AbstractScene implements IAnimatable {
         // Release UBO
         this._sceneUbo.dispose();
 
-        if (this._alternateSceneUbo) {
-            this._alternateSceneUbo.dispose();
+        if (this._multiviewSceneUbo) {
+            this._multiviewSceneUbo.dispose();
         }
 
         // Post-processes