public static string CheckMaterial(Material mat, BuildTarget buildTarget) { if (mat == null || mat.shader == null) { return(null); } string shaderName = mat.shader.name; int lOD = ShaderUtil.GetLOD(mat.shader); bool flag = Array.Exists <string>(PerformanceChecks.kShadersWithMobileVariants, (string s) => s == shaderName); bool flag2 = PerformanceChecks.IsMobileBuildTarget(buildTarget); if (buildTarget == BuildTarget.Android && ShaderUtil.HasClip(mat.shader)) { return(PerformanceChecks.FormattedTextContent("PerformanceChecks.ShaderWithClipAndroid", new object[0])); } if (!(mat.GetTag("PerformanceChecks", true).ToLower() == "false")) { if (flag) { if (flag2 && mat.HasProperty("_Color") && mat.GetColor("_Color") == new Color(1f, 1f, 1f, 1f)) { return(PerformanceChecks.FormattedTextContent("PerformanceChecks.ShaderUsesWhiteColor", new object[] { "Mobile/" + shaderName })); } if (flag2 && shaderName.StartsWith("Particles/")) { return(PerformanceChecks.FormattedTextContent("PerformanceChecks.ShaderHasMobileVariant", new object[] { "Mobile/" + shaderName })); } if (shaderName == "RenderFX/Skybox" && mat.HasProperty("_Tint") && mat.GetColor("_Tint") == new Color(0.5f, 0.5f, 0.5f, 0.5f)) { return(PerformanceChecks.FormattedTextContent("PerformanceChecks.ShaderMobileSkybox", new object[] { "Mobile/Skybox" })); } } if (lOD >= 300 && flag2 && !shaderName.StartsWith("Mobile/")) { return(PerformanceChecks.FormattedTextContent("PerformanceChecks.ShaderExpensive", new object[0])); } if (shaderName.Contains("VertexLit") && mat.HasProperty("_Emission")) { Color color = mat.GetColor("_Emission"); if (color.r >= 0.5f && color.g >= 0.5f && color.b >= 0.5f) { return(PerformanceChecks.FormattedTextContent("PerformanceChecks.ShaderUseUnlit", new object[0])); } } if (mat.HasProperty("_BumpMap") && mat.GetTexture("_BumpMap") == null) { return(PerformanceChecks.FormattedTextContent("PerformanceChecks.ShaderNoNormalMap", new object[0])); } } return(null); }
public static string CheckMaterial(Material mat, BuildTarget buildTarget) { // ISSUE: object of a compiler-generated type is created // ISSUE: variable of a compiler-generated type PerformanceChecks.\u003CCheckMaterial\u003Ec__AnonStoreyBE materialCAnonStoreyBe = new PerformanceChecks.\u003CCheckMaterial\u003Ec__AnonStoreyBE(); if ((UnityEngine.Object)mat == (UnityEngine.Object)null || (UnityEngine.Object)mat.shader == (UnityEngine.Object)null) { return((string)null); } // ISSUE: reference to a compiler-generated field materialCAnonStoreyBe.shaderName = mat.shader.name; int lod = ShaderUtil.GetLOD(mat.shader); // ISSUE: reference to a compiler-generated method bool flag1 = Array.Exists <string>(PerformanceChecks.kShadersWithMobileVariants, new Predicate <string>(materialCAnonStoreyBe.\u003C\u003Em__22D)); bool flag2 = PerformanceChecks.IsMobileBuildTarget(buildTarget); if (!(mat.GetTag("PerformanceChecks", true).ToLower() == "false")) { if (flag1) { if (flag2 && mat.HasProperty("_Color") && mat.GetColor("_Color") == new Color(1f, 1f, 1f, 1f)) { // ISSUE: reference to a compiler-generated field return(PerformanceChecks.FormattedTextContent("Shader is using white color which does nothing; Consider using {0} shader for performance.", (object)("Mobile/" + materialCAnonStoreyBe.shaderName))); } // ISSUE: reference to a compiler-generated field if (flag2 && materialCAnonStoreyBe.shaderName.StartsWith("Particles/")) { // ISSUE: reference to a compiler-generated field return(PerformanceChecks.FormattedTextContent("Consider using {0} shader on this platform for performance.", (object)("Mobile/" + materialCAnonStoreyBe.shaderName))); } // ISSUE: reference to a compiler-generated field if (materialCAnonStoreyBe.shaderName == "RenderFX/Skybox" && mat.HasProperty("_Tint") && mat.GetColor("_Tint") == new Color(0.5f, 0.5f, 0.5f, 0.5f)) { return(PerformanceChecks.FormattedTextContent("Skybox shader is using gray color which does nothing; Consider using {0} shader for performance.", (object)"Mobile/Skybox")); } } // ISSUE: reference to a compiler-generated field if (lod >= 300 && flag2 && !materialCAnonStoreyBe.shaderName.StartsWith("Mobile/")) { return(PerformanceChecks.FormattedTextContent("Shader might be expensive on this platform. Consider switching to a simpler shader; look under Mobile shaders.")); } // ISSUE: reference to a compiler-generated field if (materialCAnonStoreyBe.shaderName.Contains("VertexLit") && mat.HasProperty("_Emission")) { Color color = mat.GetColor("_Emission"); if ((double)color.r >= 0.5 && (double)color.g >= 0.5 && (double)color.b >= 0.5) { return(PerformanceChecks.FormattedTextContent("Looks like you're using VertexLit shader to simulate an unlit object (white emissive). Use one of Unlit shaders instead for performance.")); } } if (mat.HasProperty("_BumpMap") && (UnityEngine.Object)mat.GetTexture("_BumpMap") == (UnityEngine.Object)null) { return(PerformanceChecks.FormattedTextContent("Normal mapped shader without a normal map. Consider using a non-normal mapped shader for performance.")); } } return((string)null); }
public static string CheckMaterial(Material mat, BuildTarget buildTarget) { if (mat == null || mat.shader == null) { return(null); } string shaderName = mat.shader.name; int lOD = ShaderUtil.GetLOD(mat.shader); bool flag = Array.Exists <string>(PerformanceChecks.kShadersWithMobileVariants, (string s) => s == shaderName); bool flag2 = PerformanceChecks.IsMobileBuildTarget(buildTarget); if (!(mat.GetTag("PerformanceChecks", true).ToLower() == "false")) { if (flag) { if (flag2 && mat.HasProperty("_Color") && mat.GetColor("_Color") == new Color(1f, 1f, 1f, 1f)) { return(PerformanceChecks.FormattedTextContent("Shader is using white color which does nothing; Consider using {0} shader for performance.", new object[] { "Mobile/" + shaderName })); } if (flag2 && shaderName.StartsWith("Particles/")) { return(PerformanceChecks.FormattedTextContent("Consider using {0} shader on this platform for performance.", new object[] { "Mobile/" + shaderName })); } if (shaderName == "RenderFX/Skybox" && mat.HasProperty("_Tint") && mat.GetColor("_Tint") == new Color(0.5f, 0.5f, 0.5f, 0.5f)) { return(PerformanceChecks.FormattedTextContent("Skybox shader is using gray color which does nothing; Consider using {0} shader for performance.", new object[] { "Mobile/Skybox" })); } } if (lOD >= 300 && flag2 && !shaderName.StartsWith("Mobile/")) { return(PerformanceChecks.FormattedTextContent("Shader might be expensive on this platform. Consider switching to a simpler shader; look under Mobile shaders.", new object[0])); } if (shaderName.Contains("VertexLit") && mat.HasProperty("_Emission")) { Color color = mat.GetColor("_Emission"); if (color.r >= 0.5f && color.g >= 0.5f && color.b >= 0.5f) { return(PerformanceChecks.FormattedTextContent("Looks like you're using VertexLit shader to simulate an unlit object (white emissive). Use one of Unlit shaders instead for performance.", new object[0])); } } if (mat.HasProperty("_BumpMap") && mat.GetTexture("_BumpMap") == null) { return(PerformanceChecks.FormattedTextContent("Normal mapped shader without a normal map. Consider using a non-normal mapped shader for performance.", new object[0])); } } return(null); }
public static string CheckMaterial(Material mat, BuildTarget buildTarget) { if (mat == null || mat.shader == null) { return(null); } string shaderName = mat.shader.name; int shaderLOD = ShaderUtil.GetLOD(mat.shader); bool hasMobileVariant = Array.Exists(kShadersWithMobileVariants, s => s == shaderName); bool isMobileTarget = IsMobileBuildTarget(buildTarget); // Skip all performance-related checks if shader explicitly indicated that via a PerformanceChecks=False tag. bool noPerfChecks = (mat.GetTag("PerformanceChecks", true).ToLower() == "false"); if (!noPerfChecks) { // shaders that have faster / simpler equivalents already if (hasMobileVariant) { // has default white color? if (isMobileTarget && mat.HasProperty("_Color") && mat.GetColor("_Color") == new Color(1.0f, 1.0f, 1.0f, 1.0f)) { return(FormattedTextContent("Shader is using white color which does nothing; Consider using {0} shader for performance.", "Mobile/" + shaderName)); } // recommend Mobile particle shaders on mobile platforms if (isMobileTarget && shaderName.StartsWith("Particles/")) { return(FormattedTextContent("Consider using {0} shader on this platform for performance.", "Mobile/" + shaderName)); } // has default skybox tint color? if (shaderName == "RenderFX/Skybox" && mat.HasProperty("_Tint") && mat.GetColor("_Tint") == new Color(0.5f, 0.5f, 0.5f, 0.5f)) { return(FormattedTextContent("Skybox shader is using gray color which does nothing; Consider using {0} shader for performance.", "Mobile/Skybox")); } } // recommend "something simpler" for complex shaders on mobile platforms if (shaderLOD >= 300 && isMobileTarget && !shaderName.StartsWith("Mobile/")) { return(FormattedTextContent("Shader might be expensive on this platform. Consider switching to a simpler shader; look under Mobile shaders.")); } // vertex lit shader with max. emission: recommend Unlit shaders if (shaderName.Contains("VertexLit") && mat.HasProperty("_Emission")) { bool isColor = false; Shader shader = mat.shader; int count = ShaderUtil.GetPropertyCount(shader); for (int i = 0; i < count; i++) { if (ShaderUtil.GetPropertyName(shader, i) == "_Emission") { isColor = (ShaderUtil.GetPropertyType(shader, i) == ShaderUtil.ShaderPropertyType.Color); break; } } if (isColor) { Color col = mat.GetColor("_Emission"); if (col.r >= 0.5f && col.g >= 0.5f && col.b >= 0.5f) { return(FormattedTextContent("Looks like you're using VertexLit shader to simulate an unlit object (white emissive). Use one of Unlit shaders instead for performance.")); } } } // normalmapped shader without a normalmap: recommend non-normal mapped one if (mat.HasProperty("_BumpMap") && mat.GetTexture("_BumpMap") == null) { return(FormattedTextContent("Normal mapped shader without a normal map. Consider using a non-normal mapped shader for performance.")); } } return(null); }