Пример #1
0
        void Start()
        {
            if (m_TableSize < 1 || (m_TableSize & m_TableSize - 1) != 0)
            {
                m_TableSize = 64;
            }
            quadRootKey = getKey(0, 0, MaxMipLevel);

            m_LookupTexture            = new Texture2D(TableSize, TableSize, TextureFormat.RGBA32, false);
            m_LookupTexture.wrapMode   = TextureWrapMode.Clamp;
            m_LookupTexture.filterMode = FilterMode.Point;

            Shader.SetGlobalTexture("_LOOKUPTEX", m_LookupTexture);
            Shader.SetGlobalFloat("_MAXMIP", MaxMipLevel);
            Shader.SetGlobalFloat("_PAGETABLESIZE", TableSize);
            Shader.SetGlobalInt("_DEBUG", m_DebugMode);

            tileGenerator = (TileGeneration)GetComponent(typeof(TileGeneration));
            physicalTiles = (PhysicalTexture)GetComponent(typeof(PhysicalTexture));
            feedBack      = (Feedback)GetComponent(typeof(Feedback));

            AddressMapping = new Dictionary <int, PhysicalTileInfo>();
            ChildList      = new Dictionary <int, int[]>();

            feedBack.OnFeedbackReadComplete += ProcessFeedbackCoroutine;
            InCoroutine = false;
            //tileGenerator.OnTileGenerationComplete += OnGenerationComplete;
            tileGenerator.OnTileGenerationComplete += OnGenerationCompletePointer;
            //FOR POINTER
            quadRoot = new TableNode(MaxMipLevel, 0, 0, TableSize, TableSize);
            m_Pages  = new Dictionary <int, TableNode>();

            //multiple quad trees
            quadRoots = new TableNode[m_TerrainDivision * m_TerrainDivision];

            /*for(int i = 0; i < m_TerrainDivision; i++)
             * {
             *  for (int j = 0; j < m_TerrainDivision; j++) {
             *      //quadRoots[i] = new TableNode(MaxMipLevel, i )
             *  }
             * }*/
        }
Пример #2
0
        public LruCache(int maxMip, int physicalSizeX, int physicalSizeY, PhysicalTexture physical, PageTable table)
        {
            m_MipEnd = new LinkedListNode <int> [maxMip + 1];

            m_NumMip = new int[maxMip + 1];
            for (int i = 0; i < maxMip + 1; i++)
            {
                m_NumMip[i] = 0;
            }
            m_PhysicalSize = new Vector2Int(physicalSizeX, physicalSizeY);
            m_IdToMip      = new int[physicalSizeX * physicalSizeY];
            for (int i = 0; i < physicalSizeX * physicalSizeY; i++)
            {
                Add(i);
            }
            //将mip 0 list的结尾放到list 的最后,其他mip list 结尾暂时为null
            m_MipEnd[0] = m_List.Last;

            physicalTexture = physical;
            pageTable       = table;
        }
Пример #3
0
        void Start()
        {
            TilesToGenerate  = new List <int>();
            TileGeneratorMat = new Material(TileGenerator);
            TileGeneratorMat.SetShaderPassEnabled("Always", false);
            LayerCount = DemoTerrain.terrainData.terrainLayers.Length;

            physicalTexture = (PhysicalTexture)GetComponent(typeof(PhysicalTexture));
            pageTable       = (PageTable)GetComponent(typeof(PageTable));

            m_TilePool = new LruCache(pageTable.MaxMipLevel, physicalTexture.PhysicalTextureSize.x, physicalTexture.PhysicalTextureSize.y, physicalTexture, pageTable);


            //TODO 更好的texture存储方式??
            TileGeneratorMat.SetTexture("_AlphaMap", DemoTerrain.terrainData.alphamapTextures[0]);

            Vector4[] tileInfo = new Vector4[4];

            for (int i = 0; i < LayerCount && i < 4; i++)
            {
                TerrainLayer currLayer = DemoTerrain.terrainData.terrainLayers[i];

                currLayer.diffuseTexture.wrapMode     = TextureWrapMode.Repeat;
                currLayer.normalMapTexture.wrapMode   = TextureWrapMode.Repeat;
                currLayer.diffuseTexture.filterMode   = FilterMode.Bilinear;
                currLayer.normalMapTexture.filterMode = FilterMode.Bilinear;
                TileGeneratorMat.SetTexture("_Diffuse" + i, currLayer.diffuseTexture);
                TileGeneratorMat.SetTexture("_Normal" + i, currLayer.normalMapTexture);
                tileInfo[i].x = currLayer.tileSize.x;
                tileInfo[i].y = currLayer.tileSize.y;
                tileInfo[i].w = currLayer.tileOffset.x;
                tileInfo[i].z = currLayer.tileOffset.y;
            }


            TileGeneratorMat.SetVector("_TerrainSize", DemoTerrain.terrainData.size);
            TileGeneratorMat.SetVectorArray("_TileInfo", tileInfo);
        }