Beispiel #1
0
        void OnPreRender()
        {
            if (XRSettings.enabled)
            {
                switch (UnityEditor.PlayerSettings.stereoRenderingPath)
                {
                case UnityEditor.StereoRenderingPath.MultiPass:
                    renderMode = thisCamera.stereoActiveEye == Camera.MonoOrStereoscopicEye.Left ?
                                 RenderMode.RENDER_MODE_LEFT_EYE : RenderMode.RENDER_MODE_RIGHT_EYE;
                    break;

                case UnityEditor.StereoRenderingPath.SinglePass:
                    renderMode = RenderMode.RENDER_MODE_STEREO;
                    break;

                default:
                    renderMode = RenderMode.RENDER_MODE_MONO;
                    break;
                }
            }
            else
            {
                renderMode = RenderMode.RENDER_MODE_MONO;
            }

            ViveFoveatedRenderingAPI.SetRenderMode(renderMode);
        }
Beispiel #2
0
        public static bool SetParamByHMD(ViveFoveatedRendering vfr, bool isEyeTracked = false)
        {
            if (vfr == null)
            {
                return(false);
            }

            bool setParamSuccess = false;

            List <string> vids = new List <string>();
            List <string> pids = new List <string>();

            ViveFoveatedRenderingAPI.GetVidPid(str => vids.Add(str), str => pids.Add(str));

            for (int i = 0; i < vids.Count; i++)
            {
                if (vids[i] == VIVE_VID)
                {
                    if (pids[i] == VIVE_PRO_PID)
                    {
                        vfr.SetPatternPreset(ShadingPatternPreset.SHADING_PATTERN_CUSTOM);
                        vfr.SetRegionRadii(TargetArea.INNER, new Vector2(0.25f, 0.25f));
                        vfr.SetRegionRadii(TargetArea.MIDDLE, new Vector2(0.33f, 0.33f));
                        vfr.SetRegionRadii(TargetArea.PERIPHERAL, new Vector2(2.0f, 2.0f));

                        vfr.SetShadingRatePreset(ShadingRatePreset.SHADING_RATE_CUSTOM);
                        vfr.SetShadingRate(TargetArea.INNER, ShadingRate.X1_PER_PIXEL);
                        vfr.SetShadingRate(TargetArea.MIDDLE, ShadingRate.X1_PER_1X2_PIXELS);
                        vfr.SetShadingRate(TargetArea.PERIPHERAL, ShadingRate.X1_PER_2X2_PIXELS);

                        setParamSuccess = true;
                    }
                    else if (pids[i] == VIVE_COSMOS_PID)
                    {
                        vfr.SetPatternPreset(ShadingPatternPreset.SHADING_PATTERN_CUSTOM);
                        vfr.SetRegionRadii(TargetArea.INNER, new Vector2(0.33f, 0.33f));
                        vfr.SetRegionRadii(TargetArea.MIDDLE, new Vector2(0.6f, 0.6f));
                        vfr.SetRegionRadii(TargetArea.PERIPHERAL, new Vector2(2.0f, 2.0f));

                        vfr.SetShadingRatePreset(ShadingRatePreset.SHADING_RATE_CUSTOM);
                        vfr.SetShadingRate(TargetArea.INNER, ShadingRate.X1_PER_PIXEL);
                        vfr.SetShadingRate(TargetArea.MIDDLE, ShadingRate.X1_PER_1X2_PIXELS);
                        vfr.SetShadingRate(TargetArea.PERIPHERAL, ShadingRate.X1_PER_2X2_PIXELS);

                        setParamSuccess = true;
                    }
                }
            }

            return(setParamSuccess);
        }
Beispiel #3
0
        void Update()
        {
#if USE_SRANIPAL
            if (SRanipal_Eye_Framework.Status == SRanipal_Eye_Framework.FrameworkStatus.WORKING)
            {
                VerboseData data;
                if (SRanipal_Eye.GetVerboseData(out data) &&
                    data.left.GetValidity(SingleEyeDataValidity.SINGLE_EYE_DATA_GAZE_DIRECTION_VALIDITY) &&
                    data.right.GetValidity(SingleEyeDataValidity.SINGLE_EYE_DATA_GAZE_DIRECTION_VALIDITY)
                    )
                {
                    ViveFoveatedRenderingAPI.SetNormalizedGazeDirection(data.left.gaze_direction_normalized, data.right.gaze_direction_normalized);
                    GL.IssuePluginEvent(ViveFoveatedRenderingAPI.GetRenderEventFunc(), (int)EventID.UPDATE_GAZE);
                }
            }
#endif
        }
Beispiel #4
0
        public void SetPatternPreset(ShadingPatternPreset inputPreset)
        {
            if (foveatedRenderingInited)
            {
                patternPreset = inputPreset.Clamp(ShadingPatternPreset.SHADING_PATTERN_WIDE, ShadingPatternPreset.SHADING_PATTERN_MAX);
                ViveFoveatedRenderingAPI.SetFoveatedRenderingPatternPreset(patternPreset);

                if (patternPreset == ShadingPatternPreset.SHADING_PATTERN_CUSTOM)
                {
                    SetRegionRadii(TargetArea.INNER, innerRegionRadii);
                    SetRegionRadii(TargetArea.MIDDLE, middleRegionRadii);
                    SetRegionRadii(TargetArea.PERIPHERAL, peripheralRegionRadii);
                }

                GL.IssuePluginEvent(ViveFoveatedRenderingAPI.GetRenderEventFunc(), (int)EventID.UPDATE_GAZE);
            }
        }
Beispiel #5
0
        public void SetShadingRatePreset(ShadingRatePreset inputPreset)
        {
            if (foveatedRenderingInited)
            {
                shadingRatePreset = inputPreset.Clamp(ShadingRatePreset.SHADING_RATE_HIGHEST_PERFORMANCE, ShadingRatePreset.SHADING_RATE_MAX);
                ViveFoveatedRenderingAPI.SetFoveatedRenderingShadingRatePreset(shadingRatePreset);

                if (shadingRatePreset == ShadingRatePreset.SHADING_RATE_CUSTOM)
                {
                    SetShadingRate(TargetArea.INNER, innerShadingRate);
                    SetShadingRate(TargetArea.MIDDLE, middleShadingRate);
                    SetShadingRate(TargetArea.PERIPHERAL, peripheralShadingRate);
                }

                GL.IssuePluginEvent(ViveFoveatedRenderingAPI.GetRenderEventFunc(), (int)EventID.UPDATE_GAZE);
            }
        }
Beispiel #6
0
        void OnDisable()
        {
            EnableFoveatedRendering(false);
            commandBufferMgr.ClearCommands();

            ViveFoveatedRenderingAPI.ReleaseFoveatedRendering();
            ViveFoveatedRenderingAPI.ReleaseNativeLogger();

            foveatedRenderingInited = false;

            var gazeUpdater = GetComponent <ViveFoveatedGazeUpdater>();

            if (gazeUpdater != null)
            {
                gazeUpdater.enabled = false;
            }
        }
Beispiel #7
0
        void OnEnable()
        {
            ViveFoveatedRenderingAPI.InitializeNativeLogger(str => Debug.Log(str));

            thisCamera = GetComponent <Camera>();
            foveatedRenderingInited = ViveFoveatedRenderingAPI.InitializeFoveatedRendering(thisCamera.fieldOfView, thisCamera.aspect);
            if (foveatedRenderingInited)
            {
                var currentRenderingPath = thisCamera.actualRenderingPath;
                if (currentRenderingPath == RenderingPath.Forward)
                {
                    commandBufferMgr.AppendCommands("Enable Foveated Rendering", CameraEvent.BeforeForwardOpaque,
                                                    buf => buf.IssuePluginEvent(ViveFoveatedRenderingAPI.GetRenderEventFunc(), (int)EventID.ENABLE_FOVEATED_RENDERING),
                                                    buf => buf.ClearRenderTarget(false, true, Color.black));

                    commandBufferMgr.AppendCommands("Disable Foveated Rendering", CameraEvent.AfterForwardAlpha,
                                                    buf => buf.IssuePluginEvent(ViveFoveatedRenderingAPI.GetRenderEventFunc(), (int)EventID.DISABLE_FOVEATED_RENDERING));
                }
                else if (currentRenderingPath == RenderingPath.DeferredShading)
                {
                    commandBufferMgr.AppendCommands("Enable Foveated Rendering - GBuffer", CameraEvent.BeforeGBuffer,
                                                    buf => buf.IssuePluginEvent(ViveFoveatedRenderingAPI.GetRenderEventFunc(), (int)EventID.ENABLE_FOVEATED_RENDERING),
                                                    buf => buf.ClearRenderTarget(false, true, Color.black));

                    commandBufferMgr.AppendCommands("Disable Foveated Rendering - GBuffer", CameraEvent.AfterGBuffer,
                                                    buf => buf.IssuePluginEvent(ViveFoveatedRenderingAPI.GetRenderEventFunc(), (int)EventID.DISABLE_FOVEATED_RENDERING));

                    commandBufferMgr.AppendCommands("Enable Foveated Rendering - Alpha", CameraEvent.BeforeForwardAlpha,
                                                    buf => buf.IssuePluginEvent(ViveFoveatedRenderingAPI.GetRenderEventFunc(), (int)EventID.ENABLE_FOVEATED_RENDERING));

                    commandBufferMgr.AppendCommands("Disable Foveated Rendering - Alpha", CameraEvent.AfterForwardAlpha,
                                                    buf => buf.IssuePluginEvent(ViveFoveatedRenderingAPI.GetRenderEventFunc(), (int)EventID.DISABLE_FOVEATED_RENDERING));
                }

                EnableFoveatedRendering(true);
                bool isEyeTracked = ViveFoveatedGazeUpdater.AttachGazeUpdater(gameObject);
                if (manualAdjustment || (!ViveFoveatedInitParam.SetParamByHMD(this, isEyeTracked)))
                {
                    SetShadingRatePreset(shadingRatePreset);
                    SetPatternPreset(patternPreset);
                }

                ViveFoveatedRenderingAPI.SetNormalizedGazeDirection(new Vector3(0.0f, 0.0f, 1.0f), new Vector3(0.0f, 0.0f, 1.0f));
                GL.IssuePluginEvent(ViveFoveatedRenderingAPI.GetRenderEventFunc(), (int)EventID.UPDATE_GAZE);
            }
        }
Beispiel #8
0
        public void SetRegionRadii(TargetArea targetArea, Vector2 radii)
        {
            if (foveatedRenderingInited)
            {
                var clampedRadii = new Vector2(radii.x.Clamp(0.01f, 10.0f), radii.y.Clamp(0.01f, 10.0f));
                switch (targetArea)
                {
                case TargetArea.INNER:
                    innerRegionRadii = clampedRadii;
                    break;

                case TargetArea.MIDDLE:
                    middleRegionRadii = clampedRadii;
                    break;

                case TargetArea.PERIPHERAL:
                    peripheralRegionRadii = clampedRadii;
                    break;
                }

                ViveFoveatedRenderingAPI.SetRegionRadii(targetArea, clampedRadii);
                GL.IssuePluginEvent(ViveFoveatedRenderingAPI.GetRenderEventFunc(), (int)EventID.UPDATE_GAZE);
            }
        }
Beispiel #9
0
        public void SetShadingRate(TargetArea targetArea, ShadingRate rate)
        {
            if (foveatedRenderingInited)
            {
                var clampedRate = rate.Clamp(ShadingRate.CULL, ShadingRate.X1_PER_4X4_PIXELS);
                switch (targetArea)
                {
                case TargetArea.INNER:
                    innerShadingRate = clampedRate;
                    break;

                case TargetArea.MIDDLE:
                    middleShadingRate = clampedRate;
                    break;

                case TargetArea.PERIPHERAL:
                    peripheralShadingRate = clampedRate;
                    break;
                }

                ViveFoveatedRenderingAPI.SetShadingRate(targetArea, clampedRate);
                GL.IssuePluginEvent(ViveFoveatedRenderingAPI.GetRenderEventFunc(), (int)EventID.UPDATE_GAZE);
            }
        }