/// <summary> /// /// </summary> /// <param name="prop"></param> /// <param name="smoothness">used only when converting MetallicRoughness maps</param> /// <returns></returns> public Texture2D ConvertTexture(string prop, float smoothnessOrRoughness = 1.0f) { var convertedTexture = Converts.FirstOrDefault(x => x.Key == prop); if (convertedTexture.Value != null) { return(convertedTexture.Value); } if (prop == "_BumpMap") { if (Application.isPlaying) { var converted = new NormalConverter().GetImportTexture(Texture); m_converts.Add(prop, converted); return(converted); } else { #if UNITY_EDITOR var textureAssetPath = AssetDatabase.GetAssetPath(Texture); if (!string.IsNullOrEmpty(textureAssetPath)) { TextureIO.MarkTextureAssetAsNormalMap(textureAssetPath); } else { Debug.LogWarningFormat("no asset for {0}", Texture); } #endif return(Texture); } } if (prop == "_MetallicGlossMap") { var converted = new MetallicRoughnessConverter(smoothnessOrRoughness).GetImportTexture(Texture); m_converts.Add(prop, converted); return(converted); } if (prop == "_OcclusionMap") { var converted = new OcclusionConverter().GetImportTexture(Texture); m_converts.Add(prop, converted); return(converted); } return(null); }
static void Export_Metallic(Material m, TextureExportManager textureManager, glTFMaterial material) { int index = -1; if (m.HasProperty("_MetallicGlossMap")) { float smoothness = 0.0f; if (m.HasProperty("_GlossMapScale")) { smoothness = m.GetFloat("_GlossMapScale"); } // Bake smoothness values into a texture. var converter = new MetallicRoughnessConverter(smoothness); index = textureManager.ConvertAndGetIndex(m.GetTexture("_MetallicGlossMap"), converter); if (index != -1) { material.pbrMetallicRoughness.metallicRoughnessTexture = new glTFMaterialMetallicRoughnessTextureInfo() { index = index, }; } } if (index != -1) { material.pbrMetallicRoughness.metallicFactor = 1.0f; // Set 1.0f as hard-coded. See: https://github.com/dwango/UniVRM/issues/212. material.pbrMetallicRoughness.roughnessFactor = 1.0f; } else { if (m.HasProperty("_Metallic")) { material.pbrMetallicRoughness.metallicFactor = m.GetFloat("_Metallic"); } if (m.HasProperty("_Glossiness")) { material.pbrMetallicRoughness.roughnessFactor = 1.0f - m.GetFloat("_Glossiness"); } } }