Skip to content

Commit

Permalink
fixes to ShaderGraph (URP) roundtrip for glTFast
Browse files Browse the repository at this point in the history
  • Loading branch information
hybridherbst committed Dec 20, 2021
1 parent 9c9953e commit 7556205
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions UnityGLTF/Assets/UnityGLTF/Runtime/Scripts/GLTFSceneExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1413,6 +1413,23 @@ private MaterialId ExportMaterial(Material materialObj)
}
}
}
if (materialObj.HasProperty("normalTexture"))
{
var normalTex = materialObj.GetTexture("normalTexture");

if (normalTex != null)
{
if(normalTex is Texture2D)
{
material.NormalTexture = ExportNormalTextureInfo(normalTex, TextureMapType.Bump, materialObj);
ExportTextureTransform(material.NormalTexture, materialObj, "_BumpMap");
}
else
{
Debug.LogErrorFormat("Can't export a {0} normal texture in material {1}", normalTex.GetType(), materialObj.name);
}
}
}

if (materialObj.HasProperty("_OcclusionMap"))
{
Expand Down Expand Up @@ -1651,7 +1668,7 @@ private void ExportBlendShapes(SkinnedMeshRenderer smr, Mesh meshObj, int submes

private bool IsPBRMetallicRoughness(Material material)
{
return material.HasProperty("_Metallic") && (material.HasProperty("_MetallicGlossMap") || material.HasProperty("_Glossiness"));
return material.HasProperty("_Metallic") && (material.HasProperty("_MetallicGlossMap") || material.HasProperty("_Glossiness") || material.HasProperty("metallicRoughnessTexture"));
}

private bool IsUnlit(Material material)
Expand Down Expand Up @@ -1822,7 +1839,7 @@ private PbrMetallicRoughness ExportPBRMetallicRoughness(Material material)
else if (material.HasProperty("_Glossiness") || material.HasProperty("_Smoothness"))
{
var smoothnessPropertyName = material.HasProperty("_Smoothness") ? "_Smoothness" : "_Glossiness";
var metallicGlossMap = material.GetTexture("_MetallicGlossMap");
var metallicGlossMap = material.HasProperty("_MetallicGlossMap") ? material.GetTexture("_MetallicGlossMap") : null;
float smoothness = material.GetFloat(smoothnessPropertyName);
// legacy workaround: the UnityGLTF shaders misuse "_Glossiness" as roughness but don't have a keyword for it.
if (isGltfPbrMetallicRoughnessShader)
Expand Down Expand Up @@ -1851,6 +1868,13 @@ private PbrMetallicRoughness ExportPBRMetallicRoughness(Material material)
}
}
}
else if (material.HasProperty("metallicRoughnessTexture"))
{
var mrTex = material.GetTexture("metallicRoughnessTexture");
if (mrTex && mrTex is Texture2D) {
pbr.MetallicRoughnessTexture = ExportTextureInfo(mrTex, TextureMapType.MetallicGloss_DontConvert);
}
}

return pbr;
}
Expand Down

0 comments on commit 7556205

Please sign in to comment.