Material[] GetFadingMaterial(SceneResInfo res)
    {
        if (!GoablEnabledOcclusCulling)
        {
            return(null);
        }

        if (res.OcclusInstaneMaterial != null)
        {
            return(res.OcclusInstaneMaterial);
        }
        int matCount = res.OrginalMaterList.Length;

        Material[] rest = new Material[matCount];
        for (int i = 0; i < matCount; i++)
        {
            Queue <Material> matList = null;
            Material         orginal = res.OrginalMaterList[i];
            Material         result  = null;
            if (m_OcclusMaterialTable.TryGetValue(orginal, out matList))
            {
                if (matList.Count > 0)
                {
                    result = matList.Dequeue();
                }
                else
                {
                    result = SceneResInfo.CreateFadeingMaterial(orginal);
                }
            }
            else
            {
                result  = SceneResInfo.CreateFadeingMaterial(orginal);
                matList = new Queue <Material>();
                m_OcclusMaterialTable.Add(orginal, matList);
            }
            rest[i] = result;
        }
        res.OcclusInstaneMaterial = rest;
        return(rest);
    }
예제 #2
0
    /// <summary>
    /// 插入到batches,batches是以一个QuadTreeNode为单位
    /// </summary>
    /// <param name="parent"></param>
    void BuildBatches(QuadTreeNode parent)
    {
        //如果没存在淡入淡出
        if (!Batches_TreeNodeFadeTable.ContainsKey(parent))
        {
            Effect.SceneFadeInOutMaterialFloat m_FadeFloat = gameObject.AddComponent <Effect.SceneFadeInOutMaterialFloat>();
            m_FadeFloat.PropertyName = SceneResInfo.CutOutKeyWorld;
            m_FadeFloat.RegisterFinishEvent(OnBatchesFadingFinish);
            m_FadeFloat.FadeOutDuartion = FadeTime;
            m_FadeFloat.FadeOutFrom     = 1.0f;
            m_FadeFloat.FadeOutTo       = 0.0f;
            m_FadeFloat.FadeTimer       = m_FadeFloat.FadeOutFrom;
            m_FadeFloat.enabled         = false;


            List <Material>                 FadeInstanceList     = new List <Material>();
            Dictionary <Material, int>      matIndexTable        = new Dictionary <Material, int>();
            Dictionary <Material, Material> matFadeInstanceTable = new Dictionary <Material, Material>();
            foreach (QuadTreeLeaves m_Leaves in parent.m_LeavesList)
            {
                SceneResInfo res = m_Leaves.m_ResInfo;
                //回调,给到每个具体的类里,恢复原本的材质球
                m_FadeFloat.RegisterFinishEvent(res.OnFadeFinish);

                if (res.CheckSupportFading())
                {
                    Material[] shareds     = res.hostRender.sharedMaterials;
                    int        sharedCount = shareds.Length;
                    for (int i = 0; i < sharedCount; i++)
                    {
                        //如果这是一个全新的材质球,就新建一个,然后加入的实例链表里
                        if (!matIndexTable.ContainsKey(shareds[i]))
                        {
                            Material matFadeIn = SceneResInfo.CreateFadeingMaterial(shareds[i]);
                            FadeInstanceList.Add(matFadeIn);
                            matFadeInstanceTable.Add(shareds[i], matFadeIn);
                            matIndexTable.Add(shareds[i], FadeInstanceList.Count - 1);
                            res.BatchesIDs.Add(FadeInstanceList.Count - 1);
                        }
                        else
                        {
                            res.BatchesIDs.Add(matIndexTable[shareds[i]]);
                        }
                    }
                }
            }

            foreach (QuadTreeLeaves m_Leaves in parent.m_LeavesList)
            {
                SceneResInfo res = m_Leaves.m_ResInfo;
                res.Init(matFadeInstanceTable, SceneCamera);
            }

            parent.FadeMaterialList    = FadeInstanceList;
            parent.isDistanceFadingIn  = false;
            parent.isDistanceFadingIn  = false;
            parent.bOpmitizedRendering = true;
            InvBatches_TreeNodeFadeTable.Add(m_FadeFloat, parent);
            Batches_TreeNodeFadeTable.Add(parent, m_FadeFloat);
        }
    }