Exemplo n.º 1
0
        public bool KeepVariants(Shader shader, ShaderSnippetData snippet, ShaderCompilerData variants)
        {
            keywords.Clear();
            var shaderKeywords = variants.shaderKeywordSet.GetShaderKeywords();

            foreach (var shaderkeyword in shaderKeywords)
            {
                keywords.Add(ShaderKeyword.GetGlobalKeywordName(shaderkeyword));
            }
            bool hasKeywords = keywords.Count > 0;

            Debug.Log(shader.name + "\tVariants:" + (hasKeywords ? string.Join("\t", keywords.ToArray()) : "<no keywords>"));

            if (hasKeywords && keepExportVariants != null)
            {
                ShaderVariant shaderVariant = new ShaderVariant(shader, snippet.passType, keywords.ToArray());
                // 必须,自动导出的变体组合
                if (keepExportVariants.Contains(shaderVariant))
                {
                    return(true);
                }
                // 可选,自定义变体组合
                if (keepCustomVariants != null && keepCustomVariants.Contains(shaderVariant))
                {
                    return(true);
                }
                return(false);
            }
            return(true);
        }
 private bool ContainsShaderVariant(ShaderVariantCollection collection, Shader shader, ShaderSnippetData snippet, ShaderCompilerData data)
 {
     if (collection == null)
     {
         return(false);
     }
     return(collection.Contains(new ShaderVariantCollection.ShaderVariant(shader, snippet.passType, ToKeywordArray(shader, data.shaderKeywordSet))));
 }
Exemplo n.º 3
0
 private void AddShaderVariantFromShaderList(ShaderVariantCollection _svc, List <ShaderVariantCollection.ShaderVariant> svList)
 {
     foreach (var sv in svList)
     {
         if (!_svc.Contains(sv))
         {
             //存在しないので追加
             _svc.Add(sv);
         }
     }
 }
Exemplo n.º 4
0
    private void OnMaterialProcess(Material mat)
    {
        var variant = CreateVariant(mat);

        if (!collection.Contains(variant))
        {
            collection.Add(variant);
            var keywordsString = JsonUtility.ToJson(variant.keywords, true);
            Debug.Log($"New variant found!\nShader: {variant.shader.name}\nKeywords:{keywordsString}");
        }
    }
Exemplo n.º 5
0
 protected void KeywordsChanged() {
     foreach (PassType passType in GetPassTypes()) {
         try {
             ShaderVariantCollection.ShaderVariant shaderVariant =
                 new ShaderVariantCollection.ShaderVariant(GetShader(), passType, keywordsEnabled.ToArray());
             if (!shaderVariants.Contains(shaderVariant)) {
                 shaderVariants.Add(shaderVariant);
             }
         }
         catch (Exception _) {
             // ignored
         }
     }
 }
Exemplo n.º 6
0
 private void AddShaderVariantList(ShaderVariantCollection shaderVariantCollection, List <ShaderVariantCollection.ShaderVariant> list)
 {
     foreach (var variant in list)
     {
         try
         {
             if (!shaderVariantCollection.Contains(variant))
             {
                 shaderVariantCollection.Add(variant);
             }
         } catch (System.Exception e)
         {
             Debug.LogError(e);
         }
     }
 }
    // Start is called before the first frame update
    void Start()
    {
        string [] keywords = new string [] {
            "DIRECTIONAL",
            "LIGHTPROBE_SH",
            "_ALPHAPREMULTIPLY_ON"
        };
        ShaderVariantCollection.ShaderVariant variant =
            new ShaderVariantCollection.ShaderVariant(
                Shader.Find("Standard"),
                PassType.ForwardBase,
                keywords);
        bool match = variants.Contains(variant);

        Debug.LogFormat(
            "Shader {0} pass {1} keywords {2} found {3}",
            variant.shader.name,
            variant.passType,
            string.Join(" ", variant.keywords),
            match);
    }
Exemplo n.º 8
0
        private void BuildShaderInfos()
        {
            var shaderPaths = AssetDatabase.FindAssets("t:shader")
                              .Select(x => AssetDatabase.GUIDToAssetPath(x))
                              .ToArray();

            if (targetFolder != null)
            {
                var folderPath = AssetDatabase.GetAssetPath(targetFolder);

                shaderPaths = shaderPaths.Where(x => x.StartsWith(folderPath)).ToArray();
            }

            shaderInfos.Clear();

            foreach (var shaderPath in shaderPaths)
            {
                var shader = AssetDatabase.LoadMainAssetAtPath(shaderPath) as Shader;

                if (shader == null)
                {
                    continue;
                }

                var shaderVariant = new ShaderVariantCollection.ShaderVariant();

                shaderVariant.shader = shader;

                var info = new ShaderInfo()
                {
                    assetPath     = shaderPath,
                    shader        = shader,
                    add           = shaderVariantCollection.Contains(shaderVariant),
                    shaderVariant = shaderVariant,
                };

                shaderInfos.Add(info);
            }
        }
Exemplo n.º 9
0
        public void OnProcessShader(Shader shader, ShaderSnippetData snippet, IList <ShaderCompilerData> shaderData)
        {
            if (shader.name.Contains("Universal Render Pipeline") ||
                shader.name.Contains("TextMeshPro") ||
                shader.name.Contains("Default") ||
                shader.name.Contains("Hidden") ||
                shader.name.Contains("UI") ||
                shader.name.Contains("Sprites") ||
                shader.name.Contains("Skybox")
                )
            {
                return;
            }

            _shaderVariantCache.shader   = shader;
            _shaderVariantCache.passType = snippet.passType;
            for (var i = 0; i < shaderData.Count; ++i)
            {
                var internalShaderData = shaderData[i];
                var shaderKeywords     = internalShaderData.shaderKeywordSet.GetShaderKeywords();

                _compilerKeywords.Clear();
                foreach (var internalKeyword in shaderKeywords)
                {
                    _compilerKeywords.Add(ShaderKeyword.GetGlobalKeywordName(internalKeyword));
                }

                _shaderVariantCache.keywords = _compilerKeywords.ToArray();

                if (_shaderVariantCollection.Contains(_shaderVariantCache))
                {
                    continue;
                }
                shaderData.RemoveAt(i);
                i--;
            }
        }
Exemplo n.º 10
0
    void CheckShaderVariant(ShaderVariantCollection collection, Shader source, int i, bool point = true, bool projector = false)
    {
        ShaderVariantList.Clear();


        int v  = i;
        int vc = 0;

        if (v >= 64)
        {
            if (!Full)
            {
                return;
            }
            ShaderVariantList.Add("FULL_ON"); v -= 64; vc++;
        }
        else
        {
            if (!LowRes)
            {
                return;
            }
        }
        if (v >= 32)
        {
            if (!Transparency)
            {
                return;
            }
            ShaderVariantList.Add("VTRANSPARENCY_ON"); v -= 32; vc++;
        }
        else
        {
            if (!TransparencyOff)
            {
                return;
            }
        }
        if (v >= 16)
        {
            if (!DensityParticles)
            {
                return;
            }
            ShaderVariantList.Add("DENSITYPARTICLES_ON"); v -= 16; vc++;
        }
        if (v >= 8)
        {
            if (!HeightFog)
            {
                return;
            }
            ShaderVariantList.Add("HEIGHTFOG_ON"); v -= 8; vc++;
        }
        else
        {
            if (!HeightFogOff)
            {
                return;
            }
        }
        if (v >= 4)
        {
            if (!Noise)
            {
                return;
            }
            ShaderVariantList.Add("NOISE_ON"); v -= 4; vc++;
        }
        else
        {
            if (!NoiseOff)
            {
                return;
            }
        }
        if (v >= 2)
        {
            if (point)
            {
                ShaderVariantList.Add("POINT_COOKIE"); vc++;
            }
            v -= 2;
        }
        if (v >= 1)
        {
            v -= 1;
        }
        else
        {
            if (!projector)
            {
                ShaderVariantList.Add("SHADOWS_OFF");
            }
            vc++;
        };


        string[] fv = new string[vc];
        ShaderVariantList.CopyTo(fv);
        Material m = new Material(source);

        m.name = "";
        EnableKeywordList(m);

        AssetDatabase.AddObjectToAsset(m, collection);

        //string final = source.name + " ";
        //for (int s = 0; s < fv.Length; s++)
        //{
        //    final += fv[s] + " ";
        //}
        // Debug.Log(final);
        ShaderVariantCollection.ShaderVariant varient = new ShaderVariantCollection.ShaderVariant(source, PassType.Normal, fv);
        if (!collection.Contains(varient))
        {
            collection.Add(varient);
        }
        //if (shadows && !point && !projector)
        //{
        //    ShaderVariantList.Add("SHADOWS_NATIVE");
        //    string[] fv2 = new string[vc + 1];
        //    ShaderVariantList.CopyTo(fv2);
        //
        //    ShaderVariantCollection.ShaderVariant varient2 = new ShaderVariantCollection.ShaderVariant(source, PassType.Normal, fv2);
        //    if (!collection.Contains(varient2)) { collection.Add(varient2); }
        //
        //    Material m2 = new Material(source);
        //    EnableKeywordList(m2);
        //    m2.name = "";
        //    AssetDatabase.AddObjectToAsset(m2, collection);
        //    ShaderVariantList.RemoveAt(ShaderVariantList.Count - 1);
        //
        //
        //}

        if (SinglePassStereo)
        {
            ShaderVariantList.Add("UNITY_SINGLE_PASS_STEREO");
            string[] fvssp2 = new string[vc + 1];
            ShaderVariantList.CopyTo(fvssp2);

            ShaderVariantCollection.ShaderVariant varientSP = new ShaderVariantCollection.ShaderVariant(source, PassType.Normal, fvssp2); //Hier zit een error maar ik heb geen idee wat dus de gene die dit heeft geschreven check het!
            if (!collection.Contains(varientSP))
            {
                collection.Add(varientSP);
            }

            Material m2 = new Material(source);
            EnableKeywordList(m2);
            m2.name = "";
            AssetDatabase.AddObjectToAsset(m2, collection);

            // if (shadows && !point && !projector)
            // {
            //     ShaderVariantList.Add("SHADOWS_NATIVE");
            //     string[] fv2 = new string[vc + 2];
            //     ShaderVariantList.CopyTo(fv2);
            //
            //     ShaderVariantCollection.ShaderVariant varient2 = new ShaderVariantCollection.ShaderVariant(source, PassType.Normal, fv2);
            //     if (!collection.Contains(varient2)) { collection.Add(varient2); }
            //
            //     Material m3 = new Material(source);
            //     EnableKeywordList(m3);
            //     m3.name = "";
            //     AssetDatabase.AddObjectToAsset(m3, collection);
            //
            // }
        }
    }