Beispiel #1
0
    IEnumerator EndOfFrame()
    {
        while (true)
        {
            yield return(new WaitForEndOfFrame());

#if !UNITY_EDITOR
            if (!Pvr_UnitySDKManager.SDK.isEnterVRMode)
            {
                // Call GL.clear before Enter VRMode to avoid unexpected graph breaking.
                GL.Clear(false, true, Color.black);
            }
#endif
            if (isFirstStartup && frameNum == this.WaitSplashScreenFrames)
            {
                Pvr_UnitySDKAPI.System.UPvr_RemovePlatformLogo();
                if (Pvr_UnitySDKManager.SDK.ResetTrackerOnLoad)
                {
                    Debug.Log("Reset Tracker OnLoad");
                    Pvr_UnitySDKManager.pvr_UnitySDKSensor.OptionalResetUnitySDKSensor(1, 1);
                }

                Pvr_UnitySDKAPI.System.UPvr_StartVRModel();
                isFirstStartup = false;
            }
            else if (isFirstStartup && frameNum < this.WaitSplashScreenFrames)
            {
                PLOG.I("frameNum:" + frameNum);
                frameNum++;
            }

            #region Eyebuffer
#if UNITY_2018_1_OR_NEWER && !UNITY_2019_1_OR_NEWER
            if (UnityEngine.Rendering.GraphicsSettings.renderPipelineAsset != null)
            {
                for (int i = 0; i < Eyes.Length; i++)
                {
                    if (!Eyes[i].isActiveAndEnabled || !Eyes[i].eyecamera.enabled)
                    {
                        continue;
                    }

                    switch (Eyes[i].eyeSide)
                    {
                    case Pvr_UnitySDKAPI.Eye.LeftEye:
                        eyeTextureId = Pvr_UnitySDKManager.SDK.eyeTextureIds[Pvr_UnitySDKManager.SDK.currEyeTextureIdx];
                        eventType    = RenderEventType.LeftEyeEndFrame;
                        break;

                    case Pvr_UnitySDKAPI.Eye.RightEye:
                        if (!Pvr_UnitySDKManager.SDK.Monoscopic)
                        {
                            eyeTextureId = Pvr_UnitySDKManager.SDK.eyeTextureIds[Pvr_UnitySDKManager.SDK.currEyeTextureIdx + 3];
                        }
                        else
                        {
                            eyeTextureId = Pvr_UnitySDKManager.SDK.eyeTextureIds[Pvr_UnitySDKManager.SDK.currEyeTextureIdx];
                        }
                        eventType = RenderEventType.RightEyeEndFrame;
                        break;

                    case Pvr_UnitySDKAPI.Eye.BothEye:
                        eyeTextureId = Pvr_UnitySDKManager.SDK.eyeTextureIds[Pvr_UnitySDKManager.SDK.currEyeTextureIdx];
                        eventType    = RenderEventType.BothEyeEndFrame;
                        break;

                    default:
                        break;
                    }

                    // eyebuffer
                    Pvr_UnitySDKAPI.System.UPvr_UnityEventData(Pvr_UnitySDKAPI.System.UPvr_GetEyeBufferData(eyeTextureId));;
                    Pvr_UnitySDKPluginEvent.Issue(eventType);

                    Pvr_UnitySDKPluginEvent.Issue(RenderEventType.EndEye);
                }
            }
#endif
            #endregion

            // Compositor Layers: if find Overlay then Open Compositor Layers feature
            #region Compositor Layers
            int boundaryState = BoundarySystem.UPvr_GetSeeThroughState();
            if (Pvr_UnitySDKEyeOverlay.Instances.Count > 0 && boundaryState != 2)
            {
                overlayLayerDepth  = 1;
                underlayLayerDepth = 0;

                Pvr_UnitySDKEyeOverlay.Instances.Sort();
                for (int i = 0; i < Overlays.Length; i++)
                {
                    if (!Overlays[i].isActiveAndEnabled)
                    {
                        continue;
                    }
                    if (Overlays[i].layerTextures[0] == null && Overlays[i].layerTextures[1] == null && !Overlays[i].isExternalAndroidSurface)
                    {
                        continue;
                    }
                    if (Overlays[i].layerTransform != null && !Overlays[i].layerTransform.gameObject.activeSelf)
                    {
                        continue;
                    }

                    layerFlags = 0;

                    if (Overlays[i].overlayShape == Pvr_UnitySDKEyeOverlay.OverlayShape.Quad || Overlays[i].overlayShape == Pvr_UnitySDKEyeOverlay.OverlayShape.Cylinder)
                    {
                        if (Overlays[i].overlayType == Pvr_UnitySDKEyeOverlay.OverlayType.Overlay)
                        {
                            isHeadLocked = false;
                            if (Overlays[i].layerTransform != null && Overlays[i].layerTransform.parent == this.transform)
                            {
                                isHeadLocked = true;
                            }

                            // external surface
                            if (Overlays[i].isExternalAndroidSurface)
                            {
                                layerFlags = 1;
                                this.CreateExternalSurface(Overlays[i], overlayLayerDepth);
                            }

                            Pvr_UnitySDKAPI.Render.UPvr_SetOverlayModelViewMatrix((int)Overlays[i].overlayType, (int)Overlays[i].overlayShape, Overlays[i].layerTextureIds[0], (int)Pvr_UnitySDKAPI.Eye.LeftEye, overlayLayerDepth, isHeadLocked, layerFlags, Overlays[i].MVMatrixs[0],
                                                                                  Overlays[i].ModelScales[0], Overlays[i].ModelRotations[0], Overlays[i].ModelTranslations[0], Overlays[i].CameraRotations[0], Overlays[i].CameraTranslations[0], Overlays[i].GetLayerColorScale(), Overlays[i].GetLayerColorOffset());

                            Pvr_UnitySDKAPI.Render.UPvr_SetOverlayModelViewMatrix((int)Overlays[i].overlayType, (int)Overlays[i].overlayShape, Overlays[i].layerTextureIds[1], (int)Pvr_UnitySDKAPI.Eye.RightEye, overlayLayerDepth, isHeadLocked, layerFlags, Overlays[i].MVMatrixs[1],
                                                                                  Overlays[i].ModelScales[1], Overlays[i].ModelRotations[1], Overlays[i].ModelTranslations[1], Overlays[i].CameraRotations[1], Overlays[i].CameraTranslations[1], Overlays[i].GetLayerColorScale(), Overlays[i].GetLayerColorOffset());

                            overlayLayerDepth++;
                        }
                        else if (Overlays[i].overlayType == Pvr_UnitySDKEyeOverlay.OverlayType.Underlay)
                        {
                            // external surface
                            if (Overlays[i].isExternalAndroidSurface)
                            {
                                layerFlags = 1;
                                this.CreateExternalSurface(Overlays[i], underlayLayerDepth);
                            }

                            Pvr_UnitySDKAPI.Render.UPvr_SetOverlayModelViewMatrix((int)Overlays[i].overlayType, (int)Overlays[i].overlayShape, Overlays[i].layerTextureIds[0], (int)Pvr_UnitySDKAPI.Eye.LeftEye, underlayLayerDepth, false, layerFlags, Overlays[i].MVMatrixs[0],
                                                                                  Overlays[i].ModelScales[0], Overlays[i].ModelRotations[0], Overlays[i].ModelTranslations[0], Overlays[i].CameraRotations[0], Overlays[i].CameraTranslations[0], Overlays[i].GetLayerColorScale(), Overlays[i].GetLayerColorOffset());

                            Pvr_UnitySDKAPI.Render.UPvr_SetOverlayModelViewMatrix((int)Overlays[i].overlayType, (int)Overlays[i].overlayShape, Overlays[i].layerTextureIds[1], (int)Pvr_UnitySDKAPI.Eye.RightEye, underlayLayerDepth, false, layerFlags, Overlays[i].MVMatrixs[1],
                                                                                  Overlays[i].ModelScales[1], Overlays[i].ModelRotations[1], Overlays[i].ModelTranslations[1], Overlays[i].CameraRotations[1], Overlays[i].CameraTranslations[1], Overlays[i].GetLayerColorScale(), Overlays[i].GetLayerColorOffset());

                            underlayLayerDepth++;
                        }
                    }
                    else if (Overlays[i].overlayShape == Pvr_UnitySDKEyeOverlay.OverlayShape.Equirect)
                    {
                        // external surface
                        if (Overlays[i].isExternalAndroidSurface)
                        {
                            layerFlags = 1;
                            this.CreateExternalSurface(Overlays[i], 0);
                        }

                        // 360 Overlay Equirectangular Texture
                        Pvr_UnitySDKAPI.Render.UPvr_SetupLayerData(0, (int)Pvr_UnitySDKAPI.Eye.LeftEye, Overlays[i].layerTextureIds[0], (int)Overlays[i].overlayShape, layerFlags, Overlays[i].GetLayerColorScale(), Overlays[i].GetLayerColorOffset());
                        Pvr_UnitySDKAPI.Render.UPvr_SetupLayerData(0, (int)Pvr_UnitySDKAPI.Eye.RightEye, Overlays[i].layerTextureIds[1], (int)Overlays[i].overlayShape, layerFlags, Overlays[i].GetLayerColorScale(), Overlays[i].GetLayerColorOffset());
                    }
                }
                #endregion
            }

            // Begin TimeWarp
            //Pvr_UnitySDKPluginEvent.IssueWithData(RenderEventType.TimeWarp, Pvr_UnitySDKManager.SDK.RenderviewNumber);
            Pvr_UnitySDKAPI.System.UPvr_UnityEventData(Pvr_UnitySDKAPI.System.UPvr_GetEyeBufferData(0));
            Pvr_UnitySDKPluginEvent.Issue(RenderEventType.TimeWarp);
            Pvr_UnitySDKManager.SDK.currEyeTextureIdx = Pvr_UnitySDKManager.SDK.nextEyeTextureIdx;
            Pvr_UnitySDKManager.SDK.nextEyeTextureIdx = (Pvr_UnitySDKManager.SDK.nextEyeTextureIdx + 1) % 3;
        }
    }
Beispiel #2
0
    void Update()
    {
        // boundary
        if (eyecamera != null && eyecamera.enabled)
        {
            int currentBoundaryState = BoundarySystem.UPvr_GetSeeThroughState();

            if (currentBoundaryState != this.lastBoundaryState)
            {
                if (currentBoundaryState == 2) // close camera render(close camera render) and limit framerate(if needed)
                {
                    // record
                    eyeCameraOriginCullingMask     = eyecamera.cullingMask;
                    eyeCameraOriginClearFlag       = eyecamera.clearFlags;
                    eyeCameraOriginBackgroundColor = eyecamera.backgroundColor;

                    // close render
                    eyecamera.cullingMask     = 0;
                    eyecamera.clearFlags      = CameraClearFlags.SolidColor;
                    eyecamera.backgroundColor = Color.black;
                }
                else if (currentBoundaryState == 1) // open camera render, but limit framerate(if needed)
                {
                    if (this.lastBoundaryState == 2)
                    {
                        if (eyecamera.cullingMask == 0)
                        {
                            eyecamera.cullingMask = eyeCameraOriginCullingMask;
                        }
                        if (eyecamera.clearFlags == CameraClearFlags.SolidColor)
                        {
                            eyecamera.clearFlags = eyeCameraOriginClearFlag;
                        }
                        if (eyecamera.backgroundColor == Color.black)
                        {
                            eyecamera.backgroundColor = eyeCameraOriginBackgroundColor;
                        }
                    }
                }
                else // open camera render(recover)
                {
                    if ((this.lastBoundaryState == 2 || this.lastBoundaryState == 1))
                    {
                        if (eyecamera.cullingMask == 0)
                        {
                            eyecamera.cullingMask = eyeCameraOriginCullingMask;
                        }
                        if (eyecamera.clearFlags == CameraClearFlags.SolidColor)
                        {
                            eyecamera.clearFlags = eyeCameraOriginClearFlag;
                        }
                        if (eyecamera.backgroundColor == Color.black)
                        {
                            eyecamera.backgroundColor = eyeCameraOriginBackgroundColor;
                        }
                    }
                }

                this.lastBoundaryState = currentBoundaryState;
            }
        }
    }
Beispiel #3
0
    void Update()
    {
        if (Pvr_UnitySDKManager.SDK.trackingmode == 2 || Pvr_UnitySDKManager.SDK.trackingmode == 3)
        {
#if ANDROID_DEVICE
            if (!Pvr_UnitySDKManager.SDK.HmdOnlyrot)
            {
                if (Pvr_UnitySDKManager.SDK.DefaultRange)
                {
                    if (Mathf.Sqrt(Mathf.Pow(Pvr_UnitySDKManager.SDK.HeadPose.Position.x, 2.0f) + Mathf.Pow(Pvr_UnitySDKManager.SDK.HeadPose.Position.z, 2.0f)) >= 0.8f)
                    {
                        isFading          = true;
                        fadeMaterialColor = new Color(0f, 0f, 0f,
                                                      Mathf.Clamp((Mathf.Max(Mathf.Abs(Pvr_UnitySDKManager.SDK.HeadPose.Position.x),
                                                                             Mathf.Abs(Pvr_UnitySDKManager.SDK.HeadPose.Position.z)) - 0.8f) /
                                                                  0.16f, 0f, 0.3f));
                    }
                    else
                    {
                        if (isFadeUsing)
                        {
                            if (elapsedTime >= fadeTime)
                            {
                                fadeMaterialColor = new Color(0f, 0f, 0f, 0f);
                                isFading          = false;
                            }
                        }
                        else
                        {
                            fadeMaterialColor = new Color(0f, 0f, 0f, 0f);
                            isFading          = false;
                        }
                    }
                }
                else
                {
                    if (Mathf.Sqrt(Mathf.Pow(Pvr_UnitySDKManager.SDK.HeadPose.Position.x, 2.0f) + Mathf.Pow(Pvr_UnitySDKManager.SDK.HeadPose.Position.z, 2.0f)) >= Pvr_UnitySDKManager.SDK.CustomRange)
                    {
                        isFading          = true;
                        fadeMaterialColor = new Color(0f, 0f, 0f,
                                                      Mathf.Clamp((Mathf.Max(Mathf.Abs(Pvr_UnitySDKManager.SDK.HeadPose.Position.x),
                                                                             Mathf.Abs(Pvr_UnitySDKManager.SDK.HeadPose.Position.z)) - Pvr_UnitySDKManager.SDK.CustomRange) /
                                                                  (Pvr_UnitySDKManager.SDK.CustomRange / 5f), 0f, 0.3f));
                    }
                    else
                    {
                        if (isFadeUsing)
                        {
                            if (elapsedTime >= fadeTime)
                            {
                                fadeMaterialColor = new Color(0f, 0f, 0f, 0f);
                                isFading          = false;
                            }
                        }
                        else
                        {
                            fadeMaterialColor = new Color(0f, 0f, 0f, 0f);
                            isFading          = false;
                        }
                    }
                }
                SetFadeMeshEnable();
            }
#endif
        }

        // boundary
        if (eyecamera != null && eyecamera.enabled)
        {
            int boundaryState = BoundarySystem.UPvr_GetSeeThroughState();
            if (boundaryState == 2)
            {
                // close camera render(close camera render)
                if (eyecamera.cullingMask != 0)
                {
                    eyecamera.cullingMask = 0;
                }

                if (eyecamera.clearFlags != CameraClearFlags.SolidColor)
                {
                    eyecamera.clearFlags      = CameraClearFlags.SolidColor;
                    eyecamera.backgroundColor = Color.black;
                }

                if (boundaryFrameRate)
                {
                    if (Application.targetFrameRate != 30)
                    {
                        Application.targetFrameRate = 30;
                    }
                }
            }
            else if (boundaryState == 1)
            {
                if (eyecamera.cullingMask != eyeCameraOriginCullingMask)
                {
                    eyecamera.cullingMask = eyeCameraOriginCullingMask;
                }

                if (eyecamera.clearFlags != eyeCameraOriginClearFlag)
                {
                    eyecamera.clearFlags      = eyeCameraOriginClearFlag;
                    eyecamera.backgroundColor = eyeCameraOriginBackgroundColor;
                }

                if (boundaryFrameRate)
                {
                    if (Application.targetFrameRate != 30)
                    {
                        Application.targetFrameRate = 30;
                    }
                }
            }
            else
            {
                // open camera render(recover)
                if (eyecamera.cullingMask != eyeCameraOriginCullingMask)
                {
                    eyecamera.cullingMask = eyeCameraOriginCullingMask;
                }

                if (eyecamera.clearFlags != eyeCameraOriginClearFlag)
                {
                    eyecamera.clearFlags      = eyeCameraOriginClearFlag;
                    eyecamera.backgroundColor = eyeCameraOriginBackgroundColor;
                }

                if (Application.targetFrameRate != applicationOriginFrameRate)
                {
                    Application.targetFrameRate = applicationOriginFrameRate;
                }
            }
        }
    }
Beispiel #4
0
    void Update()
    {
#if UNITY_EDITOR
        SetCameraEnableEditor();
#endif
        // boundary limit FPS
        if (isFrameRateLimitForBoundary)
        {
            int currentBoundaryState = BoundarySystem.UPvr_GetSeeThroughState();

            if (currentBoundaryState != this.lastBoundaryState)
            {
                if (currentBoundaryState == 2 || currentBoundaryState == 1) // limit framerate
                {
                    if (Application.targetFrameRate != this.limitTargetFrameRate)
                    {
                        // record
                        this.recordTargetFrameRate = Application.targetFrameRate;
                        // limit FPS
                        Application.targetFrameRate = this.limitTargetFrameRate;
                    }
                }
                else // recover
                {
                    Application.targetFrameRate = this.recordTargetFrameRate;
                }

                this.lastBoundaryState = currentBoundaryState;
            }
        }



        if (Pvr_UnitySDKRender.Instance.StereoRenderPath == StereoRenderingPathPico.SinglePass)
        {
            for (int i = 0; i < Eyes.Length; i++)
            {
                if (Eyes[i].isActiveAndEnabled && Eyes[i].eyeSide == Eye.BothEye)
                {
                    Eyes[i].EyeRender();
                }
            }
        }
        if (Pvr_UnitySDKRender.Instance.StereoRenderPath == StereoRenderingPathPico.MultiPass)
        {
            if (!Pvr_UnitySDKManager.SDK.Monoscopic)
            {
                // Open Stero Eye Render
                for (int i = 0; i < Eyes.Length; i++)
                {
                    if (Eyes[i].isActiveAndEnabled && Eyes[i].eyeSide != Eye.BothEye)
                    {
                        Eyes[i].EyeRender();
                    }
                }
            }
            else
            {
                // Open Mono Eye Render
                MonoEyeRender();
            }
        }
    }