Skip to content

Commit

Permalink
🐛 Fixed shader warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
AnotherFoxGuy committed Aug 24, 2023
1 parent d7fdc00 commit c55cf82
Showing 1 changed file with 24 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using System.Collections.Generic;
using System.IO;
using System.Globalization;
using System.Linq;
using Overte;

class AvatarExporter : MonoBehaviour
Expand Down Expand Up @@ -186,9 +187,11 @@ class AvatarExporter : MonoBehaviour
};

static readonly string STANDARD_SHADER = "Standard";
static readonly string STANDARD_ROUGHNESS_SHADER = "Autodesk Interactive"; // "Standard (Roughness setup)" Has been renamed in unity 2018.03
static readonly string STANDARD_SPECULAR_SHADER = "Standard (Specular setup)";
static readonly string[] SUPPORTED_SHADERS = new string[] {
STANDARD_SHADER,
STANDARD_ROUGHNESS_SHADER,
STANDARD_SPECULAR_SHADER,
};

Expand Down Expand Up @@ -266,7 +269,8 @@ static void UpdateAvatar()
[MenuItem("Overte/About")]
static void About()
{
EditorUtility.DisplayDialog("About", "Avatar Exporter\nVersion " + AVATAR_EXPORTER_VERSION + "\nCopyright 2022 to 2023 Overte e.V.\nCopyright 2018 High Fidelity, Inc.", "Ok");
EditorUtility.DisplayDialog("About",
$"Avatar Exporter\nVersion {AVATAR_EXPORTER_VERSION}\nCopyright 2022 to 2023 Overte e.V.\nCopyright 2018 High Fidelity, Inc.", "Ok");
}

/*[MenuItem("Overte/Test")]
Expand Down Expand Up @@ -343,14 +347,10 @@ static void ExportSelectedAvatar(bool updateExistingAvatar)
warnings = "";
foreach (var failedAvatarRule in failedAvatarRules)
{
if (Array.IndexOf(EXPORT_BLOCKING_AVATAR_RULES, failedAvatarRule.Key) >= 0)
{
if (EXPORT_BLOCKING_AVATAR_RULES.Contains(failedAvatarRule.Key))
boneErrors += failedAvatarRule.Value + "\n\n";
}
else
{
warnings += failedAvatarRule.Value + "\n\n";
}
}

// add material and texture warnings after bone-related warnings
Expand All @@ -359,9 +359,7 @@ static void ExportSelectedAvatar(bool updateExistingAvatar)

// remove trailing newlines at the end of the warnings
if (!string.IsNullOrEmpty(warnings))
{
warnings = warnings.Substring(0, warnings.LastIndexOf("\n\n"));
}
warnings = warnings.Trim();

if (!string.IsNullOrEmpty(boneErrors))
{
Expand All @@ -372,7 +370,7 @@ static void ExportSelectedAvatar(bool updateExistingAvatar)
boneErrors += "Warnings:\n\n" + warnings;
}
// remove ending newlines from the last rule failure string that was added above
boneErrors = boneErrors.Substring(0, boneErrors.LastIndexOf("\n\n"));
boneErrors = boneErrors.Trim();
EditorUtility.DisplayDialog("Error", boneErrors, "Ok");
return;
}
Expand Down Expand Up @@ -726,11 +724,10 @@ static void SetBoneAndMaterialInformation()
{
string humanName = bone.humanName;
string userBoneName = bone.boneName;
string overteJointName;
if (userBoneInfos.ContainsKey(userBoneName))
{
++userBoneInfos[userBoneName].mappingCount;
if (HUMANOID_TO_OVERTE_JOINT_NAME.TryGetValue(humanName, out overteJointName))
if (HUMANOID_TO_OVERTE_JOINT_NAME.ContainsKey(humanName))
{
userBoneInfos[userBoneName].humanName = humanName;
humanoidToUserBoneMappings.Add(humanName, userBoneName);
Expand Down Expand Up @@ -1245,8 +1242,9 @@ static void StoreMaterialData(Material[] materials)
}

// don't store any material data for unsupported shader types
if (Array.IndexOf(SUPPORTED_SHADERS, shaderName) == -1)
if (!SUPPORTED_SHADERS.Contains(shaderName))
{
Debug.Log($"Unsuported shader {shaderName} in mat {materialName}");
if (!unsupportedShaderMaterials.Contains(materialName))
{
unsupportedShaderMaterials.Add(materialName);
Expand Down Expand Up @@ -1339,46 +1337,22 @@ static void SetMaterialMappings()

static void AddMaterialWarnings()
{
string alternateStandardShaders = "";
string unsupportedShaders = "";
// combine all material names for each material warning into a comma-separated string
foreach (string materialName in alternateStandardShaderMaterials)
if (alternateStandardShaderMaterials.Count != 0)
{
if (!string.IsNullOrEmpty(alternateStandardShaders))
{
alternateStandardShaders += ", ";
}
alternateStandardShaders += materialName;
string alternateStandardShaders = string.Join(", ", alternateStandardShaderMaterials);
warnings += alternateStandardShaderMaterials.Count == 1
? $"The material {alternateStandardShaders} is not using the recommended variation of the Standard shader."
: $"The materials {alternateStandardShaders} are not using the recommended variation of the Standard shader."
+ " We recommend you change them to \"Autodesk Interactive\" shader for improved performance.\n\n";
}
foreach (string materialName in unsupportedShaderMaterials)
{
if (!string.IsNullOrEmpty(unsupportedShaders))
{
unsupportedShaders += ", ";
}
unsupportedShaders += materialName;
}
if (alternateStandardShaderMaterials.Count > 1)
{
warnings += "The materials " + alternateStandardShaders + " are not using the " +
"recommended variation of the Standard shader. We recommend you change " +
"them to Standard (Roughness setup) shader for improved performance.\n\n";
}
else if (alternateStandardShaderMaterials.Count == 1)
{
warnings += "The material " + alternateStandardShaders + " is not using the " +
"recommended variation of the Standard shader. We recommend you change " +
"it to Standard (Roughness setup) shader for improved performance.\n\n";
}
if (unsupportedShaderMaterials.Count > 1)
{
warnings += "The materials " + unsupportedShaders + " are using an unsupported shader. " +
"We recommend you change them to a Standard shader type.\n\n";
}
else if (unsupportedShaderMaterials.Count == 1)

if (unsupportedShaderMaterials.Count != 0)
{
warnings += "The material " + unsupportedShaders + " is using an unsupported shader. " +
"We recommend you change it to a Standard shader type.\n\n";
string unsupportedShaders = string.Join(", ", unsupportedShaderMaterials);
warnings += unsupportedShaderMaterials.Count == 1
? $"The material {unsupportedShaders} is using an unsupported shader."
: $"The materials {unsupportedShaders} are using an unsupported shader."
+ " We recommend you change it to the \"Autodesk Interactive\" shader\n\n";
}
}

Expand Down

0 comments on commit c55cf82

Please sign in to comment.