Skip to content

Commit

Permalink
Fix texture transform export for metallic roughness
Browse files Browse the repository at this point in the history
  • Loading branch information
marwie committed Jul 31, 2023
1 parent b026b3f commit 086739e
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ public MaterialId ExportMaterial(Material materialObj)
: Color.white).ToNumericsColorLinear(),
BaseColorTexture = mainTex ? ExportTextureInfo(mainTex, TextureMapType.BaseColor) : null
};
ExportTextureTransform(material.PbrMetallicRoughness.BaseColorTexture, materialObj, "_BaseMap");
}
else if (materialObj.HasProperty("_ColorTexture"))
{
Expand All @@ -294,6 +295,7 @@ public MaterialId ExportMaterial(Material materialObj)
: Color.white).ToNumericsColorLinear(),
BaseColorTexture = mainTex ? ExportTextureInfo(mainTex, TextureMapType.BaseColor) : null
};
ExportTextureTransform(material.PbrMetallicRoughness.BaseColorTexture, materialObj, "_ColorTexture");
}
else if (materialObj.HasProperty("_MainTex")) //else export main texture
{
Expand Down Expand Up @@ -391,6 +393,8 @@ private static bool CheckForPropertyInShader(Shader shader, string name, ShaderP

private void ExportTextureTransform(TextureInfo def, Material mat, string texName)
{
if (def == null) return;

// early out if texture transform is explicitly disabled
if (mat.HasProperty("_TEXTURE_TRANSFORM") && !mat.IsKeywordEnabled("_TEXTURE_TRANSFORM_ON"))
return;
Expand Down Expand Up @@ -677,6 +681,7 @@ public PbrMetallicRoughness ExportPBRMetallicRoughness(Material material)
if (mrTex)
{
pbr.MetallicRoughnessTexture = ExportTextureInfo(mrTex, TextureMapType.MetallicRoughness);
ExportTextureTransform(pbr.MetallicRoughnessTexture, material, "metallicRoughnessTexture");
}
}
else if (material.HasProperty("_MetallicRoughnessTexture"))
Expand All @@ -685,6 +690,7 @@ public PbrMetallicRoughness ExportPBRMetallicRoughness(Material material)
if (mrTex)
{
pbr.MetallicRoughnessTexture = ExportTextureInfo(mrTex, TextureMapType.MetallicRoughness);
ExportTextureTransform(pbr.MetallicRoughnessTexture, material, "_MetallicRoughnessTexture");
}
}
else if (material.HasProperty("_MetallicGlossMap"))
Expand Down

0 comments on commit 086739e

Please sign in to comment.