示例#1
0
        public void UpdateLod(List <int> activePassIds, MyLodStrategyPreprocessor preprocessor)
        {
            MyLodStrategyInfo lodStrategyInfo = StandardModel.GetLodStrategyInfo();
            Vector3D          cameraPos       = MyRender11.Environment.Matrices.CameraPosition;
            Vector3D          instancePos     = m_transformStrategy.GetCoreTranslation();

            m_lodStrategy.SmoothResolve(lodStrategyInfo, MyCommon.FrameCounter, MyCommon.LastFrameDelta(), cameraPos, instancePos, activePassIds, preprocessor);
        }
示例#2
0
 int GetTheBestLod(MyLodStrategyInfo strategyInfo, float distance)
 {
     for (int i = 0; i < strategyInfo.LodSwitchingDistances.Count; i++)
     {
         float lodDistance = strategyInfo.LodSwitchingDistances[i];
         if (lodDistance > distance)
         {
             return(i);
         }
     }
     return(strategyInfo.LodSwitchingDistances.Count);
 }
示例#3
0
        public void SetExplicitLodState(MyLodStrategyInfo strategyInfo, MyInstanceLodState state, float stateData)
        {
            m_explicitState     = state;
            m_explicitStateData = stateData;
            int maxLod = 0;

            if (!strategyInfo.IsEmpty)
            {
                maxLod = strategyInfo.GetLodsCount() - 1;
            }
            UpdateCachedResults(maxLod, m_allPassIds);
        }
示例#4
0
        int GetTheBestLodWithHisteresis(MyLodStrategyInfo strategyInfo, float distance, int currentLod)
        {
            for (int i = 0; i < strategyInfo.LodSwitchingDistances.Count; i++)
            {
                float offset = m_lodTransitionDistances[i] / 2;
                offset = currentLod > i ? -offset : +offset;

                float lodDistance = strategyInfo.LodSwitchingDistances[i] + offset;
                if (lodDistance > distance)
                {
                    return(i);
                }
            }
            return(strategyInfo.LodSwitchingDistances.Count);
        }
示例#5
0
        public void ResolveExplicit(MyLodStrategyInfo strategyInfo, ulong currentFrameId, int lodNum, List <int> activePassIds)
        {
            if (strategyInfo.IsEmpty)
            {
                return;
            }

            if (currentFrameId == m_updatedAtFrameId)
            {
                return;
            }

            int maxLod = strategyInfo.GetLodsCount() - 1;

            m_currentLod    = Math.Min(lodNum, maxLod);
            m_transitionLod = -1;
            m_transition    = 0;

            UpdateCachedResults(maxLod, activePassIds);
        }
示例#6
0
        public void SkippingResolve(MyLodStrategyInfo strategyInfo, ulong currentFrameId, Vector3D cameraPos, Vector3D instancePos, List <int> activePassIds, MyLodStrategyPreprocessor preprocessor)
        {
            if (strategyInfo.IsEmpty)
            {
                return;
            }

            float distance = (float)(cameraPos - instancePos).Length();

            distance *= preprocessor.DistanceMult;
            distance += m_objectDistanceAdd;
            distance *= m_objectDistanceMult;

            m_currentLod    = GetTheBestLod(strategyInfo, distance);
            m_transitionLod = -1;
            m_transition    = 0;

            m_updatedAtFrameId = currentFrameId;
            int maxLod = strategyInfo.GetLodsCount() - 1;

            UpdateCachedResults(maxLod, activePassIds);
        }
示例#7
0
        public void SmoothResolve(MyLodStrategyInfo strategyInfo, ulong currentFrameId, float timeDeltaSeconds, Vector3D cameraPos, Vector3D instancePos, List <int> activePassIds, MyLodStrategyPreprocessor preprocessor)
        {
            if (strategyInfo.IsEmpty)
            {
                return;
            }

            if (currentFrameId == m_updatedAtFrameId)
            {
                return;
            }

            float distance = (float)(cameraPos - instancePos).Length();

            distance *= preprocessor.DistanceMult;
            distance += m_objectDistanceAdd;
            distance *= m_objectDistanceMult;

            if (MISSING_FRAMES_TO_JUMP < currentFrameId - m_updatedAtFrameId) // the lod was not updated for a long time, we can jump to the lod
            {
                m_currentLod    = GetTheBestLod(strategyInfo, distance);
                m_transitionLod = -1;
                m_transition    = 0;
            }
            else
            {
                SmoothTransition(strategyInfo, timeDeltaSeconds, distance, ref m_currentLod, ref m_transitionLod, ref m_transition);
            }

            m_updatedAtFrameId = currentFrameId;
            int maxLod = strategyInfo.GetLodsCount() - 1;

            /*m_currentLod = strategyInfo.GetLodsCount() - 1;
             * m_transition = 0;*/

            UpdateCachedResults(maxLod, activePassIds);
        }
示例#8
0
        void SmoothTransition(MyLodStrategyInfo strategyInfo, float timeDeltaSeconds, float distance, ref int currentLod, ref int targetLod, ref float transition)
        {
            if (transition == 0) // the transition has not started
            {
                //Check the suitable lod
                targetLod = GetTheBestLodWithHisteresis(strategyInfo, distance, currentLod);

                //Lod is fine, therefore no transition
                if (currentLod == targetLod)
                {
                    targetLod = -1;
                    return;
                }

                //Lod is not found, init transition:
                m_transitionStartedAtDistance = distance;

                //And swap target and current lod
                int swappedLod = targetLod;
                targetLod  = currentLod;
                currentLod = swappedLod;
            }

            // The transition should start
            float deltaTransitionTime     = timeDeltaSeconds / MAX_TRANSITION_TIME_IN_SECS;
            float deltaTransitionDistance = Math.Abs(m_transitionStartedAtDistance - distance) / m_lodTransitionDistances[Math.Min(currentLod, targetLod)];
            float deltaTransition         = Math.Max(deltaTransitionDistance, deltaTransitionTime);

            deltaTransition = Math.Min(deltaTransition, MAX_TRANSITION_PER_FRAME);
            transition      = transition + deltaTransition;
            if (transition >= 1.0f)
            {
                transition = 0.0f;
                targetLod  = -1;
            }
        }
示例#9
0
        public void UpdateLodExplicit(List <int> activePassIds, int explicitLodNum)
        {
            MyLodStrategyInfo lodStrategyInfo = StandardModel.GetLodStrategyInfo();

            m_lodStrategy.ResolveExplicit(lodStrategyInfo, MyCommon.FrameCounter, explicitLodNum, activePassIds);
        }