public static void Update()
        {
            //use only for profiling
            /*
            long startTime;
            MyWindowsAPIWrapper.QueryPerformanceCounter(out startTime);
              */


            bool renderEnviromentMaps = MyRender.EnableLights && MyRender.Settings.EnableLightsRuntime && MyRender.Settings.EnableSun && (MyRender.Settings.EnableEnvironmentMapAmbient || MyRender.Settings.EnableEnvironmentMapReflection);

            if (!renderEnviromentMaps)
            {
                return;
            }

            if (BlendDistance > MainMapMaxDistance)
            {
                throw new InvalidOperationException("BlendDistance must be lower than MainMapMaxDistance");
            }

            MyRender.RenderOcclusionsImmediatelly = true;

            var cameraPos = MyRenderCamera.Position;

            if (MainMapPosition.HasValue && (cameraPos - MainMapPosition.Value).Length() > InstantRefreshDistance)
            {
                m_renderInstantly = true;
            }
            
            // Makes evironment camera pos 300m in front of real camera
            //cameraPos += Vector3.Normalize(MyCamera.ForwardVector) * 300

            if (MainMapPosition == null)
            {
                LastUpdateTime = 0;
                MainMapPosition = cameraPos;
                m_environmentMapRendererMain.StartUpdate(MainMapPosition.Value, m_renderInstantly);
                m_environmentMapRendererAux.StartUpdate(MainMapPosition.Value, m_renderInstantly);
                m_renderInstantly = false;

                BlendFactor = 0.0f;
            }
            else
            {
                var mainMapDistance = (MainMapPosition.Value - cameraPos).Length();

                // When behind blend distance
                if (mainMapDistance > BlendDistance)
                {
                    // Create AuxMap if not created
                    if (AuxMapPosition == null)
                    {
                        LastUpdateTime = 0;
                        AuxMapPosition = cameraPos;
                        m_environmentMapRendererAux.StartUpdate(AuxMapPosition.Value, m_renderInstantly);
                        m_renderInstantly = false;
                    }

                    // Wait till rendering done before blending
                    if (m_environmentMapRendererAux.IsDone())
                    {
                        // Set proper blend factor
                        BlendFactor = (float)(mainMapDistance - BlendDistance) / (MainMapMaxDistance - BlendDistance);
                    }
                }
                else if ((mainMapDistance + Hysteresis) < BlendDistance)
                {
                    AuxMapPosition = null;
                }

                // If MainMap should not be even displayed...swap aux and main and display
                if (mainMapDistance > MainMapMaxDistance && m_environmentMapRendererAux.IsDone())
                {
                    var tmp = m_environmentMapRendererAux;
                    m_environmentMapRendererAux = m_environmentMapRendererMain;
                    m_environmentMapRendererMain = tmp;
                    MainMapPosition = cameraPos + MyUtils.Normalize(MainMapPosition.Value - cameraPos) * BlendDistance;
                    AuxMapPosition = null;
                    BlendFactor = 0.0f;
                }
            }


            m_environmentMapRendererMain.ContinueUpdate();
            m_environmentMapRendererAux.ContinueUpdate();

            MyRender.RenderOcclusionsImmediatelly = false;

            /*
            long frq;
            MyWindowsAPIWrapper.QueryPerformanceFrequency(out frq);

            long stopTime;
            MyWindowsAPIWrapper.QueryPerformanceCounter(out stopTime);

            float updateTime = ((float)(stopTime - startTime)) / frq * 1000.0f;
            if(updateTime > LastUpdateTime)
            {
                LastUpdateTime = updateTime;
            }
             * */
        }
Beispiel #2
0
        public static void Update()
        {
            //use only for profiling

            /*
             * long startTime;
             * MyWindowsAPIWrapper.QueryPerformanceCounter(out startTime);
             */


            bool renderEnviromentMaps = MyRender.EnableLights && MyRender.Settings.EnableLightsRuntime && MyRender.Settings.EnableSun && (MyRender.Settings.EnableEnvironmentMapAmbient || MyRender.Settings.EnableEnvironmentMapReflection);

            if (!renderEnviromentMaps)
            {
                return;
            }

            if (BlendDistance > MainMapMaxDistance)
            {
                throw new InvalidOperationException("BlendDistance must be lower than MainMapMaxDistance");
            }

            MyRender.RenderOcclusionsImmediatelly = true;

            var cameraPos = MyRenderCamera.Position;

            if (MainMapPosition.HasValue && (cameraPos - MainMapPosition.Value).Length() > InstantRefreshDistance)
            {
                m_renderInstantly = true;
            }

            // Makes evironment camera pos 300m in front of real camera
            //cameraPos += Vector3.Normalize(MyCamera.ForwardVector) * 300

            if (MainMapPosition == null)
            {
                LastUpdateTime  = 0;
                MainMapPosition = cameraPos;
                m_environmentMapRendererMain.StartUpdate(MainMapPosition.Value, m_renderInstantly);
                m_environmentMapRendererAux.StartUpdate(MainMapPosition.Value, m_renderInstantly);
                m_renderInstantly = false;

                BlendFactor = 0.0f;
            }
            else
            {
                var mainMapDistance = (MainMapPosition.Value - cameraPos).Length();

                // When behind blend distance
                if (mainMapDistance > BlendDistance)
                {
                    // Create AuxMap if not created
                    if (AuxMapPosition == null)
                    {
                        LastUpdateTime = 0;
                        AuxMapPosition = cameraPos;
                        m_environmentMapRendererAux.StartUpdate(AuxMapPosition.Value, m_renderInstantly);
                        m_renderInstantly = false;
                    }

                    // Wait till rendering done before blending
                    if (m_environmentMapRendererAux.IsDone())
                    {
                        // Set proper blend factor
                        BlendFactor = (float)(mainMapDistance - BlendDistance) / (MainMapMaxDistance - BlendDistance);
                    }
                }
                else if ((mainMapDistance + Hysteresis) < BlendDistance)
                {
                    AuxMapPosition = null;
                }

                // If MainMap should not be even displayed...swap aux and main and display
                if (mainMapDistance > MainMapMaxDistance && m_environmentMapRendererAux.IsDone())
                {
                    var tmp = m_environmentMapRendererAux;
                    m_environmentMapRendererAux  = m_environmentMapRendererMain;
                    m_environmentMapRendererMain = tmp;
                    MainMapPosition = cameraPos + MyUtils.Normalize(MainMapPosition.Value - cameraPos) * BlendDistance;
                    AuxMapPosition  = null;
                    BlendFactor     = 0.0f;
                }
            }


            m_environmentMapRendererMain.ContinueUpdate();
            m_environmentMapRendererAux.ContinueUpdate();

            MyRender.RenderOcclusionsImmediatelly = false;

            /*
             * long frq;
             * MyWindowsAPIWrapper.QueryPerformanceFrequency(out frq);
             *
             * long stopTime;
             * MyWindowsAPIWrapper.QueryPerformanceCounter(out stopTime);
             *
             * float updateTime = ((float)(stopTime - startTime)) / frq * 1000.0f;
             * if(updateTime > LastUpdateTime)
             * {
             *  LastUpdateTime = updateTime;
             * }
             * */
        }