コード例 #1
0
 public static string GetKeywordName(ShaderKeyword k)
 {
                 #if UNITY_2018_3_OR_NEWER
     return(k.GetKeywordName());
                 #else
     return( = k.GetName());
                 #endif
 }
コード例 #2
0
        public void OnProcessShader(Shader shader, ShaderSnippetData snippet, IList <ShaderCompilerData> shaderVariants)
        {
            if (!ShaderVariantsStripperConfigure.Configure.useStripper)
            {
                return;
            }

            int    inputShaderVariantCount = shaderVariants.Count;
            string prefix = "VARIANT: " + shader.name + " (";

            if (snippet.passName.Length > 0)
            {
                prefix += snippet.passName + ", ";
            }

            prefix += snippet.shaderType.ToString() + ") ";
            if (ShaderVariantsStripperConfigure.Configure.enableLog)
            {
                if (shaderSets.Add(shader.name))
                {
                    File.AppendAllText(allshaderFile, shader.name + "\n");
                }
            }
            for (int i = 0; i < shaderVariants.Count; ++i)
            {
                string log = prefix;

                log += shaderVariants[i].shaderCompilerPlatform.ToString() + "  ";
                log += shaderVariants[i].graphicsTier.ToString() + "  ";

                if (ShaderVariantsStripperConfigure.Configure.enableLog)
                {
                    ShaderKeyword[] keywords = shaderVariants[i].shaderKeywordSet.GetShaderKeywords();
                    for (int labelIndex = 0; labelIndex < keywords.Count(); ++labelIndex)
                    {
                        ShaderKeyword akey                  = keywords[labelIndex];
                        bool          isUserDefined         = akey.GetKeywordType() == ShaderKeywordType.UserDefined;
                        bool          isBuiltinDefault      = akey.GetKeywordType() == ShaderKeywordType.BuiltinDefault;
                        bool          isBuiltinExtra        = akey.GetKeywordType() == ShaderKeywordType.BuiltinExtra;
                        bool          isBuiltinAutoStripped = akey.GetKeywordType() == ShaderKeywordType.BuiltinAutoStripped;

#if UNITY_2018_3_OR_NEWER
                        string keyWordName = akey.GetKeywordName();
#else
                        string keyWordName = akey.GetName();
#endif
                        log += keyWordName + " ";
                        {
                            if (keySets.Add(keyWordName))
                            {
                                File.AppendAllText(keywordFile, keyWordName + "\n");
                            }
                        }

                        if (isBuiltinDefault)
                        {
                            if (!buildInKeys.Contains(keyWordName))
                            {
                                buildInKeys.Add(keyWordName);
                                File.AppendAllText(buildInFile, keyWordName + "\n");
                            }
                        }
                        if (isBuiltinExtra)
                        {
                            if (!buildInExtraKeys.Contains(keyWordName))
                            {
                                buildInExtraKeys.Add(keyWordName);
                                File.AppendAllText(buildExtraFile, keyWordName + "\n");
                            }
                        }
                        if (isBuiltinAutoStripped)
                        {
                            if (!buildInAutoStripKeys.Contains(keyWordName))
                            {
                                buildInAutoStripKeys.Add(keyWordName);
                                File.AppendAllText(buildInAutoStripFile, keyWordName + "\n");
                            }
                        }
                        if (isUserDefined)
                        {
                            if (!userDefineKeys.Contains(keyWordName))
                            {
                                userDefineKeys.Add(keyWordName);
                                File.AppendAllText(userDefineFile, keyWordName + "\n");
                            }
                        }
                    }
                }

                bool keepVariant = true;
                if (ShaderVariantsStripperConfigure.Configure.useWhitelist)
                {
                    keepVariant = KeepVariantByWhitelist(shader, snippet, shaderVariants[i]);
                }
                else
                {
                    keepVariant = KeepVariantByConfigure(shader, snippet, shaderVariants[i]);
                }

                if (ShaderVariantsStripperConfigure.Configure.enableLog)
                {
                    //填写编译结果
                    ShaderCompileReport.Report.AddCompileInfo(shader.name, snippet, shaderVariants[i], !keepVariant);
                }

                if (!keepVariant)
                {
                    shaderVariants.RemoveAt(i);
                    --i;
                }
                if (ShaderVariantsStripperConfigure.Configure.enableLog)
                {
                    File.AppendAllText(logFile, log + "\n");
                }
            }


            if (ShaderVariantsStripperConfigure.Configure.enableLog)
            {
                float  percentage = (float)shaderVariants.Count / (float)inputShaderVariantCount * 100f;
                string logresult  = "STRIPPING(" + shader.name + " " + snippet.passName + " " + snippet.shaderType.ToString() + ") = Kept / Total = " + shaderVariants.Count + " / " + inputShaderVariantCount + " = " + percentage + "% of the generated shader variants remain in the player data";
                //Debug.Log(BText(logresult));
                File.AppendAllText(logFile, logresult + "\n");
            }
        }