Skip to content

Commit

Permalink
fix: some TMPro materials were not exported properly
Browse files Browse the repository at this point in the history
  • Loading branch information
hybridherbst committed Sep 30, 2022
1 parent 645af2a commit f4c5d95
Showing 1 changed file with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,19 @@ private static void CleanUpRenderTextureCache(GLTFSceneExporter _, GLTFRoot __)

private static bool BeforeMaterialExport(GLTFSceneExporter exporter, GLTFRoot gltfRoot, Material material, GLTFMaterial materialNode)
{
if (material.shader.name.Contains("TextMeshPro"))
if (material.shader.name.Contains("TextMeshPro")) // seems to only work for TextMeshPro/Mobile/ right now (SDFAA_HINTED?)
{
var s = material.shader;
// TODO figure out how to properly use the non-mobile shaders
var newS = Shader.Find("TestMeshPro/Mobile/Distance Field");
#if UNITY_EDITOR
if (!newS)
{
newS = UnityEditor.AssetDatabase.LoadAssetAtPath<Shader>(UnityEditor.AssetDatabase.GUIDToAssetPath("fe393ace9b354375a9cb14cdbbc28be4")); // same as above
}
#endif
material.shader = newS;

if (!tempMat) tempMat = new Material(Shader.Find("Unlit/Transparent Cutout"));

var existingTex = material.mainTexture;
Expand All @@ -42,6 +53,7 @@ private static bool BeforeMaterialExport(GLTFSceneExporter exporter, GLTFRoot gl
var rt = new RenderTexture(existingTex.width, existingTex.height, 0, RenderTextureFormat.ARGB32);
if (material.HasProperty("_OutlineSoftness"))
material.SetFloat("_OutlineSoftness", 0);
// TODO figure out how to get this more smooth
Graphics.Blit(existingTex, rt, material);
rtCache[existingTex] = rt;
rt.anisoLevel = 9;
Expand All @@ -50,6 +62,7 @@ private static bool BeforeMaterialExport(GLTFSceneExporter exporter, GLTFRoot gl

tempMat.mainTexture = rtCache[existingTex];


exporter.ExportUnlit(materialNode, tempMat);

// export material
Expand All @@ -58,6 +71,11 @@ private static bool BeforeMaterialExport(GLTFSceneExporter exporter, GLTFRoot gl
materialNode.PbrMetallicRoughness.BaseColorFactor = Color.white.ToNumericsColorLinear();
materialNode.AlphaMode = AlphaMode.BLEND;

material.shader = s;
#if UNITY_EDITOR
UnityEditor.EditorUtility.ClearDirty(material);
#endif

return true;
}

Expand Down

0 comments on commit f4c5d95

Please sign in to comment.