示例#1
0
        /// <summary>
        /// Creates the command buffer for single eye (left or right)
        /// </summary>
        private void createCommandBufferForSingleEye()
        {
            Camera eye = this.GetComponent <Camera>();

            //Setup orthographic view command buffer:
            float pScreenW, pScreenH;//physical screen width, height

            if (!PEUtils.GetPhysicalScreenSize(out pScreenW, out pScreenH))
            {
                throw new UnityException("Fail to get screen physical size");
            }
            //in case screen ori not correct
            if (pScreenH > pScreenW)
            {
                var t = pScreenH;
                pScreenH = pScreenW;
                pScreenW = t;
            }
//            Debug.LogFormat("Physical w/h: {0}/{1}", pScreenW, pScreenH);
            pScreenW /= 2;

            eye.orthographic = true;
            var phoneProfile = PhoneProfileContainer.GetCurrent();

            eye.orthographicSize = phoneProfile.OrthoRectSize;
            Matrix4x4 matrix_ortho_prj = eye.projectionMatrix;

            Matrix4x4 matrix_World2Cam = Matrix4x4.TRS(new Vector3(0, 0, 0), Quaternion.identity, new Vector3(1, 1, -1));

            if (m_CmdBuffer_SingleEye != null)
            {
                eye.RemoveCommandBuffer(CameraEvent.AfterImageEffects, m_CmdBuffer_SingleEye);
            }
            m_CmdBuffer_SingleEye = new CommandBuffer();
            m_CmdBuffer_SingleEye.SetViewProjectionMatrices(matrix_World2Cam, matrix_ortho_prj);
            m_CmdBuffer_SingleEye.ClearRenderTarget(clearDepth: true, clearColor: false, backgroundColor: Color.black);
            var undistortionRender   = undistortionRoot.transform.GetChild(0).GetComponent <MeshRenderer>();
            var undistortionBGRender = undistortionRoot.transform.GetChild(1).GetComponent <MeshRenderer>();

            m_CmdBuffer_SingleEye.DrawRenderer(undistortionBGRender, undistortionBGRender.sharedMaterial);//order does matter
            m_CmdBuffer_SingleEye.DrawRenderer(undistortionRender, undistortionRender.sharedMaterial);
            eye.AddCommandBuffer(CameraEvent.AfterImageEffects, m_CmdBuffer_SingleEye);


            //Setup rendering camera properties:
            ReflectionLenProfile lenProfile = ReflectionLenProfileContainer.GetLenProfile();
            var hFov = lenProfile.hFov;
            var vFov = lenProfile.vFov;

            eye.SetCameraFov(hFov, vFov);

            #region Alignment

            var projectionMatrix = eye.projectionMatrix;
            projectionMatrix[1, 1] = 1.23646257F;
            projectionMatrix[1, 2] = -0.0777916671F;
            eye.projectionMatrix   = projectionMatrix;

            #endregion
        }