Ejemplo n.º 1
0
    /*************************************  Unity API ****************************************/
    #region Application EVENT

    void Awake()
    {
        if (!VrUtility.IsPicoVR)
        {
            return;
        }

        if (sdk == null)
        {
            sdk = this;
        }
        if (sdk != this)
        {
            Debug.LogWarning("SDK object should be a singleton.");
            enabled = false;
            return;
        }
        string     FPSname = "PicoVR/Head/FPS";
        GameObject FPS     = GameObject.Find(FPSname);

        FPS.SetActive(showFPS);
        InitDevice();
        picoVRProfile = PicoVRConfigProfile.Default.Clone();
        inPicovr      = false;
        newInPicovr   = true;
        eyeFov        = 90.0f;
        headPose      = new PicoVRPose(Matrix4x4.identity);
        //CheckStereoRender();
        AddPrePostRenderStages();
    }
Ejemplo n.º 2
0
    /// <summary>
    /// 设置相关参数
    /// </summary>
    private void Setup()
    {
        if (controller == null)
        {
            return;
        }
#if UNITY_EDITOR
        if (PicoVRManager.SDK.IsVREditorDebug)
        {
            transform.localPosition = PicoVRManager.SDK.EyeOffset(eye);
            camera.aspect           = 1.0f;
            Rect rect = new Rect(0, 0, 1, 1);
            camera.fieldOfView = PicoVRManager.SDK.eyeFov;
            camera.rect        = rect;
        }
        else
        {
            var monoCamera = controller.GetComponent <Camera>();

            Matrix4x4 proj = PicoVRManager.SDK.Projection(eye);

            CopyCameraAndMakeSideBySide(controller, proj[0, 2], proj[1, 2]);

            float lerp = Mathf.Clamp01(controller.matchByZoom) * Mathf.Clamp01(controller.matchMonoFOV);

            float monoProj11 = monoCamera.projectionMatrix[1, 1];
            float zoom       = 1;
            if (proj[1, 1] != 0 && monoProj11 != 0 && proj[1, 1] != 0)
            {
                zoom = 1 / Mathf.Lerp(1 / proj[1, 1], 1 / monoProj11, lerp) / proj[1, 1];
            }
            proj[0, 0] *= zoom;
            proj[1, 1] *= zoom;

            float ipdScale;
            float eyeOffset;
            controller.ComputeStereoAdjustment(proj[1, 1], transform.lossyScale.z,
                                               out ipdScale, out eyeOffset);

            transform.localPosition = ipdScale * PicoVRManager.SDK.EyeOffset(eye) +
                                      eyeOffset * Vector3.forward;


            // Set up the eye's projection.
            float near = monoCamera.nearClipPlane;
            float far  = monoCamera.farClipPlane;
            FixProjection(ref proj, near, far, ipdScale);
            camera.projectionMatrix = proj;

            if (Application.isEditor)
            {
                camera.fieldOfView = 2 * Mathf.Atan(1 / proj[1, 1]) * Mathf.Rad2Deg;
                Matrix4x4 realProj = PicoVRManager.SDK.UndistortedProjection(eye);
                FixProjection(ref realProj, near, far, ipdScale);

                Vector4 projvec = new Vector4(proj[0, 0] / zoom, proj[1, 1] / zoom,
                                              proj[0, 2] - 1, proj[1, 2] - 1) / 2;
                Vector4 unprojvec = new Vector4(realProj[0, 0], realProj[1, 1],
                                                realProj[0, 2] - 1, realProj[1, 2] - 1) / 2;
                Shader.SetGlobalVector("_Projection", projvec);
                Shader.SetGlobalVector("_Unprojection", unprojvec);
                PicoVRConfigProfile p = PicoVRManager.SDK.picoVRProfile;

                float distortionFactor = 0.0241425f;
                Shader.SetGlobalVector("_Distortion1",
                                       new Vector4(p.device.devDistortion.k1, p.device.devDistortion.k2, p.device.devDistortion.k3, distortionFactor));
                Shader.SetGlobalVector("_Distortion2",
                                       new Vector4(p.device.devDistortion.k4, p.device.devDistortion.k5, p.device.devDistortion.k6));
            }

            if (controller.StereoScreen == null)
            {
                Rect rect = camera.rect;

                if (Application.isEditor)
                {
                    Rect view = PicoVRManager.SDK.EyeRect(eye);
                    if (eye == PicoVRManager.Eye.RightEye)
                    {
                        rect.x -= 0.5f;
                    }
                    rect.width  *= 2 * view.width;
                    rect.x       = view.x + 2 * rect.x * view.width;
                    rect.height *= view.height;
                    rect.y       = view.y + rect.y * view.height;
                }
                camera.rect = rect;
            }
        }
#else
        // NOTE : Android && PC && IOS using the same setting !!!!!

        transform.localPosition = PicoVRManager.SDK.EyeOffset(eye);
        camera.aspect           = 1.0f;
        Rect rect = new Rect(0, 0, 1, 1);
        camera.fieldOfView = PicoVRManager.SDK.eyeFov;
        camera.rect        = rect;
#endif
    }