public static void AllMaterialShadersAreNotBuiltin(string projectName, ShaderPathID shaderPathID)
    {
        string shaderPath = AssetDatabase.GUIDToAssetPath(ShaderUtils.GetShaderGUID(shaderPathID));

        Assert.IsFalse(string.IsNullOrEmpty(shaderPath));

        var shader = AssetDatabase.LoadAssetAtPath <Shader>(shaderPath);

        Assert.AreEqual(shader.name, ShaderUtils.GetShaderPath(shaderPathID));

        var guids = AssetDatabase.FindAssets("t:Material");

        foreach (var guid in guids)
        {
            var path = AssetDatabase.GUIDToAssetPath(guid);

            // We only care what is in assets folder
            if (!path.StartsWith("Assets"))
            {
                continue;
            }

            Material material = AssetDatabase.LoadAssetAtPath <Material>(path);
            Assert.AreNotEqual(material.shader, shader, $"Material ({path}) has excluded shader. {projectName} project should not have shader {shader.name}");
        }
    }
 static void UpgradeV2(Material material, ShaderPathID shaderID)
 {
     // fix 50 offset on shaders
     if (material.HasProperty("_QueueOffset"))
     {
         BaseShaderGUI.SetupMaterialBlendMode(material);
     }
 }
示例#3
0
    public void ValidateShaderResources(ShaderPathID shaderPathID)
    {
        string path = AssetDatabase.GUIDToAssetPath(ShaderUtils.GetShaderGUID(shaderPathID));

        Assert.IsFalse(string.IsNullOrEmpty(path));

        var shader = AssetDatabase.LoadAssetAtPath <Shader>(path);

        Assert.AreEqual(shader.name, ShaderUtils.GetShaderPath(shaderPathID));
    }
        public static string GetShaderPath(ShaderPathID id)
        {
            int index = (int)id;

            if (index < 0 && index >= (int)ShaderPathID.SHADER_PATH_COUNT)
            {
                Debug.LogError("Trying to access lightweight shader path out of bounds");
                return("");
            }

            return(m_ShaderPaths[index]);
        }
示例#5
0
        internal static string GetShaderGUID(ShaderPathID id)
        {
            int index = (int)id;

            if (index < 0 && index >= (int)ShaderPathID.Count)
            {
                Debug.LogError("Trying to access universal shader path out of bounds");
                return("");
            }

            return(s_ShaderGUIDs[index]);
        }
        internal static string GetShaderGUID(ShaderPathID id)
        {
            int index       = (int)id;
            int arrayLength = s_ShaderGUIDs.Length;

            if (arrayLength > 0 && index >= 0 && index < arrayLength)
            {
                return(s_ShaderGUIDs[index]);
            }

            Debug.LogError("Trying to access universal shader GUID out of bounds: (" + id + ": " + index + ")");
            return("");
        }
示例#7
0
        static void UpgradeV5(Material material, ShaderPathID shaderID)
        {
            var propertyID = Shader.PropertyToID("_Surface");

            if (material.HasProperty(propertyID))
            {
                float surfaceType = material.GetFloat(propertyID);
                if (surfaceType >= 1.0f)
                {
                    material.EnableKeyword("_SURFACE_TYPE_TRANSPARENT");
                }
                else
                {
                    material.DisableKeyword("_SURFACE_TYPE_TRANSPARENT");
                }
            }
        }
示例#8
0
    public void ValidateShaderResources(ShaderPathID shaderPathID)
    {
        string path = AssetDatabase.GUIDToAssetPath(ShaderUtils.GetShaderGUID(shaderPathID));

        Assert.IsFalse(string.IsNullOrEmpty(path));

        var shader = AssetDatabase.LoadAssetAtPath <Shader>(path);

        Assert.AreEqual(shader.name, ShaderUtils.GetShaderPath(shaderPathID));

        var propertyNames = new System.Collections.Generic.HashSet <string>();

        for (int j = 0; j < shader.GetPropertyCount(); ++j)
        {
            string propertyName = shader.GetPropertyName(j);
            Assert.IsFalse(propertyNames.Contains(propertyName), $"{shader.name} has duplicated property {propertyName}!");
            propertyNames.Add(propertyName);
        }
    }
 static void UpgradeV3(Material material, ShaderPathID shaderID)
 {
     switch (shaderID)
     {
     case ShaderPathID.Lit:
     case ShaderPathID.SimpleLit:
     case ShaderPathID.ParticlesLit:
     case ShaderPathID.ParticlesSimpleLit:
     case ShaderPathID.ParticlesUnlit:
         var propertyID = Shader.PropertyToID("_EmissionColor");
         if (material.HasProperty(propertyID))
         {
             // In older version there was a bug that these shaders did not had HDR attribute on emission property.
             // This caused emission color to be converted from gamma to linear space.
             // In order to avoid visual regression on older projects we will do gamma to linear conversion here.
             var emissionGamma  = material.GetColor(propertyID);
             var emissionLinear = emissionGamma.linear;
             material.SetColor(propertyID, emissionLinear);
         }
         break;
     }
 }
        static void UpgradeV1(Material material, ShaderPathID shaderID)
        {
            var shaderPath  = ShaderUtils.GetShaderPath(shaderID);
            var upgradeFlag = MaterialUpgrader.UpgradeFlags.LogMessageWhenNoUpgraderFound;

            switch (shaderID)
            {
            case ShaderPathID.Unlit:
                MaterialUpgrader.Upgrade(material, new UnlitUpdaterV1(shaderPath), upgradeFlag);
                UnlitShader.SetMaterialKeywords(material);
                break;

            case ShaderPathID.SimpleLit:
                MaterialUpgrader.Upgrade(material, new SimpleLitUpdaterV1(shaderPath), upgradeFlag);
                SimpleLitShader.SetMaterialKeywords(material, SimpleLitGUI.SetMaterialKeywords);
                break;

            case ShaderPathID.Lit:
                MaterialUpgrader.Upgrade(material, new LitUpdaterV1(shaderPath), upgradeFlag);
                LitShader.SetMaterialKeywords(material, LitGUI.SetMaterialKeywords);
                break;

            case ShaderPathID.ParticlesLit:
                MaterialUpgrader.Upgrade(material, new ParticleUpdaterV1(shaderPath), upgradeFlag);
                ParticlesLitShader.SetMaterialKeywords(material, LitGUI.SetMaterialKeywords, ParticleGUI.SetMaterialKeywords);
                break;

            case ShaderPathID.ParticlesSimpleLit:
                MaterialUpgrader.Upgrade(material, new ParticleUpdaterV1(shaderPath), upgradeFlag);
                ParticlesSimpleLitShader.SetMaterialKeywords(material, SimpleLitGUI.SetMaterialKeywords, ParticleGUI.SetMaterialKeywords);
                break;

            case ShaderPathID.ParticlesUnlit:
                MaterialUpgrader.Upgrade(material, new ParticleUpdaterV1(shaderPath), upgradeFlag);
                ParticlesUnlitShader.SetMaterialKeywords(material, null, ParticleGUI.SetMaterialKeywords);
                break;
            }
        }
 static void InitializeLatest(Material material, ShaderPathID id)
 {
 }
        static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
        {
            var upgradeLog   = "UniversalRP Material log:";
            var upgradeCount = 0;

            foreach (var asset in importedAssets)
            {
                if (!asset.ToLowerInvariant().EndsWith(".mat"))
                {
                    continue;
                }

                var material = (Material)AssetDatabase.LoadAssetAtPath(asset, typeof(Material));
                if (!ShaderUtils.IsLWShader(material.shader))
                {
                    continue;
                }

                ShaderPathID id            = ShaderUtils.GetEnumFromPath(material.shader.name);
                var          wasUpgraded   = false;
                var          assetVersions = AssetDatabase.LoadAllAssetsAtPath(asset);
                AssetVersion assetVersion  = null;
                foreach (var subAsset in assetVersions)
                {
                    if (subAsset.GetType() == typeof(AssetVersion))
                    {
                        assetVersion = subAsset as AssetVersion;
                    }
                }
                var debug = "\n" + material.name;

                if (!assetVersion)
                {
                    wasUpgraded  = true;
                    assetVersion = ScriptableObject.CreateInstance <AssetVersion>();
                    if (s_CreatedAssets.Contains(asset))
                    {
                        assetVersion.version = k_Upgraders.Length;
                        s_CreatedAssets.Remove(asset);
                        InitializeLatest(material, id);
                    }
                    else
                    {
                        assetVersion.version = 0;
                    }

                    assetVersion.hideFlags = HideFlags.HideInHierarchy | HideFlags.HideInInspector | HideFlags.NotEditable;
                    AssetDatabase.AddObjectToAsset(assetVersion, asset);
                    debug += " initialized.";
                }

                while (assetVersion.version < k_Upgraders.Length)
                {
                    k_Upgraders[assetVersion.version](material, id);
                    debug += $" upgrading:v{assetVersion.version} to v{assetVersion.version + 1}";
                    assetVersion.version++;
                    wasUpgraded = true;
                }

                if (wasUpgraded)
                {
                    upgradeLog += debug;
                    upgradeCount++;
                    EditorUtility.SetDirty(assetVersion);
                    s_ImportedAssetThatNeedSaving.Add(asset);
                    s_NeedsSavingAssets = true;
                }
            }
        }
示例#13
0
 static void UpgradeV4(Material material, ShaderPathID shaderID)
 {
 }
示例#14
0
 public void AllShadersAreNot(ShaderPathID shaderPathID)
 {
     UniversalProjectAssert.AllMaterialShadersAreNotBuiltin(kProjectName, shaderPathID);
 }
示例#15
0
 public void CheckIfScenesDoNoHaveShader(ShaderPathID shaderPathID)
 {
     UniversalProjectAssert.AllMaterialShadersAreNotBuiltin(kProjectName, shaderPathID);
 }