瀏覽代碼

webVRHelper multiview support

Trevor Baron 6 年之前
父節點
當前提交
4aee1bd719
共有 5 個文件被更改,包括 29 次插入1 次删除
  1. 1 0
      src/Cameras/RigModes/vrRigMode.ts
  2. 6 0
      src/Cameras/VR/vrExperienceHelper.ts
  3. 16 0
      src/Cameras/VR/webVRCamera.ts
  4. 5 0
      src/Cameras/camera.ts
  5. 1 1
      src/scene.ts

+ 1 - 0
src/Cameras/RigModes/vrRigMode.ts

@@ -29,6 +29,7 @@ Camera._setVRRigMode = function(camera: Camera, rigParams: any) {
             Logger.Warn("Multiview is not supported, falling back to standard rendering");
             metrics.multiviewEnabled = false;
         }else {
+            camera._useMultiviewToSingleView = true;
             camera._rigPostProcess = new VRMultiviewToSingleview("VRMultiviewToSingleview", camera, 1.0);
         }
     }

+ 6 - 0
src/Cameras/VR/vrExperienceHelper.ts

@@ -707,6 +707,12 @@ export class VRExperienceHelper {
 
         // Create VR cameras
         if (webVROptions.createFallbackVRDeviceOrientationFreeCamera) {
+            if (webVROptions.useMultiview) {
+                if (!webVROptions.vrDeviceOrientationCameraMetrics) {
+                    webVROptions.vrDeviceOrientationCameraMetrics = VRCameraMetrics.GetDefault();
+                }
+                webVROptions.vrDeviceOrientationCameraMetrics.multiviewEnabled = true;
+            }
             this._vrDeviceOrientationCamera = new VRDeviceOrientationFreeCamera("VRDeviceOrientationVRHelper", this._position, this._scene, true, webVROptions.vrDeviceOrientationCameraMetrics);
             this._vrDeviceOrientationCamera.angularSensibility = Number.MAX_VALUE;
         }

+ 16 - 0
src/Cameras/VR/webVRCamera.ts

@@ -13,6 +13,8 @@ import { Node } from "../../node";
 import { AbstractMesh } from "../../Meshes/abstractMesh";
 import { Ray } from "../../Culling/ray";
 import { HemisphericLight } from "../../Lights/hemisphericLight";
+import { Logger } from '../../Misc/logger';
+import { VRMultiviewToSingleview } from '../../PostProcesses/vrDistortionCorrectionPostProcess';
 
 // Side effect import to define the stereoscopic mode.
 import "../RigModes/webVRRigMode";
@@ -140,6 +142,10 @@ export interface WebVROptions {
      */
     defaultHeight?: number;
 
+    /**
+     * If multiview should be used if availible (default: false)
+     */
+    useMultiview?: boolean;
 }
 
 /**
@@ -277,6 +283,16 @@ export class WebVRFreeCamera extends FreeCamera implements PoseControlled {
             this._frameData = new VRFrameData();
         }
 
+        if (webVROptions.useMultiview) {
+            if (!this.getScene().getEngine().getCaps().multiview) {
+                Logger.Warn("Multiview is not supported, falling back to standard rendering");
+                this._useMultiviewToSingleView = false;
+            }else {
+                this._useMultiviewToSingleView = true;
+                this._rigPostProcess = new VRMultiviewToSingleview("VRMultiviewToSingleview", this, 1.0);
+            }
+        }
+
         /**
          * The idea behind the following lines:
          * objects that have the camera as parent should actually have the rig cameras as a parent.

+ 5 - 0
src/Cameras/camera.ts

@@ -243,6 +243,11 @@ export class Camera extends Node {
      * @hidden
      * For cameras that cannot use multiview images to display directly. (e.g. webVR camera will render to multiview texture, then copy to each eye texture and go from there)
      */
+    public _useMultiviewToSingleView = false;
+    /**
+     * @hidden
+     * For cameras that cannot use multiview images to display directly. (e.g. webVR camera will render to multiview texture, then copy to each eye texture and go from there)
+     */
     public _multiviewTexture: Nullable<RenderTargetTexture> = null;
 
     /**

+ 1 - 1
src/scene.ts

@@ -4108,7 +4108,7 @@ export class Scene extends AbstractScene implements IAnimatable {
             return;
         }
 
-        if (camera._rigCameras[0]._cameraRigParams && camera._rigCameras[0]._cameraRigParams.vrMetrics && camera._rigCameras[0]._cameraRigParams.vrMetrics.multiviewEnabled) {
+        if (camera._useMultiviewToSingleView) {
             // Multiview is only able to be displayed directly for API's such as webXR
             // This displays a multiview image by rendering to the multiview image and then
             // copying the result into the sub cameras instead of rendering them and proceeding as normal from there