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); }