/// <summary>
        /// Registers an LOD to the prototype. LODs contain the renderers for instance prototypes,
        /// so even if no LOD is being used, the prototype must be registered as LOD0 using this method.
        /// </summary>
        /// <param name="screenRelativeTransitionHeight">if not defined, will default to 0</param>
        public void AddLod(float screenRelativeTransitionHeight = -1, bool excludeBounds = false)
        {
            if (instanceLODs == null)
            {
                instanceLODs = new List <GPUInstancerPrototypeLOD>();
            }

            GPUInstancerPrototypeLOD instanceLOD = new GPUInstancerPrototypeLOD();

            instanceLOD.excludeBounds = excludeBounds;
            instanceLODs.Add(instanceLOD);

            // Ensure the LOD will render if this is the first LOD and lodDistance is not set.
            if (instanceLODs.Count == 1 && screenRelativeTransitionHeight < 0f)
            {
                lodSizes[0] = 0;
            }

            // Do not modify the lodDistances vector if LOD distance is not supplied.
            if (screenRelativeTransitionHeight < 0f)
            {
                return;
            }

            float lodSize = (screenRelativeTransitionHeight / (prototype != null && prototype.lodBiasAdjustment > 0 ? prototype.lodBiasAdjustment : 1)) / QualitySettings.lodBias;

            if (instanceLODs.Count < 5)
            {
                lodSizes[(instanceLODs.Count - 1) * 4] = lodSize;
            }
            else
            {
                lodSizes[(instanceLODs.Count - 5) * 4 + 1] = lodSize;
            }

            if (prototype.isLODCrossFade)
            {
#if !UNITY_EDITOR && UNITY_ANDROID
                prototype.isLODCrossFade = false;
#else
                if (!prototype.isLODCrossFadeAnimate)
                {
                    float previousLodSize = 1;
                    if (instanceLODs.Count > 1)
                    {
                        if (instanceLODs.Count < 5)
                        {
                            previousLodSize = lodSizes[(instanceLODs.Count - 2) * 4];
                        }
                        else if (instanceLODs.Count == 5)
                        {
                            previousLodSize = lodSizes[12];
                        }
                        else
                        {
                            previousLodSize = lodSizes[(instanceLODs.Count - 6) * 4];
                        }
                    }
                    float dif    = previousLodSize - lodSize;
                    float cfSize = lodSize + dif * prototype.lodFadeTransitionWidth;

                    if (instanceLODs.Count < 5)
                    {
                        lodCFSizes[(instanceLODs.Count - 1) * 4] = cfSize;
                    }
                    else
                    {
                        lodCFSizes[(instanceLODs.Count - 5) * 4 + 1] = cfSize;
                    }
                }
#endif
            }
        }
Exemple #2
0
        /// <summary>
        /// Registers an LOD to the prototype. LODs contain the renderers for instance prototypes,
        /// so even if no LOD is being used, the prototype must be registered as LOD0 using this method.
        /// </summary>
        /// <param name="screenRelativeTransitionHeight">if not defined, will default to 0</param>
        public virtual void AddLod(float screenRelativeTransitionHeight = -1, bool excludeBounds = false)
        {
            if (instanceLODs == null)
            {
                instanceLODs = new List <GPUInstancerPrototypeLOD>();
            }

            GPUInstancerPrototypeLOD instanceLOD = new GPUInstancerPrototypeLOD();

            instanceLOD.excludeBounds = excludeBounds;
            instanceLODs.Add(instanceLOD);

            // Ensure the LOD will render if this is the first LOD and lodDistance is not set.
            if (instanceLODs.Count == 1 && screenRelativeTransitionHeight < 0f)
            {
                lodSizes[0] = 0;
            }

            // Do not modify the lodDistances vector if LOD distance is not supplied.
            if (screenRelativeTransitionHeight < 0f)
            {
                return;
            }

            if (lodBiasApplied == -1)
            {
                lodBiasApplied = QualitySettings.lodBias;
            }

            int lodIndex = (instanceLODs.Count - 1) * 4;

            if (instanceLODs.Count > 4)
            {
                lodIndex = (instanceLODs.Count - 5) * 4 + 1;
            }

            float lodSize = (screenRelativeTransitionHeight / (prototype != null && prototype.lodBiasAdjustment > 0 ? prototype.lodBiasAdjustment : 1)) / lodBiasApplied;

            lodSizes[lodIndex] = lodSize;

            if (GPUInstancerUtility.matrixHandlingType != GPUIMatrixHandlingType.Default)
            {
                prototype.isLODCrossFade = false;
            }

            if (prototype.isLODCrossFade)
            {
                if (!prototype.isLODCrossFadeAnimate)
                {
                    float previousLodSize = 1;
                    if (instanceLODs.Count > 1)
                    {
                        if (instanceLODs.Count < 5)
                        {
                            previousLodSize = lodSizes[(instanceLODs.Count - 2) * 4];
                        }
                        else if (instanceLODs.Count == 5)
                        {
                            previousLodSize = lodSizes[12];
                        }
                        else
                        {
                            previousLodSize = lodSizes[(instanceLODs.Count - 6) * 4];
                        }
                    }
                    float dif    = previousLodSize - lodSize;
                    float cfSize = lodSize + dif * prototype.lodFadeTransitionWidth;

                    lodSizes[lodIndex + 2] = cfSize;
                }
            }
        }