Пример #1
0
    protected void RefreshRenderTextures(Camera mainCamera)
    {
        int width  = Screen.width;
        int height = Screen.height;
        RenderTextureFormat renderTextureFormat = (!mainCamera.targetTexture) ? RenderTextureFormat.ARGB32 : this.DesiredRenderTextureFormat(mainCamera.targetTexture.format);
        int num = (!mainCamera.targetTexture) ? 24 : mainCamera.targetTexture.depth;

        OVRSandwichComposition.HistoryRecord historyRecord = this.historyRecordArray[this.historyRecordCursorIndex];
        historyRecord.timestamp = this.frameRealtime;
        if (historyRecord.fgRenderTexture == null || historyRecord.fgRenderTexture.width != width || historyRecord.fgRenderTexture.height != height || historyRecord.fgRenderTexture.format != renderTextureFormat || historyRecord.fgRenderTexture.depth != num)
        {
            historyRecord.fgRenderTexture      = new RenderTexture(width, height, num, renderTextureFormat);
            historyRecord.fgRenderTexture.name = "Sandwich FG " + this.historyRecordCursorIndex.ToString();
        }
        this.fgCamera.targetTexture = historyRecord.fgRenderTexture;
        if (historyRecord.bgRenderTexture == null || historyRecord.bgRenderTexture.width != width || historyRecord.bgRenderTexture.height != height || historyRecord.bgRenderTexture.format != renderTextureFormat || historyRecord.bgRenderTexture.depth != num)
        {
            historyRecord.bgRenderTexture      = new RenderTexture(width, height, num, renderTextureFormat);
            historyRecord.bgRenderTexture.name = "Sandwich BG " + this.historyRecordCursorIndex.ToString();
        }
        this.bgCamera.targetTexture = historyRecord.bgRenderTexture;
        if (OVRManager.instance.virtualGreenScreenType != OVRManager.VirtualGreenScreenType.Off)
        {
            if (historyRecord.boundaryMeshMaskTexture == null || historyRecord.boundaryMeshMaskTexture.width != width || historyRecord.boundaryMeshMaskTexture.height != height)
            {
                historyRecord.boundaryMeshMaskTexture      = new RenderTexture(width, height, 0, RenderTextureFormat.R8);
                historyRecord.boundaryMeshMaskTexture.name = "Boundary Mask " + this.historyRecordCursorIndex.ToString();
                historyRecord.boundaryMeshMaskTexture.Create();
            }
        }
        else
        {
            historyRecord.boundaryMeshMaskTexture = null;
        }
    }
Пример #2
0
 public override void Update(Camera mainCamera)
 {
     if (!this.hasCameraDeviceOpened)
     {
         return;
     }
     this.frameRealtime = Time.realtimeSinceStartup;
     this.historyRecordCursorIndex++;
     if (this.historyRecordCursorIndex >= this.historyRecordCount)
     {
         this.historyRecordCursorIndex = 0;
     }
     if (!OVRPlugin.SetHandNodePoseStateLatency((double)OVRManager.instance.handPoseStateLatency))
     {
         Debug.LogWarning("HandPoseStateLatency is invalid. Expect a value between 0.0 to 0.5, get " + OVRManager.instance.handPoseStateLatency);
     }
     this.RefreshRenderTextures(mainCamera);
     this.bgCamera.clearFlags      = mainCamera.clearFlags;
     this.bgCamera.backgroundColor = mainCamera.backgroundColor;
     this.bgCamera.cullingMask     = (mainCamera.cullingMask & ~OVRManager.instance.extraHiddenLayers);
     this.fgCamera.cullingMask     = (mainCamera.cullingMask & ~OVRManager.instance.extraHiddenLayers);
     OVRPlugin.CameraExtrinsics extrinsics;
     OVRPlugin.CameraIntrinsics cameraIntrinsics;
     if (OVRMixedReality.useFakeExternalCamera || OVRPlugin.GetExternalCameraCount() == 0)
     {
         OVRPose pose = default(OVRPose);
         pose = OVRExtensions.ToWorldSpacePose(new OVRPose
         {
             position    = OVRMixedReality.fakeCameraPositon,
             orientation = OVRMixedReality.fakeCameraRotation
         });
         this.RefreshCameraPoses(OVRMixedReality.fakeCameraFov, OVRMixedReality.fakeCameraAspect, pose);
     }
     else if (OVRPlugin.GetMixedRealityCameraInfo(0, out extrinsics, out cameraIntrinsics))
     {
         OVRPose pose2  = base.ComputeCameraWorldSpacePose(extrinsics);
         float   fovY   = Mathf.Atan(cameraIntrinsics.FOVPort.UpTan) * 57.29578f * 2f;
         float   aspect = cameraIntrinsics.FOVPort.LeftTan / cameraIntrinsics.FOVPort.UpTan;
         this.RefreshCameraPoses(fovY, aspect, pose2);
     }
     else
     {
         Debug.LogWarning("Failed to get external camera information");
     }
     this.compositionCamera.GetComponent <OVRCameraComposition.OVRCameraFrameCompositionManager>().boundaryMeshMaskTexture = this.historyRecordArray[this.historyRecordCursorIndex].boundaryMeshMaskTexture;
     OVRSandwichComposition.HistoryRecord historyRecordForComposition = this.GetHistoryRecordForComposition();
     base.UpdateCameraFramePlaneObject(mainCamera, this.compositionCamera, historyRecordForComposition.boundaryMeshMaskTexture);
     OVRSandwichComposition.OVRSandwichCompositionManager component = this.compositionCamera.gameObject.GetComponent <OVRSandwichComposition.OVRSandwichCompositionManager>();
     component.fgTexture = historyRecordForComposition.fgRenderTexture;
     component.bgTexture = historyRecordForComposition.bgRenderTexture;
     this.cameraProxyPlane.transform.position = this.fgCamera.transform.position + this.fgCamera.transform.forward * this.cameraFramePlaneDistance;
     this.cameraProxyPlane.transform.LookAt(this.cameraProxyPlane.transform.position + this.fgCamera.transform.forward);
 }