예제 #1
0
 public override void Cleanup()
 {
     base.Cleanup();
     OVRCompositionUtil.SafeDestroy(ref this.directCompositionCameraGameObject);
     this.directCompositionCamera = null;
     Debug.Log("DirectComposition deactivated");
 }
    public override void Cleanup()
    {
        OVRCompositionUtil.SafeDestroy(ref backgroundCameraGameObject);
        backgroundCamera = null;
        OVRCompositionUtil.SafeDestroy(ref foregroundCameraGameObject);
        foregroundCamera = null;
        Debug.Log("ExternalComposition deactivated");

#if OVR_ANDROID_MRC
        if (lastMrcEncodeFrameSyncId != -1)
        {
            OVRPlugin.Media.SyncMrcFrame(lastMrcEncodeFrameSyncId);
            lastMrcEncodeFrameSyncId = -1;
        }

        CleanupAudioFilter();

        for (int i = 0; i < 2; ++i)
        {
            mrcRenderTextureArray[i].Release();
            mrcRenderTextureArray[i] = null;

            if (!renderCombinedFrame)
            {
                mrcForegroundRenderTextureArray[i].Release();
                mrcForegroundRenderTextureArray[i] = null;
            }
        }

        frameIndex = 0;
#endif
    }
    protected OVRCameraComposition(GameObject parentObject, Camera mainCamera, OVRManager.CameraDevice inCameraDevice, bool inUseDynamicLighting, OVRManager.DepthQuality depthQuality)
        : base(parentObject, mainCamera)
    {
        cameraDevice = OVRCompositionUtil.ConvertCameraDevice(inCameraDevice);

        Debug.Assert(!hasCameraDeviceOpened);
        Debug.Assert(!OVRPlugin.IsCameraDeviceAvailable(cameraDevice) || !OVRPlugin.HasCameraDeviceOpened(cameraDevice));
        hasCameraDeviceOpened = false;
        useDynamicLighting    = inUseDynamicLighting;

        bool cameraSupportsDepth = OVRPlugin.DoesCameraDeviceSupportDepth(cameraDevice);

        if (useDynamicLighting && !cameraSupportsDepth)
        {
            Debug.LogWarning("The camera device doesn't support depth. The result of dynamic lighting might not be correct");
        }

        if (OVRPlugin.IsCameraDeviceAvailable(cameraDevice))
        {
            OVRPlugin.CameraExtrinsics extrinsics;
            OVRPlugin.CameraIntrinsics intrinsics;
            OVRPlugin.Posef            calibrationRawPose;
            if (OVRPlugin.GetExternalCameraCount() > 0 && OVRPlugin.GetMixedRealityCameraInfo(0, out extrinsics, out intrinsics, out calibrationRawPose))
            {
                OVRPlugin.SetCameraDevicePreferredColorFrameSize(cameraDevice, intrinsics.ImageSensorPixelResolution.w, intrinsics.ImageSensorPixelResolution.h);
            }

            if (useDynamicLighting)
            {
                OVRPlugin.SetCameraDeviceDepthSensingMode(cameraDevice, OVRPlugin.CameraDeviceDepthSensingMode.Fill);
                OVRPlugin.CameraDeviceDepthQuality quality = OVRPlugin.CameraDeviceDepthQuality.Medium;
                if (depthQuality == OVRManager.DepthQuality.Low)
                {
                    quality = OVRPlugin.CameraDeviceDepthQuality.Low;
                }
                else if (depthQuality == OVRManager.DepthQuality.Medium)
                {
                    quality = OVRPlugin.CameraDeviceDepthQuality.Medium;
                }
                else if (depthQuality == OVRManager.DepthQuality.High)
                {
                    quality = OVRPlugin.CameraDeviceDepthQuality.High;
                }
                else
                {
                    Debug.LogWarning("Unknown depth quality");
                }
                OVRPlugin.SetCameraDevicePreferredDepthQuality(cameraDevice, quality);
            }

            Debug.LogFormat("Opening camera device {0}", cameraDevice);
            OVRPlugin.OpenCameraDevice(cameraDevice);
            if (OVRPlugin.HasCameraDeviceOpened(cameraDevice))
            {
                Debug.LogFormat("Opened camera device {0}", cameraDevice);
                hasCameraDeviceOpened = true;
            }
        }
    }
예제 #4
0
    private void RefreshCameraObjects(GameObject parentObject, Camera mainCamera, OVRMixedRealityCaptureConfiguration configuration)
    {
        if (!hasCameraDeviceOpened)
        {
            Debug.LogWarning("[OVRDirectComposition] RefreshCameraObjects(): Unable to open camera device " + cameraDevice);
            return;
        }

        if (mainCamera.gameObject != previousMainCameraObject)
        {
            Debug.LogFormat("[OVRDirectComposition] Camera refreshed. Rebind camera to {0}", mainCamera.gameObject.name);

            OVRCompositionUtil.SafeDestroy(ref directCompositionCameraGameObject);
            directCompositionCamera = null;

            RefreshCameraRig(parentObject, mainCamera);

            Debug.Assert(directCompositionCameraGameObject == null);
            if (configuration.instantiateMixedRealityCameraGameObject != null)
            {
                directCompositionCameraGameObject = configuration.instantiateMixedRealityCameraGameObject(mainCamera.gameObject, OVRManager.MrcCameraType.Normal);
            }
            else
            {
                directCompositionCameraGameObject = Object.Instantiate(mainCamera.gameObject);
            }
            directCompositionCameraGameObject.name             = "OculusMRC_DirectCompositionCamera";
            directCompositionCameraGameObject.transform.parent = cameraInTrackingSpace ? cameraRig.trackingSpace : parentObject.transform;
            if (directCompositionCameraGameObject.GetComponent <AudioListener>())
            {
                Object.Destroy(directCompositionCameraGameObject.GetComponent <AudioListener>());
            }
            if (directCompositionCameraGameObject.GetComponent <OVRManager>())
            {
                Object.Destroy(directCompositionCameraGameObject.GetComponent <OVRManager>());
            }
            directCompositionCamera = directCompositionCameraGameObject.GetComponent <Camera>();
#if USING_MRC_COMPATIBLE_URP_VERSION
            var directCamData = directCompositionCamera.GetUniversalAdditionalCameraData();
            if (directCamData != null)
            {
                directCamData.allowXRRendering = false;
            }
#elif USING_URP
            Debug.LogError("Using URP with MRC is only supported with URP version 10.0.0 or higher. Consider using Unity 2020 or higher.");
#else
            directCompositionCamera.stereoTargetEye = StereoTargetEyeMask.None;
#endif
            directCompositionCamera.depth       = float.MaxValue;
            directCompositionCamera.rect        = new Rect(0.0f, 0.0f, 1.0f, 1.0f);
            directCompositionCamera.cullingMask = (directCompositionCamera.cullingMask & ~configuration.extraHiddenLayers) | configuration.extraVisibleLayers;


            Debug.Log("DirectComposition activated : useDynamicLighting " + (configuration.useDynamicLighting ? "ON" : "OFF"));
            RefreshCameraFramePlaneObject(parentObject, directCompositionCamera, configuration);

            previousMainCameraObject = mainCamera.gameObject;
        }
    }
예제 #5
0
 public override void Cleanup()
 {
     OVRCompositionUtil.SafeDestroy(ref this.cameraFramePlaneObject);
     if (this.hasCameraDeviceOpened)
     {
         OVRPlugin.CloseCameraDevice(this.cameraDevice);
     }
 }
예제 #6
0
	public override void Cleanup()
	{
		OVRCompositionUtil.SafeDestroy(ref cameraFramePlaneObject):
		if (hasCameraDeviceOpened)
		{
			OVRPlugin.CloseCameraDevice(cameraDevice):
		}
	}
예제 #7
0
 public override void Cleanup()
 {
     OVRCompositionUtil.SafeDestroy(ref cameraFramePlaneObject);
     if (hasCameraDeviceOpened)
     {
         Debug.LogFormat("Close camera device {0}", cameraDevice);
         OVRPlugin.CloseCameraDevice(cameraDevice);
     }
 }
예제 #8
0
	public override void Cleanup()
	{
		base.Cleanup():

		OVRCompositionUtil.SafeDestroy(ref directCompositionCameraGameObject):
		directCompositionCamera = null:

		Debug.Log("DirectComposition deactivated"):
	}
예제 #9
0
 public override void Cleanup()
 {
     OVRCompositionUtil.SafeDestroy(ref backgroundCameraGameObject);
     backgroundCamera = null;
     OVRCompositionUtil.SafeDestroy(ref foregroundCameraGameObject);
     foregroundCamera = null;
     OVRCompositionUtil.SafeDestroy(ref cameraProxyPlane);
     Debug.Log("ExternalComposition deactivated");
 }
예제 #10
0
	protected OVRCameraComposition(OVRManager.CameraDevice inCameraDevice, bool inUseDynamicLighting, OVRManager.DepthQuality depthQuality)
	{
		cameraDevice = OVRCompositionUtil.ConvertCameraDevice(inCameraDevice):

		Debug.Assert(!hasCameraDeviceOpened):
		Debug.Assert(!OVRPlugin.IsCameraDeviceAvailable(cameraDevice) || !OVRPlugin.HasCameraDeviceOpened(cameraDevice)):
		hasCameraDeviceOpened = false:
		useDynamicLighting = inUseDynamicLighting:

		bool cameraSupportsDepth = OVRPlugin.DoesCameraDeviceSupportDepth(cameraDevice):
		if (useDynamicLighting && !cameraSupportsDepth)
		{
			Debug.LogWarning("The camera device doesn't support depth. The result of dynamic lighting might not be correct"):
		}

		if (OVRPlugin.IsCameraDeviceAvailable(cameraDevice))
		{
			OVRPlugin.CameraExtrinsics extrinsics:
			OVRPlugin.CameraIntrinsics intrinsics:
			if (OVRPlugin.GetExternalCameraCount() > 0 && OVRPlugin.GetMixedRealityCameraInfo(0, out extrinsics, out intrinsics))
			{
				OVRPlugin.SetCameraDevicePreferredColorFrameSize(cameraDevice, intrinsics.ImageSensorPixelResolution.w, intrinsics.ImageSensorPixelResolution.h):
			}

			if (useDynamicLighting)
			{
				OVRPlugin.SetCameraDeviceDepthSensingMode(cameraDevice, OVRPlugin.CameraDeviceDepthSensingMode.Fill):
				OVRPlugin.CameraDeviceDepthQuality quality = OVRPlugin.CameraDeviceDepthQuality.Medium:
				if (depthQuality == OVRManager.DepthQuality.Low)
				{
					quality = OVRPlugin.CameraDeviceDepthQuality.Low:
				}
				else if (depthQuality == OVRManager.DepthQuality.Medium)
				{
					quality = OVRPlugin.CameraDeviceDepthQuality.Medium:
				}
				else if (depthQuality == OVRManager.DepthQuality.High)
				{
					quality = OVRPlugin.CameraDeviceDepthQuality.High:
				}
				else
				{
					Debug.LogWarning("Unknown depth quality"):
				}
				OVRPlugin.SetCameraDevicePreferredDepthQuality(cameraDevice, quality):
			}

			OVRPlugin.OpenCameraDevice(cameraDevice):
			if (OVRPlugin.HasCameraDeviceOpened(cameraDevice))
			{
				hasCameraDeviceOpened = true:
			}
		}
	}
예제 #11
0
    protected void RefreshBoundaryMesh(Camera camera, out float cullingDistance)
    {
        float num = (!OVRManager.instance.virtualGreenScreenApplyDepthCulling) ? float.PositiveInfinity : OVRManager.instance.virtualGreenScreenDepthTolerance;

        cullingDistance = OVRCompositionUtil.GetMaximumBoundaryDistance(camera, OVRCompositionUtil.ToBoundaryType(OVRManager.instance.virtualGreenScreenType)) + num;
        if (this.boundaryMesh == null || this.boundaryMeshType != OVRManager.instance.virtualGreenScreenType || this.boundaryMeshTopY != OVRManager.instance.virtualGreenScreenTopY || this.boundaryMeshBottomY != OVRManager.instance.virtualGreenScreenBottomY)
        {
            this.boundaryMeshTopY    = OVRManager.instance.virtualGreenScreenTopY;
            this.boundaryMeshBottomY = OVRManager.instance.virtualGreenScreenBottomY;
            this.boundaryMesh        = OVRCompositionUtil.BuildBoundaryMesh(OVRCompositionUtil.ToBoundaryType(OVRManager.instance.virtualGreenScreenType), this.boundaryMeshTopY, this.boundaryMeshBottomY);
            this.boundaryMeshType    = OVRManager.instance.virtualGreenScreenType;
        }
    }
예제 #12
0
    private void RefreshCameraObjects(GameObject parentObject, Camera mainCamera, OVRMixedRealityCaptureConfiguration configuration)
    {
        if (!hasCameraDeviceOpened)
        {
            Debug.LogWarning("[OVRDirectComposition] RefreshCameraObjects(): Unable to open camera device " + cameraDevice);
            return;
        }

        if (mainCamera.gameObject != previousMainCameraObject)
        {
            Debug.LogFormat("[OVRDirectComposition] Camera refreshed. Rebind camera to {0}", mainCamera.gameObject.name);

            OVRCompositionUtil.SafeDestroy(ref directCompositionCameraGameObject);
            directCompositionCamera = null;

            RefreshCameraRig(parentObject, mainCamera);

            Debug.Assert(directCompositionCameraGameObject == null);
            if (configuration.instantiateMixedRealityCameraGameObject != null)
            {
                directCompositionCameraGameObject = configuration.instantiateMixedRealityCameraGameObject(mainCamera.gameObject, OVRManager.MrcCameraType.Normal);
            }
            else
            {
                directCompositionCameraGameObject = Object.Instantiate(mainCamera.gameObject);
            }
            directCompositionCameraGameObject.name             = "OculusMRC_DirectCompositionCamera";
            directCompositionCameraGameObject.transform.parent = cameraInTrackingSpace ? cameraRig.trackingSpace : parentObject.transform;
            if (directCompositionCameraGameObject.GetComponent <AudioListener>())
            {
                Object.Destroy(directCompositionCameraGameObject.GetComponent <AudioListener>());
            }
            if (directCompositionCameraGameObject.GetComponent <OVRManager>())
            {
                Object.Destroy(directCompositionCameraGameObject.GetComponent <OVRManager>());
            }
            directCompositionCamera = directCompositionCameraGameObject.GetComponent <Camera>();
            directCompositionCamera.stereoTargetEye = StereoTargetEyeMask.None;
            directCompositionCamera.depth           = float.MaxValue;
            directCompositionCamera.rect            = new Rect(0.0f, 0.0f, 1.0f, 1.0f);
            directCompositionCamera.cullingMask     = (directCompositionCamera.cullingMask & ~configuration.extraHiddenLayers) | configuration.extraVisibleLayers;


            Debug.Log("DirectComposition activated : useDynamicLighting " + (configuration.useDynamicLighting ? "ON" : "OFF"));
            RefreshCameraFramePlaneObject(parentObject, directCompositionCamera, configuration);

            previousMainCameraObject = mainCamera.gameObject;
        }
    }
예제 #13
0
    protected OVRCameraComposition(OVRManager.CameraDevice inCameraDevice, bool inUseDynamicLighting, OVRManager.DepthQuality depthQuality)
    {
        this.cameraDevice          = OVRCompositionUtil.ConvertCameraDevice(inCameraDevice);
        this.hasCameraDeviceOpened = false;
        this.useDynamicLighting    = inUseDynamicLighting;
        bool flag = OVRPlugin.DoesCameraDeviceSupportDepth(this.cameraDevice);

        if (this.useDynamicLighting && !flag)
        {
            Debug.LogWarning("The camera device doesn't support depth. The result of dynamic lighting might not be correct");
        }
        if (OVRPlugin.IsCameraDeviceAvailable(this.cameraDevice))
        {
            OVRPlugin.CameraExtrinsics cameraExtrinsics;
            OVRPlugin.CameraIntrinsics cameraIntrinsics;
            if (OVRPlugin.GetExternalCameraCount() > 0 && OVRPlugin.GetMixedRealityCameraInfo(0, out cameraExtrinsics, out cameraIntrinsics))
            {
                OVRPlugin.SetCameraDevicePreferredColorFrameSize(this.cameraDevice, cameraIntrinsics.ImageSensorPixelResolution.w, cameraIntrinsics.ImageSensorPixelResolution.h);
            }
            if (this.useDynamicLighting)
            {
                OVRPlugin.SetCameraDeviceDepthSensingMode(this.cameraDevice, OVRPlugin.CameraDeviceDepthSensingMode.Fill);
                OVRPlugin.CameraDeviceDepthQuality depthQuality2 = OVRPlugin.CameraDeviceDepthQuality.Medium;
                if (depthQuality == OVRManager.DepthQuality.Low)
                {
                    depthQuality2 = OVRPlugin.CameraDeviceDepthQuality.Low;
                }
                else if (depthQuality == OVRManager.DepthQuality.Medium)
                {
                    depthQuality2 = OVRPlugin.CameraDeviceDepthQuality.Medium;
                }
                else if (depthQuality == OVRManager.DepthQuality.High)
                {
                    depthQuality2 = OVRPlugin.CameraDeviceDepthQuality.High;
                }
                else
                {
                    Debug.LogWarning("Unknown depth quality");
                }
                OVRPlugin.SetCameraDevicePreferredDepthQuality(this.cameraDevice, depthQuality2);
            }
            OVRPlugin.OpenCameraDevice(this.cameraDevice);
            if (OVRPlugin.HasCameraDeviceOpened(this.cameraDevice))
            {
                this.hasCameraDeviceOpened = true;
            }
        }
    }
예제 #14
0
	protected void RefreshBoundaryMesh(Camera camera, out float cullingDistance)
	{
		float depthTolerance = OVRManager.instance.virtualGreenScreenApplyDepthCulling ? OVRManager.instance.virtualGreenScreenDepthTolerance : float.PositiveInfinity:
		cullingDistance = OVRCompositionUtil.GetMaximumBoundaryDistance(camera, OVRCompositionUtil.ToBoundaryType(OVRManager.instance.virtualGreenScreenType)) + depthTolerance:
		if (boundaryMesh == null || boundaryMeshType != OVRManager.instance.virtualGreenScreenType || boundaryMeshTopY != OVRManager.instance.virtualGreenScreenTopY || boundaryMeshBottomY != OVRManager.instance.virtualGreenScreenBottomY)
		{
			boundaryMeshTopY = OVRManager.instance.virtualGreenScreenTopY:
			boundaryMeshBottomY = OVRManager.instance.virtualGreenScreenBottomY:
			boundaryMesh = OVRCompositionUtil.BuildBoundaryMesh(OVRCompositionUtil.ToBoundaryType(OVRManager.instance.virtualGreenScreenType), boundaryMeshTopY, boundaryMeshBottomY):
			boundaryMeshType = OVRManager.instance.virtualGreenScreenType:

			// Creating GameObject for testing purpose only
			//GameObject boundaryMeshObject = new GameObject("BoundaryMeshObject"):
			//boundaryMeshObject.AddComponent<MeshFilter>().mesh = boundaryMesh:
			//boundaryMeshObject.AddComponent<MeshRenderer>():
		}
	}
    public override void Cleanup()
    {
        base.Cleanup();

        Camera[] cameras = { fgCamera, bgCamera, compositionCamera };

        foreach (Camera c in cameras)
        {
            OVRCompositionUtil.SafeDestroy(c.gameObject);
        }

        fgCamera          = null;
        bgCamera          = null;
        compositionCamera = null;

        Debug.Log("SandwichComposition deactivated");
    }
예제 #16
0
    protected void RefreshBoundaryMesh(Camera camera, OVRMixedRealityCaptureConfiguration configuration, out float cullingDistance)
    {
        float depthTolerance = configuration.virtualGreenScreenApplyDepthCulling ? configuration.virtualGreenScreenDepthTolerance : float.PositiveInfinity;

        cullingDistance = OVRCompositionUtil.GetMaximumBoundaryDistance(camera, OVRCompositionUtil.ToBoundaryType(configuration.virtualGreenScreenType)) + depthTolerance;
        if (boundaryMesh == null || boundaryMeshType != configuration.virtualGreenScreenType || boundaryMeshTopY != configuration.virtualGreenScreenTopY || boundaryMeshBottomY != configuration.virtualGreenScreenBottomY)
        {
            boundaryMeshTopY    = configuration.virtualGreenScreenTopY;
            boundaryMeshBottomY = configuration.virtualGreenScreenBottomY;
            boundaryMesh        = OVRCompositionUtil.BuildBoundaryMesh(OVRCompositionUtil.ToBoundaryType(configuration.virtualGreenScreenType), boundaryMeshTopY, boundaryMeshBottomY);
            boundaryMeshType    = configuration.virtualGreenScreenType;

            // Creating GameObject for testing purpose only
            //GameObject boundaryMeshObject = new GameObject("BoundaryMeshObject");
            //boundaryMeshObject.AddComponent<MeshFilter>().mesh = boundaryMesh;
            //boundaryMeshObject.AddComponent<MeshRenderer>();
        }
    }
예제 #17
0
 public override void Cleanup()
 {
     base.Cleanup();
     Camera[] array = new Camera[]
     {
         this.fgCamera,
         this.bgCamera,
         this.compositionCamera
     };
     foreach (Camera camera in array)
     {
         OVRCompositionUtil.SafeDestroy(camera.gameObject);
     }
     this.fgCamera          = null;
     this.bgCamera          = null;
     this.compositionCamera = null;
     Debug.Log("SandwichComposition deactivated");
 }
예제 #18
0
    protected void RefreshCameraFramePlaneObject(GameObject parentObject, Camera mixedRealityCamera, OVRMixedRealityCaptureConfiguration configuration)
    {
        OVRCompositionUtil.SafeDestroy(ref cameraFramePlaneObject);

        Debug.Assert(cameraFramePlaneObject == null);
        cameraFramePlaneObject                  = GameObject.CreatePrimitive(PrimitiveType.Quad);
        cameraFramePlaneObject.name             = "OculusMRC_CameraFrame";
        cameraFramePlaneObject.transform.parent = cameraInTrackingSpace ? cameraRig.trackingSpace : parentObject.transform;
        cameraFramePlaneObject.GetComponent <Collider>().enabled = false;
        cameraFramePlaneObject.GetComponent <MeshRenderer>().shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
        Material cameraFrameMaterial = new Material(Shader.Find(configuration.useDynamicLighting ? "Oculus/OVRMRCameraFrameLit" : "Oculus/OVRMRCameraFrame"));

        cameraFramePlaneObject.GetComponent <MeshRenderer>().material = cameraFrameMaterial;
        cameraFrameMaterial.SetColor("_Color", Color.white);
        cameraFrameMaterial.SetFloat("_Visible", 0.0f);
        cameraFramePlaneObject.transform.localScale = new Vector3(4, 4, 4);
        cameraFramePlaneObject.SetActive(true);
        cameraFrameCompositionManager = mixedRealityCamera.gameObject.AddComponent <OVRCameraFrameCompositionManager>();
        cameraFrameCompositionManager.configuration      = configuration;
        cameraFrameCompositionManager.cameraFrameGameObj = cameraFramePlaneObject;
        cameraFrameCompositionManager.composition        = this;
    }
예제 #19
0
    public static float GetMaximumBoundaryDistance(Camera camera, OVRBoundary.BoundaryType boundaryType)
    {
        if (!OVRManager.boundary.GetConfigured())
        {
            return(float.MaxValue);
        }
        Vector3[] geometry = OVRManager.boundary.GetGeometry(boundaryType);
        if (geometry.Length == 0)
        {
            return(float.MaxValue);
        }
        float num = float.MinValue;

        foreach (Vector3 trackingSpacePosition in geometry)
        {
            Vector3 worldPosition = OVRCompositionUtil.GetWorldPosition(trackingSpacePosition);
            float   num2          = Vector3.Dot(camera.transform.forward, worldPosition);
            if (num < num2)
            {
                num = num2;
            }
        }
        return(num);
    }
예제 #20
0
 public static void SafeDestroy(ref GameObject obj)
 {
     OVRCompositionUtil.SafeDestroy(obj);
     obj = null;
 }
    private void RefreshCameraObjects(GameObject parentObject, Camera mainCamera)
    {
        if (mainCamera.gameObject != previousMainCameraObject)
        {
            Debug.LogFormat("[OVRExternalComposition] Camera refreshed. Rebind camera to {0}", mainCamera.gameObject.name);

            OVRCompositionUtil.SafeDestroy(ref backgroundCameraGameObject);
            backgroundCamera = null;
            OVRCompositionUtil.SafeDestroy(ref foregroundCameraGameObject);
            foregroundCamera = null;

            RefreshCameraRig(parentObject, mainCamera);

            Debug.Assert(backgroundCameraGameObject == null);
            backgroundCameraGameObject                  = Object.Instantiate(mainCamera.gameObject);
            backgroundCameraGameObject.name             = "OculusMRC_BackgroundCamera";
            backgroundCameraGameObject.transform.parent = cameraInTrackingSpace ? cameraRig.trackingSpace : parentObject.transform;
            if (backgroundCameraGameObject.GetComponent <AudioListener>())
            {
                Object.Destroy(backgroundCameraGameObject.GetComponent <AudioListener>());
            }
            if (backgroundCameraGameObject.GetComponent <OVRManager>())
            {
                Object.Destroy(backgroundCameraGameObject.GetComponent <OVRManager>());
            }
            backgroundCamera                 = backgroundCameraGameObject.GetComponent <Camera>();
            backgroundCamera.tag             = "Untagged";
            backgroundCamera.stereoTargetEye = StereoTargetEyeMask.None;
            backgroundCamera.depth           = 99990.0f;
            backgroundCamera.rect            = new Rect(0.0f, 0.0f, 0.5f, 1.0f);
            backgroundCamera.cullingMask     = mainCamera.cullingMask & (~OVRManager.instance.extraHiddenLayers);
#if OVR_ANDROID_MRC
            backgroundCamera.targetTexture = mrcRenderTextureArray[0];
            if (!renderCombinedFrame)
            {
                backgroundCamera.rect = new Rect(0.0f, 0.0f, 1.0f, 1.0f);
            }
#endif

            Debug.Assert(foregroundCameraGameObject == null);
            foregroundCameraGameObject                  = Object.Instantiate(mainCamera.gameObject);
            foregroundCameraGameObject.name             = "OculusMRC_ForgroundCamera";
            foregroundCameraGameObject.transform.parent = cameraInTrackingSpace ? cameraRig.trackingSpace : parentObject.transform;
            if (foregroundCameraGameObject.GetComponent <AudioListener>())
            {
                Object.Destroy(foregroundCameraGameObject.GetComponent <AudioListener>());
            }
            if (foregroundCameraGameObject.GetComponent <OVRManager>())
            {
                Object.Destroy(foregroundCameraGameObject.GetComponent <OVRManager>());
            }
            foregroundCamera                 = foregroundCameraGameObject.GetComponent <Camera>();
            foregroundCamera.tag             = "Untagged";
            foregroundCamera.stereoTargetEye = StereoTargetEyeMask.None;
            foregroundCamera.depth           = backgroundCamera.depth + 1.0f;       // enforce the forground be rendered after the background
            foregroundCamera.rect            = new Rect(0.5f, 0.0f, 0.5f, 1.0f);
            foregroundCamera.clearFlags      = CameraClearFlags.Color;
#if OVR_ANDROID_MRC
            foregroundCamera.backgroundColor = OVRManager.instance.externalCompositionBackdropColorQuest;
#else
            foregroundCamera.backgroundColor = OVRManager.instance.externalCompositionBackdropColorRift;
#endif
            foregroundCamera.cullingMask = mainCamera.cullingMask & (~OVRManager.instance.extraHiddenLayers);
#if OVR_ANDROID_MRC
            if (renderCombinedFrame)
            {
                foregroundCamera.targetTexture = mrcRenderTextureArray[0];
            }
            else
            {
                foregroundCamera.targetTexture = mrcForegroundRenderTextureArray[0];
                foregroundCamera.rect          = new Rect(0.0f, 0.0f, 1.0f, 1.0f);
            }
#endif

            previousMainCameraObject = mainCamera.gameObject;
        }
    }
예제 #22
0
    private void RefreshCameraObjects(GameObject parentObject, Camera mainCamera)
    {
        if (mainCamera.gameObject != previousMainCameraObject)
        {
            Debug.LogFormat("[OVRExternalComposition] Camera refreshed. Rebind camera to {0}", mainCamera.gameObject.name);

            OVRCompositionUtil.SafeDestroy(ref backgroundCameraGameObject);
            backgroundCamera = null;
            OVRCompositionUtil.SafeDestroy(ref foregroundCameraGameObject);
            foregroundCamera = null;
            OVRCompositionUtil.SafeDestroy(ref cameraProxyPlane);

            RefreshCameraRig(parentObject, mainCamera);

            Debug.Assert(backgroundCameraGameObject == null);
            backgroundCameraGameObject                  = Object.Instantiate(mainCamera.gameObject);
            backgroundCameraGameObject.name             = "OculusMRC_BackgroundCamera";
            backgroundCameraGameObject.transform.parent = cameraInTrackingSpace ? cameraRig.trackingSpace : parentObject.transform;
            if (backgroundCameraGameObject.GetComponent <AudioListener>())
            {
                Object.Destroy(backgroundCameraGameObject.GetComponent <AudioListener>());
            }
            if (backgroundCameraGameObject.GetComponent <OVRManager>())
            {
                Object.Destroy(backgroundCameraGameObject.GetComponent <OVRManager>());
            }
            backgroundCamera                 = backgroundCameraGameObject.GetComponent <Camera>();
            backgroundCamera.tag             = "Untagged";
            backgroundCamera.stereoTargetEye = StereoTargetEyeMask.None;
            backgroundCamera.depth           = 99990.0f;
            backgroundCamera.rect            = new Rect(0.0f, 0.0f, 0.5f, 1.0f);
            backgroundCamera.cullingMask     = mainCamera.cullingMask & (~OVRManager.instance.extraHiddenLayers);
#if OVR_ANDROID_MRC
            backgroundCamera.targetTexture = mrcRenderTextureArray[0];
#endif

            Debug.Assert(foregroundCameraGameObject == null);
            foregroundCameraGameObject                  = Object.Instantiate(mainCamera.gameObject);
            foregroundCameraGameObject.name             = "OculusMRC_ForgroundCamera";
            foregroundCameraGameObject.transform.parent = cameraInTrackingSpace ? cameraRig.trackingSpace : parentObject.transform;
            if (foregroundCameraGameObject.GetComponent <AudioListener>())
            {
                Object.Destroy(foregroundCameraGameObject.GetComponent <AudioListener>());
            }
            if (foregroundCameraGameObject.GetComponent <OVRManager>())
            {
                Object.Destroy(foregroundCameraGameObject.GetComponent <OVRManager>());
            }
            foregroundCamera                 = foregroundCameraGameObject.GetComponent <Camera>();
            foregroundCamera.tag             = "Untagged";
            foregroundCamera.stereoTargetEye = StereoTargetEyeMask.None;
            foregroundCamera.depth           = backgroundCamera.depth + 1.0f;       // enforce the forground be rendered after the background
            foregroundCamera.rect            = new Rect(0.5f, 0.0f, 0.5f, 1.0f);
            foregroundCamera.clearFlags      = CameraClearFlags.Color;
#if OVR_ANDROID_MRC
            foregroundCamera.backgroundColor = OVRManager.instance.externalCompositionBackdropColorQuest;
#else
            foregroundCamera.backgroundColor = OVRManager.instance.externalCompositionBackdropColorRift;
#endif
            foregroundCamera.cullingMask = mainCamera.cullingMask & (~OVRManager.instance.extraHiddenLayers);
#if OVR_ANDROID_MRC
            foregroundCamera.targetTexture = mrcRenderTextureArray[0];
#endif

            // Create cameraProxyPlane for clipping
            Debug.Assert(cameraProxyPlane == null);
            cameraProxyPlane                  = GameObject.CreatePrimitive(PrimitiveType.Quad);
            cameraProxyPlane.name             = "OculusMRC_ProxyClipPlane";
            cameraProxyPlane.transform.parent = cameraInTrackingSpace ? cameraRig.trackingSpace : parentObject.transform;
            cameraProxyPlane.GetComponent <Collider>().enabled = false;
            cameraProxyPlane.GetComponent <MeshRenderer>().shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
            Material clipMaterial = new Material(Shader.Find("Oculus/OVRMRClipPlane"));
            cameraProxyPlane.GetComponent <MeshRenderer>().material = clipMaterial;
#if OVR_ANDROID_MRC
            clipMaterial.SetColor("_Color", OVRManager.instance.externalCompositionBackdropColorQuest);
#else
            clipMaterial.SetColor("_Color", OVRManager.instance.externalCompositionBackdropColorRift);
#endif
            clipMaterial.SetFloat("_Visible", 0.0f);
            cameraProxyPlane.transform.localScale = new Vector3(1000, 1000, 1000);
            cameraProxyPlane.SetActive(true);
            OVRMRForegroundCameraManager foregroundCameraManager = foregroundCameraGameObject.AddComponent <OVRMRForegroundCameraManager>();
            foregroundCameraManager.composition      = this;
            foregroundCameraManager.clipPlaneGameObj = cameraProxyPlane;

            previousMainCameraObject = mainCamera.gameObject;
        }
    }
예제 #23
0
    private void RefreshCameraObjects(GameObject parentObject, Camera mainCamera, OVRMixedRealityCaptureConfiguration configuration)
    {
        if (mainCamera.gameObject != previousMainCameraObject)
        {
            Debug.LogFormat("[OVRExternalComposition] Camera refreshed. Rebind camera to {0}", mainCamera.gameObject.name);

            OVRCompositionUtil.SafeDestroy(ref backgroundCameraGameObject);
            backgroundCamera = null;
            OVRCompositionUtil.SafeDestroy(ref foregroundCameraGameObject);
            foregroundCamera = null;

            RefreshCameraRig(parentObject, mainCamera);

            Debug.Assert(backgroundCameraGameObject == null);
            if (configuration.instantiateMixedRealityCameraGameObject != null)
            {
                backgroundCameraGameObject = configuration.instantiateMixedRealityCameraGameObject(mainCamera.gameObject, OVRManager.MrcCameraType.Background);
            }
            else
            {
                backgroundCameraGameObject = Object.Instantiate(mainCamera.gameObject);
            }

            backgroundCameraGameObject.name             = "OculusMRC_BackgroundCamera";
            backgroundCameraGameObject.transform.parent =
                cameraInTrackingSpace ? cameraRig.trackingSpace : parentObject.transform;
            if (backgroundCameraGameObject.GetComponent <AudioListener>())
            {
                Object.Destroy(backgroundCameraGameObject.GetComponent <AudioListener>());
            }

            if (backgroundCameraGameObject.GetComponent <OVRManager>())
            {
                Object.Destroy(backgroundCameraGameObject.GetComponent <OVRManager>());
            }
            backgroundCamera     = backgroundCameraGameObject.GetComponent <Camera>();
            backgroundCamera.tag = "Untagged";
#if USING_MRC_COMPATIBLE_URP_VERSION
            var backgroundCamData = backgroundCamera.GetUniversalAdditionalCameraData();
            if (backgroundCamData != null)
            {
                backgroundCamData.allowXRRendering = false;
            }
#elif USING_URP
            Debug.LogError("Using URP with MRC is only supported with URP version 10.0.0 or higher. Consider using Unity 2020 or higher.");
#else
            backgroundCamera.stereoTargetEye = StereoTargetEyeMask.None;
#endif
            backgroundCamera.depth       = 99990.0f;
            backgroundCamera.rect        = new Rect(0.0f, 0.0f, 0.5f, 1.0f);
            backgroundCamera.cullingMask = (backgroundCamera.cullingMask & ~configuration.extraHiddenLayers) | configuration.extraVisibleLayers;
#if OVR_ANDROID_MRC
            backgroundCamera.targetTexture = mrcRenderTextureArray[0];
            if (!renderCombinedFrame)
            {
                backgroundCamera.rect = new Rect(0.0f, 0.0f, 1.0f, 1.0f);
            }
#endif

            Debug.Assert(foregroundCameraGameObject == null);
            if (configuration.instantiateMixedRealityCameraGameObject != null)
            {
                foregroundCameraGameObject = configuration.instantiateMixedRealityCameraGameObject(mainCamera.gameObject, OVRManager.MrcCameraType.Foreground);
            }
            else
            {
                foregroundCameraGameObject = Object.Instantiate(mainCamera.gameObject);
            }

            foregroundCameraGameObject.name             = "OculusMRC_ForgroundCamera";
            foregroundCameraGameObject.transform.parent = cameraInTrackingSpace ? cameraRig.trackingSpace : parentObject.transform;
            if (foregroundCameraGameObject.GetComponent <AudioListener>())
            {
                Object.Destroy(foregroundCameraGameObject.GetComponent <AudioListener>());
            }
            if (foregroundCameraGameObject.GetComponent <OVRManager>())
            {
                Object.Destroy(foregroundCameraGameObject.GetComponent <OVRManager>());
            }
            foregroundCamera     = foregroundCameraGameObject.GetComponent <Camera>();
            foregroundCamera.tag = "Untagged";
#if USING_MRC_COMPATIBLE_URP_VERSION
            var foregroundCamData = foregroundCamera.GetUniversalAdditionalCameraData();
            if (foregroundCamData != null)
            {
                foregroundCamData.allowXRRendering = false;
            }
#elif USING_URP
            Debug.LogError("Using URP with MRC is only supported with URP version 10.0.0 or higher. Consider using Unity 2020 or higher.");
#else
            foregroundCamera.stereoTargetEye = StereoTargetEyeMask.None;
#endif
            foregroundCamera.depth      = backgroundCamera.depth + 1.0f;            // enforce the forground be rendered after the background
            foregroundCamera.rect       = new Rect(0.5f, 0.0f, 0.5f, 1.0f);
            foregroundCamera.clearFlags = CameraClearFlags.Color;
#if OVR_ANDROID_MRC
            foregroundCamera.backgroundColor = configuration.externalCompositionBackdropColorQuest;
#else
            foregroundCamera.backgroundColor = configuration.externalCompositionBackdropColorRift;
#endif
            foregroundCamera.cullingMask = (foregroundCamera.cullingMask & ~configuration.extraHiddenLayers) | configuration.extraVisibleLayers;

#if OVR_ANDROID_MRC
            if (renderCombinedFrame)
            {
                foregroundCamera.targetTexture = mrcRenderTextureArray[0];
            }
            else
            {
                foregroundCamera.targetTexture = mrcForegroundRenderTextureArray[0];
                foregroundCamera.rect          = new Rect(0.0f, 0.0f, 1.0f, 1.0f);
            }
#endif

            previousMainCameraObject = mainCamera.gameObject;
        }
    }