private static void InitializeExternalCompositionObjects(GameObject parentObject, Camera mainCamera)
    {
        Debug.Assert(!externalCompositionObjectsInitialized);
        Debug.Assert(!directCompositionObjectsInitialized);

        Debug.Assert(backgroundCameraGameObject == null);
        backgroundCameraGameObject                  = new GameObject();
        backgroundCameraGameObject.name             = "MRBackgroundCamera";
        backgroundCameraGameObject.transform.parent = parentObject.transform;
        backgroundCamera = backgroundCameraGameObject.AddComponent <Camera>();
        backgroundCamera.stereoTargetEye = StereoTargetEyeMask.None;
        backgroundCamera.depth           = float.MaxValue;
        backgroundCamera.rect            = new Rect(0.0f, 0.0f, 0.5f, 1.0f);
        backgroundCamera.clearFlags      = mainCamera.clearFlags;
        backgroundCamera.backgroundColor = mainCamera.backgroundColor;
        backgroundCamera.cullingMask     = mainCamera.cullingMask;
        backgroundCamera.nearClipPlane   = mainCamera.nearClipPlane;
        backgroundCamera.farClipPlane    = mainCamera.farClipPlane;

        Debug.Assert(foregroundCameraGameObject == null);
        foregroundCameraGameObject                  = new GameObject();
        foregroundCameraGameObject.name             = "MRForgroundCamera";
        foregroundCameraGameObject.transform.parent = parentObject.transform;
        foregroundCamera = foregroundCameraGameObject.AddComponent <Camera>();
        foregroundCamera.stereoTargetEye = StereoTargetEyeMask.None;
        foregroundCamera.depth           = float.MaxValue;
        foregroundCamera.rect            = new Rect(0.5f, 0.0f, 0.5f, 1.0f);
        foregroundCamera.clearFlags      = CameraClearFlags.Color;
        foregroundCamera.backgroundColor = chromaKeyColor;
        foregroundCamera.cullingMask     = mainCamera.cullingMask;
        foregroundCamera.nearClipPlane   = mainCamera.nearClipPlane;
        foregroundCamera.farClipPlane    = mainCamera.farClipPlane;

        // Create cameraProxyPlane for clipping
        Debug.Assert(cameraProxyPlane == null);
        cameraProxyPlane                  = GameObject.CreatePrimitive(PrimitiveType.Quad);
        cameraProxyPlane.name             = "MRProxyClipPlane";
        cameraProxyPlane.transform.parent = parentObject.transform;
        cameraProxyPlane.GetComponent <Collider>().enabled = false;
        cameraProxyPlane.GetComponent <MeshRenderer>().shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
        Material clipMaterial = new Material(Shader.Find("Unlit/OVRMRClipPlane"));

        cameraProxyPlane.GetComponent <MeshRenderer>().material = clipMaterial;
        clipMaterial.SetColor("_Color", chromaKeyColor);
        clipMaterial.SetFloat("_Visible", 0.0f);
        cameraProxyPlane.transform.localScale = new Vector3(1000, 1000, 1000);
        cameraProxyPlane.SetActive(true);
        OVRMRForegroundCameraManager foregroundCameraManager = foregroundCameraGameObject.AddComponent <OVRMRForegroundCameraManager>();

        foregroundCameraManager.clipPlaneGameObj = cameraProxyPlane;

        externalCompositionObjectsInitialized = true;
    }
Exemplo n.º 2
0
    public OVRExternalComposition(GameObject parentObject, Camera mainCamera)
        : base(parentObject, mainCamera)
    {
        Debug.Assert(backgroundCameraGameObject == null);
        backgroundCameraGameObject                  = new GameObject();
        backgroundCameraGameObject.name             = "MRBackgroundCamera";
        backgroundCameraGameObject.transform.parent = cameraInTrackingSpace ? cameraRig.trackingSpace : parentObject.transform;
        backgroundCamera = backgroundCameraGameObject.AddComponent <Camera>();
        backgroundCamera.stereoTargetEye = StereoTargetEyeMask.None;
        backgroundCamera.depth           = float.MaxValue;
        backgroundCamera.rect            = new Rect(0.0f, 0.0f, 0.5f, 1.0f);
        backgroundCamera.clearFlags      = mainCamera.clearFlags;
        backgroundCamera.backgroundColor = mainCamera.backgroundColor;
        backgroundCamera.cullingMask     = mainCamera.cullingMask & (~OVRManager.instance.extraHiddenLayers);
        backgroundCamera.nearClipPlane   = mainCamera.nearClipPlane;
        backgroundCamera.farClipPlane    = mainCamera.farClipPlane;

        Debug.Assert(foregroundCameraGameObject == null);
        foregroundCameraGameObject                  = new GameObject();
        foregroundCameraGameObject.name             = "MRForgroundCamera";
        foregroundCameraGameObject.transform.parent = cameraInTrackingSpace ? cameraRig.trackingSpace : parentObject.transform;
        foregroundCamera = foregroundCameraGameObject.AddComponent <Camera>();
        foregroundCamera.stereoTargetEye = StereoTargetEyeMask.None;
        foregroundCamera.depth           = float.MaxValue;
        foregroundCamera.rect            = new Rect(0.5f, 0.0f, 0.5f, 1.0f);
        foregroundCamera.clearFlags      = CameraClearFlags.Color;
        foregroundCamera.backgroundColor = OVRMixedReality.chromaKeyColor;
        foregroundCamera.cullingMask     = mainCamera.cullingMask & (~OVRManager.instance.extraHiddenLayers);
        foregroundCamera.nearClipPlane   = mainCamera.nearClipPlane;
        foregroundCamera.farClipPlane    = mainCamera.farClipPlane;

        // Create cameraProxyPlane for clipping
        Debug.Assert(cameraProxyPlane == null);
        cameraProxyPlane                  = GameObject.CreatePrimitive(PrimitiveType.Quad);
        cameraProxyPlane.name             = "MRProxyClipPlane";
        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;
        clipMaterial.SetColor("_Color", OVRMixedReality.chromaKeyColor);
        clipMaterial.SetFloat("_Visible", 0.0f);
        cameraProxyPlane.transform.localScale = new Vector3(1000, 1000, 1000);
        cameraProxyPlane.SetActive(true);
        OVRMRForegroundCameraManager foregroundCameraManager = foregroundCameraGameObject.AddComponent <OVRMRForegroundCameraManager>();

        foregroundCameraManager.clipPlaneGameObj = cameraProxyPlane;
    }
Exemplo n.º 3
0
    public OVRExternalComposition(GameObject parentObject, Camera mainCamera)
    {
        this.backgroundCameraGameObject                  = new GameObject();
        this.backgroundCameraGameObject.name             = "MRBackgroundCamera";
        this.backgroundCameraGameObject.transform.parent = parentObject.transform;
        this.backgroundCamera = this.backgroundCameraGameObject.AddComponent <Camera>();
        this.backgroundCamera.stereoTargetEye            = StereoTargetEyeMask.None;
        this.backgroundCamera.depth                      = float.MaxValue;
        this.backgroundCamera.rect                       = new Rect(0f, 0f, 0.5f, 1f);
        this.backgroundCamera.clearFlags                 = mainCamera.clearFlags;
        this.backgroundCamera.backgroundColor            = mainCamera.backgroundColor;
        this.backgroundCamera.cullingMask                = (mainCamera.cullingMask & ~OVRManager.instance.extraHiddenLayers);
        this.backgroundCamera.nearClipPlane              = mainCamera.nearClipPlane;
        this.backgroundCamera.farClipPlane               = mainCamera.farClipPlane;
        this.foregroundCameraGameObject                  = new GameObject();
        this.foregroundCameraGameObject.name             = "MRForgroundCamera";
        this.foregroundCameraGameObject.transform.parent = parentObject.transform;
        this.foregroundCamera = this.foregroundCameraGameObject.AddComponent <Camera>();
        this.foregroundCamera.stereoTargetEye = StereoTargetEyeMask.None;
        this.foregroundCamera.depth           = float.MaxValue;
        this.foregroundCamera.rect            = new Rect(0.5f, 0f, 0.5f, 1f);
        this.foregroundCamera.clearFlags      = CameraClearFlags.Color;
        this.foregroundCamera.backgroundColor = OVRMixedReality.chromaKeyColor;
        this.foregroundCamera.cullingMask     = (mainCamera.cullingMask & ~OVRManager.instance.extraHiddenLayers);
        this.foregroundCamera.nearClipPlane   = mainCamera.nearClipPlane;
        this.foregroundCamera.farClipPlane    = mainCamera.farClipPlane;
        this.cameraProxyPlane                  = GameObject.CreatePrimitive(PrimitiveType.Quad);
        this.cameraProxyPlane.name             = "MRProxyClipPlane";
        this.cameraProxyPlane.transform.parent = parentObject.transform;
        this.cameraProxyPlane.GetComponent <Collider>().enabled = false;
        this.cameraProxyPlane.GetComponent <MeshRenderer>().shadowCastingMode = ShadowCastingMode.Off;
        Material material = new Material(Shader.Find("Oculus/OVRMRClipPlane"));

        this.cameraProxyPlane.GetComponent <MeshRenderer>().material = material;
        material.SetColor("_Color", OVRMixedReality.chromaKeyColor);
        material.SetFloat("_Visible", 0f);
        this.cameraProxyPlane.transform.localScale = new Vector3(1000f, 1000f, 1000f);
        this.cameraProxyPlane.SetActive(true);
        OVRMRForegroundCameraManager ovrmrforegroundCameraManager = this.foregroundCameraGameObject.AddComponent <OVRMRForegroundCameraManager>();

        ovrmrforegroundCameraManager.clipPlaneGameObj = this.cameraProxyPlane;
    }
Exemplo n.º 4
0
    public OVRSandwichComposition(GameObject parentObject, Camera mainCamera, OVRManager.CameraDevice cameraDevice, bool useDynamicLighting, OVRManager.DepthQuality depthQuality) : base(cameraDevice, useDynamicLighting, depthQuality)
    {
        this.frameRealtime      = Time.realtimeSinceStartup;
        this.historyRecordCount = OVRManager.instance.sandwichCompositionBufferedFrames;
        if (this.historyRecordCount < 1)
        {
            Debug.LogWarning("Invalid sandwichCompositionBufferedFrames in OVRManager. It should be at least 1");
            this.historyRecordCount = 1;
        }
        if (this.historyRecordCount > 16)
        {
            Debug.LogWarning("The value of sandwichCompositionBufferedFrames in OVRManager is too big. It would consume a lot of memory. It has been override to 16");
            this.historyRecordCount = 16;
        }
        this.historyRecordArray = new OVRSandwichComposition.HistoryRecord[this.historyRecordCount];
        for (int i = 0; i < this.historyRecordCount; i++)
        {
            this.historyRecordArray[i] = new OVRSandwichComposition.HistoryRecord();
        }
        this.historyRecordCursorIndex = 0;
        this.fgCamera = new GameObject("MRSandwichForegroundCamera")
        {
            transform =
            {
                parent = parentObject.transform
            }
        }.AddComponent <Camera>();
        this.fgCamera.depth           = 200f;
        this.fgCamera.clearFlags      = CameraClearFlags.Color;
        this.fgCamera.backgroundColor = Color.clear;
        this.fgCamera.cullingMask     = (mainCamera.cullingMask & ~OVRManager.instance.extraHiddenLayers);
        this.fgCamera.nearClipPlane   = mainCamera.nearClipPlane;
        this.fgCamera.farClipPlane    = mainCamera.farClipPlane;
        this.bgCamera = new GameObject("MRSandwichBackgroundCamera")
        {
            transform =
            {
                parent = parentObject.transform
            }
        }.AddComponent <Camera>();
        this.bgCamera.depth                    = 100f;
        this.bgCamera.clearFlags               = mainCamera.clearFlags;
        this.bgCamera.backgroundColor          = mainCamera.backgroundColor;
        this.bgCamera.cullingMask              = (mainCamera.cullingMask & ~OVRManager.instance.extraHiddenLayers);
        this.bgCamera.nearClipPlane            = mainCamera.nearClipPlane;
        this.bgCamera.farClipPlane             = mainCamera.farClipPlane;
        this.cameraProxyPlane                  = GameObject.CreatePrimitive(PrimitiveType.Quad);
        this.cameraProxyPlane.name             = "MRProxyClipPlane";
        this.cameraProxyPlane.transform.parent = parentObject.transform;
        this.cameraProxyPlane.GetComponent <Collider>().enabled = false;
        this.cameraProxyPlane.GetComponent <MeshRenderer>().shadowCastingMode = ShadowCastingMode.Off;
        Material material = new Material(Shader.Find("Oculus/OVRMRClipPlane"));

        this.cameraProxyPlane.GetComponent <MeshRenderer>().material = material;
        material.SetColor("_Color", Color.clear);
        material.SetFloat("_Visible", 0f);
        this.cameraProxyPlane.transform.localScale = new Vector3(1000f, 1000f, 1000f);
        this.cameraProxyPlane.SetActive(true);
        OVRMRForegroundCameraManager ovrmrforegroundCameraManager = this.fgCamera.gameObject.AddComponent <OVRMRForegroundCameraManager>();

        ovrmrforegroundCameraManager.clipPlaneGameObj = this.cameraProxyPlane;
        this.compositionCamera = new GameObject("MRSandwichCaptureCamera")
        {
            transform =
            {
                parent = parentObject.transform
            }
        }.AddComponent <Camera>();
        this.compositionCamera.stereoTargetEye = StereoTargetEyeMask.None;
        this.compositionCamera.depth           = float.MaxValue;
        this.compositionCamera.rect            = new Rect(0f, 0f, 1f, 1f);
        this.compositionCamera.clearFlags      = CameraClearFlags.Depth;
        this.compositionCamera.backgroundColor = mainCamera.backgroundColor;
        this.compositionCamera.cullingMask     = 1 << this.cameraFramePlaneLayer;
        this.compositionCamera.nearClipPlane   = mainCamera.nearClipPlane;
        this.compositionCamera.farClipPlane    = mainCamera.farClipPlane;
        if (!this.hasCameraDeviceOpened)
        {
            Debug.LogError("Unable to open camera device " + cameraDevice);
        }
        else
        {
            Debug.Log("SandwichComposition activated : useDynamicLighting " + ((!useDynamicLighting) ? "OFF" : "ON"));
            base.CreateCameraFramePlaneObject(parentObject, this.compositionCamera, useDynamicLighting);
            this.cameraFramePlaneObject.layer = this.cameraFramePlaneLayer;
            this.RefreshRenderTextures(mainCamera);
            this.compositionManager           = this.compositionCamera.gameObject.AddComponent <OVRSandwichComposition.OVRSandwichCompositionManager>();
            this.compositionManager.fgTexture = this.historyRecordArray[this.historyRecordCursorIndex].fgRenderTexture;
            this.compositionManager.bgTexture = this.historyRecordArray[this.historyRecordCursorIndex].bgRenderTexture;
        }
    }
    public OVRExternalComposition(GameObject parentObject, Camera mainCamera)
        : base(parentObject, mainCamera)
    {
#if OVR_ANDROID_MRC
        int frameWidth;
        int frameHeight;
        OVRPlugin.Media.GetMrcFrameSize(out frameWidth, out frameHeight);
        Debug.LogFormat("[OVRExternalComposition] Create render texture {0}, {1}", frameWidth, frameHeight);
        for (int i = 0; i < 2; ++i)
        {
            mrcRenderTextureArray[i] = new RenderTexture(frameWidth, frameHeight, 24, RenderTextureFormat.ARGB32);
            mrcRenderTextureArray[i].Create();
        }

        frameIndex = 0;
        lastMrcEncodeFrameSyncId = -1;
#endif

        Debug.Assert(backgroundCameraGameObject == null);
        backgroundCameraGameObject                  = new GameObject();
        backgroundCameraGameObject.name             = "MRBackgroundCamera";
        backgroundCameraGameObject.transform.parent = cameraInTrackingSpace ? cameraRig.trackingSpace : parentObject.transform;
        backgroundCamera = backgroundCameraGameObject.AddComponent <Camera>();
        backgroundCamera.stereoTargetEye = StereoTargetEyeMask.None;
        backgroundCamera.depth           = 99990.0f;
        backgroundCamera.rect            = new Rect(0.0f, 0.0f, 0.5f, 1.0f);
        backgroundCamera.clearFlags      = mainCamera.clearFlags;
        backgroundCamera.backgroundColor = mainCamera.backgroundColor;
        backgroundCamera.cullingMask     = mainCamera.cullingMask & (~OVRManager.instance.extraHiddenLayers);
        backgroundCamera.nearClipPlane   = mainCamera.nearClipPlane;
        backgroundCamera.farClipPlane    = mainCamera.farClipPlane;
#if OVR_ANDROID_MRC
        backgroundCamera.targetTexture = mrcRenderTextureArray[0];
#endif

        Debug.Assert(foregroundCameraGameObject == null);
        foregroundCameraGameObject                  = new GameObject();
        foregroundCameraGameObject.name             = "MRForgroundCamera";
        foregroundCameraGameObject.transform.parent = cameraInTrackingSpace ? cameraRig.trackingSpace : parentObject.transform;
        foregroundCamera = foregroundCameraGameObject.AddComponent <Camera>();
        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;
        foregroundCamera.backgroundColor = OVRManager.instance.externalCompositionBackdropColor;
        foregroundCamera.cullingMask     = mainCamera.cullingMask & (~OVRManager.instance.extraHiddenLayers);
        foregroundCamera.nearClipPlane   = mainCamera.nearClipPlane;
        foregroundCamera.farClipPlane    = mainCamera.farClipPlane;
#if OVR_ANDROID_MRC
        foregroundCamera.targetTexture = mrcRenderTextureArray[0];
#endif

        // Create cameraProxyPlane for clipping
        Debug.Assert(cameraProxyPlane == null);
        cameraProxyPlane                  = GameObject.CreatePrimitive(PrimitiveType.Quad);
        cameraProxyPlane.name             = "MRProxyClipPlane";
        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;
        clipMaterial.SetColor("_Color", OVRManager.instance.externalCompositionBackdropColor);
        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;
    }
    public OVRSandwichComposition(GameObject parentObject, Camera mainCamera, OVRManager.CameraDevice cameraDevice, bool useDynamicLighting, OVRManager.DepthQuality depthQuality)
        : base(cameraDevice, useDynamicLighting, depthQuality)
    {
        frameRealtime = Time.realtimeSinceStartup;

        historyRecordCount = OVRManager.instance.sandwichCompositionBufferedFrames;
        if (historyRecordCount < 1)
        {
            Debug.LogWarning("Invalid sandwichCompositionBufferedFrames in OVRManager. It should be at least 1");
            historyRecordCount = 1;
        }
        if (historyRecordCount > 16)
        {
            Debug.LogWarning("The value of sandwichCompositionBufferedFrames in OVRManager is too big. It would consume a lot of memory. It has been override to 16");
            historyRecordCount = 16;
        }
        historyRecordArray = new HistoryRecord[historyRecordCount];
        for (int i = 0; i < historyRecordCount; ++i)
        {
            historyRecordArray[i] = new HistoryRecord();
        }
        historyRecordCursorIndex = 0;

        GameObject fgObject = new GameObject("MRSandwichForegroundCamera");

        fgObject.transform.parent = parentObject.transform;
        fgCamera                 = fgObject.AddComponent <Camera>();
        fgCamera.depth           = 200;
        fgCamera.clearFlags      = CameraClearFlags.SolidColor;
        fgCamera.backgroundColor = Color.clear;
        fgCamera.cullingMask     = mainCamera.cullingMask & (~OVRManager.instance.extraHiddenLayers);
        fgCamera.nearClipPlane   = mainCamera.nearClipPlane;
        fgCamera.farClipPlane    = mainCamera.farClipPlane;

        GameObject bgObject = new GameObject("MRSandwichBackgroundCamera");

        bgObject.transform.parent = parentObject.transform;
        bgCamera                 = bgObject.AddComponent <Camera>();
        bgCamera.depth           = 100;
        bgCamera.clearFlags      = mainCamera.clearFlags;
        bgCamera.backgroundColor = mainCamera.backgroundColor;
        bgCamera.cullingMask     = mainCamera.cullingMask & (~OVRManager.instance.extraHiddenLayers);
        bgCamera.nearClipPlane   = mainCamera.nearClipPlane;
        bgCamera.farClipPlane    = mainCamera.farClipPlane;

        // Create cameraProxyPlane for clipping
        Debug.Assert(cameraProxyPlane == null);
        cameraProxyPlane                  = GameObject.CreatePrimitive(PrimitiveType.Quad);
        cameraProxyPlane.name             = "MRProxyClipPlane";
        cameraProxyPlane.transform.parent = 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;
        clipMaterial.SetColor("_Color", Color.clear);
        clipMaterial.SetFloat("_Visible", 0.0f);
        cameraProxyPlane.transform.localScale = new Vector3(1000, 1000, 1000);
        cameraProxyPlane.SetActive(true);
        OVRMRForegroundCameraManager foregroundCameraManager = fgCamera.gameObject.AddComponent <OVRMRForegroundCameraManager>();

        foregroundCameraManager.clipPlaneGameObj = cameraProxyPlane;

        GameObject compositionCameraObject = new GameObject("MRSandwichCaptureCamera");

        compositionCameraObject.transform.parent = parentObject.transform;
        compositionCamera = compositionCameraObject.AddComponent <Camera>();
        compositionCamera.stereoTargetEye = StereoTargetEyeMask.None;
        compositionCamera.depth           = float.MaxValue;
        compositionCamera.rect            = new Rect(0.0f, 0.0f, 1.0f, 1.0f);
        compositionCamera.clearFlags      = CameraClearFlags.Depth;
        compositionCamera.backgroundColor = mainCamera.backgroundColor;
        compositionCamera.cullingMask     = 1 << cameraFramePlaneLayer;
        compositionCamera.nearClipPlane   = mainCamera.nearClipPlane;
        compositionCamera.farClipPlane    = mainCamera.farClipPlane;

        if (!hasCameraDeviceOpened)
        {
            Debug.LogError("Unable to open camera device " + cameraDevice);
        }
        else
        {
            Debug.Log("SandwichComposition activated : useDynamicLighting " + (useDynamicLighting ? "ON" : "OFF"));
            CreateCameraFramePlaneObject(parentObject, compositionCamera, useDynamicLighting);
            cameraFramePlaneObject.layer = cameraFramePlaneLayer;
            RefreshRenderTextures(mainCamera);
            compositionManager           = compositionCamera.gameObject.AddComponent <OVRSandwichCompositionManager>();
            compositionManager.fgTexture = historyRecordArray[historyRecordCursorIndex].fgRenderTexture;
            compositionManager.bgTexture = historyRecordArray[historyRecordCursorIndex].bgRenderTexture;
        }
    }
Exemplo n.º 7
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;
        }
    }