|
|
|
|
|
|
|
|
|
|
// Metallic
|
|
|
|
bool hasMetallic = false; |
|
|
|
Texture metallicMap; |
|
|
|
Texture metallicMap = Texture2D.blackTexture; |
|
|
|
if (hasMetallic) metallicMap = TextureCombiner.GetTextureSafe(srcMaterial, "_MetallicGlossMap", Color.white); |
|
|
|
if (hasMetallic) |
|
|
|
{ |
|
|
|
metallicMap = TextureCombiner.GetTextureSafe(srcMaterial, "_MetallicGlossMap", Color.white); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
float metallicValue = Mathf.Pow(srcMaterial.GetFloat("_Metallic"), 2.2f); // Convert _Metallic value from Gamma to Linear
|
|
|
|
|
|
|
|
dstMaterial.SetFloat("_Metallic", metallicValue); |
|
|
|
metallicMap = TextureCombiner.TextureFromColor(Color.white * metallicValue); |
|
|
|
} |
|
|
|
else |
|
|
|
metallicMap = Texture2D.blackTexture; |
|
|
|
Texture occlusionMap; |
|
|
|
Texture occlusionMap = Texture2D.whiteTexture; |
|
|
|
Texture detailMaskMap; |
|
|
|
Texture detailMaskMap = Texture2D.whiteTexture; |
|
|
|
if (hasDetailMask) detailMaskMap = TextureCombiner.GetTextureSafe(srcMaterial, "_DetailMask", Color.white); |
|
|
|
|
|
|
|
// Smoothness
|
|
|
|
|
|
|
Texture2D maskMap; |
|
|
|
|
|
|
|
TextureCombiner maskMapCombiner = new TextureCombiner( |
|
|
|
TextureCombiner.GetTextureSafe(srcMaterial, "_MetallicGlossMap", Color.white), 4, // Metallic
|
|
|
|
TextureCombiner.GetTextureSafe(srcMaterial, "_OcclusionMap", Color.white), 4, // Occlusion
|
|
|
|
TextureCombiner.GetTextureSafe(srcMaterial, "_DetailMask", Color.white), 4, // Detail Mask
|
|
|
|
smoothnessMap, (srcMaterial.shader.name == Standard_Rough)?-4:3 // Smoothness Texture
|
|
|
|
metallicMap, 0, // R: Metallic from red
|
|
|
|
occlusionMap, 0, // G: Occlusion from red
|
|
|
|
detailMaskMap, 0, // B: Detail Mask from red
|
|
|
|
smoothnessMap, (srcMaterial.shader.name == Standard_Rough)?-4:3 // A: Smoothness Texture from inverse greyscale for roughness setup, or alpha
|
|
|
|
|
|
|
|
dstMaterial.SetFloat("_Metallic", 1f); // Force _Metallic value to 1, to use the value stored in the mask map without modification
|
|
|
|
|
|
|
|
string maskMapPath = AssetDatabase.GetAssetPath(srcMaterial); |
|
|
|
maskMapPath = maskMapPath.Remove(maskMapPath.Length-4) + "_MaskMap.png"; |
|
|
|