/// <summary> /// Gets Unity Material from Daggerfall terrain tilemap texture. /// </summary> /// <param name="archive">Archive index.</param> /// <returns>Material or null.</returns> public Material GetTerrainTilesetMaterial(int archive) { // Ready check if (!IsReady) { return(null); } // Return from cache if present int key = MakeTextureKey((short)archive, (byte)0, (byte)0, TileMapKeyGroup); if (materialDict.ContainsKey(key)) { CachedMaterial cm = GetMaterialFromCache(key); if (cm.filterMode == MainFilterMode) { // Properties are the same return(cm.material); } else { // Properties don't match, remove material and reload materialDict.Remove(key); } } //// TODO: Attempt to load prebuilt atlas asset, otherwise create one in memory //Texture2D texture = TerrainAtlasBuilder.LoadTerrainAtlasTextureResource(archive, CreateTextureAssetResourcesPath); //if (texture == null) // Generate atlas // Not currently generating normals as very slow on such a large texture // and results are not very noticeable GetTextureResults results = textureReader.GetTerrainTilesetTexture(archive); results.albedoMap.filterMode = MainFilterMode; Shader shader = Shader.Find(_DaggerfallTilemapShaderName); Material material = new Material(shader); material.name = string.Format("TEXTURE.{0:000} [Tilemap]", archive); material.SetTexture("_TileAtlasTex", results.albedoMap); CachedMaterial newcm = new CachedMaterial() { key = key, keyGroup = TileMapKeyGroup, material = material, filterMode = MainFilterMode, }; materialDict.Add(key, newcm); return(material); }
/// <summary> /// Gets Unity Material from Daggerfall terrain tilemap texture. /// </summary> /// <param name="archive">Archive index.</param> /// <returns>Material or null.</returns> public Material GetTerrainTilesetMaterial(int archive) { // Ready check if (!IsReady) { return(null); } // Return from cache if present int key = MakeTextureKey((short)archive, (byte)0, (byte)0, TileMapKeyGroup); if (materialDict.ContainsKey(key)) { CachedMaterial cm = materialDict[key]; if (cm.filterMode == MainFilterMode) { // Properties are the same return(cm.material); } else { // Properties don't match, remove material and reload materialDict.Remove(key); } } //// TODO: Attempt to load prebuilt atlas asset, otherwise create one in memory //Texture2D texture = TerrainAtlasBuilder.LoadTerrainAtlasTextureResource(archive, CreateTextureAssetResourcesPath); //if (texture == null) Texture2D texture = textureReader.GetTerrainTilesetTexture(archive); texture.filterMode = MainFilterMode; Shader shader = Shader.Find(_DaggerfallTilemapShaderName); Material material = new Material(shader); material.name = string.Format("TEXTURE.{0:000} [Tilemap]", archive); material.mainTexture = texture; CachedMaterial newcm = new CachedMaterial() { key = key, keyGroup = TileMapKeyGroup, material = material, filterMode = MainFilterMode, }; materialDict.Add(key, newcm); return(material); }