public static EyeProjectionMatrices CreateDefaultProjMatrices()
        {
            var eyeProjMatrices = new EyeProjectionMatrices();
            var aspect          = (float)SRD.Utils.SRDSettings.DeviceInfo.ScreenRect.Width / (float)SRD.Utils.SRDSettings.DeviceInfo.ScreenRect.Height;

            eyeProjMatrices.LeftMatrix  = Matrix4x4.Perspective(40f, aspect, 0.3f, 100f);
            eyeProjMatrices.RightMatrix = Matrix4x4.Perspective(40f, aspect, 0.3f, 100f);

            return(eyeProjMatrices);
        }
        public SrdXrResult GetCurrentProjMatrices(float nearClip, float farClip, out EyeProjectionMatrices projMatrices)
        {
            projMatrices = (_prevProjMatrix != null) ? _prevProjMatrix : SRDFaceTracker.CreateDefaultProjMatrices();

            var leftMatrix  = projMatrices.LeftMatrix;
            var rightMatrix = projMatrices.RightMatrix;
            var xrResult    = SRDCorePlugin.GetProjectionMatrix(SRDSessionHandler.SessionHandle, nearClip, farClip,
                                                                out leftMatrix, out rightMatrix);

            projMatrices = new EyeProjectionMatrices(leftMatrix, rightMatrix);
            if (xrResult == SrdXrResult.ERROR_HANDLE_INVALID || xrResult == SrdXrResult.ERROR_SESSION_NOT_RUNNING)
            {
                projMatrices = SRDFaceTracker.CreateDefaultProjMatrices();
            }
            _prevProjMatrix = projMatrices;
            return(xrResult);
        }
        public SrdXrResult GetCurrentProjMatrices(float nearClip, float farClip, out EyeProjectionMatrices projMatrices)
        {
            var posInDispCoord = _dispCenerCoordTposTrackCoord.MultiplyPoint3x4(_facePose.HeadPose.position);
            var maxAng         = 0f;

            foreach (var edge in Utils.SRDSettings.DeviceInfo.BodyBounds.EdgePositions)
            {
                var toEdge   = edge - posInDispCoord;
                var toCenter = Utils.SRDSettings.DeviceInfo.BodyBounds.Center - posInDispCoord;
                var ang      = Vector3.Angle(toCenter, toEdge);
                if (ang > maxAng)
                {
                    maxAng = ang;
                }
            }
            var projMat = Matrix4x4.Perspective(maxAng * 2.0f, 1f, nearClip, farClip);

            projMatrices = new EyeProjectionMatrices(projMat, projMat);
            return(SrdXrResult.SUCCESS);
        }
        public SRDEyeViewRenderer()
        {
            _eyeTransform = new Dictionary <EyeType, Transform>();
            _eyeCamera    = new Dictionary <EyeType, Camera>();
            //_eyeCamRenderTexture = new Dictionary<EyeType, RenderTexture>();
            _eyeCamRenderTextureCache = new Dictionary <EyeType, RenderTexture>();
            _eyeCamMaterial           = new Dictionary <EyeType, Material>();

            _eyeTypes = new List <EyeType>()
            {
                EyeType.Left, EyeType.Right
            };
            _isSRPUsed = (GraphicsSettings.renderPipelineAsset != null);

            _currentFacePose     = SRDFaceTracker.CreateDefaultFacePose();
            _currentProjMatrices = SRDFaceTracker.CreateDefaultProjMatrices();

            var width  = SRDSettings.DeviceInfo.ScreenRect.Width;
            var height = SRDSettings.DeviceInfo.ScreenRect.Height;

            foreach (var type in _eyeTypes)
            {
                // RenderTarget
                //var outrt = new RenderTexture(width, height, RenderTextureDepth, RenderTextureFormat.ARGB32);
                //outrt.name = SRDHelper.SRDConstants.EyeCamRenderTexDefaultName + SRDHelper.EyeSideName[type] + "_Temp";
                //outrt.Create();
                //_eyeCamRenderTexture.Add(type, outrt);
                var camrt = new RenderTexture(width, height, RenderTextureDepth, RenderTextureFormat.ARGB32,
                                              (QualitySettings.desiredColorSpace == ColorSpace.Linear) ? RenderTextureReadWrite.Linear : RenderTextureReadWrite.Default);
                camrt.name = SRDHelper.SRDConstants.EyeCamRenderTexDefaultName + SRDHelper.EyeSideName[type];
                camrt.Create();
                _eyeCamRenderTextureCache.Add(type, camrt);

                var homographyMaterial = new Material(Shader.Find("uHomography/Homography"));
                homographyMaterial.hideFlags = HideFlags.HideAndDontSave;
                _eyeCamMaterial[type]        = homographyMaterial;
            }
        }