Пример #1
0
        private static void CreateCompiledFiles(string dir, CompiledShaderParser compiledShaderParser)
        {
            int idx       = 0;
            var programs  = compiledShaderParser.GetShaderPrograms();
            var passInfos = compiledShaderParser.GetPassInfos();

            InitDirectory(dir);
            StringBuilder pathSb       = new StringBuilder(128);
            StringBuilder infoSb       = new StringBuilder(1024);
            int           programCount = programs.Count;
            int           passCount    = passInfos.Count;

            infoSb.Append("{");
            infoSb.Append("\"passInfo\":[\n");
            foreach (var passInfo in passInfos)
            {
                infoSb.Append("  {\n    \"name\":");
                AppendJsonStringValue(infoSb, passInfo.name).Append(",\n");

                infoSb.Append("\n    \"tags\":");
                AppendJsonStringValue(infoSb, passInfo.tags).Append("\n");

                infoSb.Append("  }");
                if (idx == passCount - 1)
                {
                    infoSb.Append("\n");
                }
                else
                {
                    infoSb.Append(",\n");
                }
                ++idx;
            }
            infoSb.Append("],\n");

            idx = 0;
            infoSb.Append("\"keywords\":[\n");
            foreach (var program in programs)
            {
                infoSb.Append("  {\n    \"global\":\"").Append(program.globalKeyword).Append("\",\n");
                infoSb.Append("    \"local\":\"").Append(program.globalKeyword).Append("\",\n");
                infoSb.Append("    \"passIdx\":\"").Append(program.passInfoIdx).Append("\"\n  }");
                if (idx == programCount - 1)
                {
                    infoSb.Append("\n");
                }
                else
                {
                    infoSb.Append(",\n");
                }
                pathSb.Clear().Append(dir).Append('/').Append(idx).Append(".vert");
                File.WriteAllText(pathSb.ToString(), program.vertShader);
                pathSb.Clear().Append(dir).Append('/').Append(idx).Append(".frag");
                File.WriteAllText(pathSb.ToString(), program.fragShader);
                ++idx;
            }
            infoSb.Append("]}");
            pathSb.Clear().Append(dir).Append("/info.json");
            File.WriteAllText(pathSb.ToString(), infoSb.ToString());
        }
Пример #2
0
        public static AnalyzedShaderInfo Create(Shader shader, CompiledShaderParser compiledShaderParser)
        {
            AnalyzedShaderInfo info = new AnalyzedShaderInfo();

            info.shaderName = shader.name;
            var programs  = compiledShaderParser.GetShaderPrograms();
            var passInfos = compiledShaderParser.GetPassInfos();

            string dir = Path.Combine(COMPILED_FILE_PATH, shader.name);

            // create compile files
            EditorUtility.DisplayProgressBar("Analyzing", "Analyze ShaderProgram", 0.0f);
            try
            {
                CreateCompiledFiles(dir, compiledShaderParser);
                for (int i = 0; i < programs.Count; ++i)
                {
                    EditorUtility.DisplayProgressBar("Analyzing", "Analyze ShaderProgram", i / (float)programs.Count);

                    var vertJson          = MaliocPluginUtility.CallMaliShaderOfflineCompiler(dir + "/" + i + ".vert", true);
                    var fragJson          = MaliocPluginUtility.CallMaliShaderOfflineCompiler(dir + "/" + i + ".frag", true);
                    var vertResult        = MaliOcReport.CreateFromJson(vertJson);
                    var fragResult        = MaliOcReport.CreateFromJson(fragJson);
                    var shaderProgramInfo = ShaderProgramInfo.Create(vertResult, fragResult);

                    var key = new ShaderKeywordInfo();
                    key.globalKeyword = programs[i].globalKeyword;
                    key.localKeyword  = programs[i].localKeyword;
                    key.passIndex     = programs[i].passInfoIdx;
                    info.AddProgramInfo(key, shaderProgramInfo);
                }
            }catch (System.ComponentModel.Win32Exception e)
            {
                EditorUtility.ClearProgressBar();
                EditorUtility.DisplayDialog("malioc not found", "please install ARM Mobile studio. or make to malioc path correct.", "OK");
                return(null);
            }
            EditorUtility.ClearProgressBar();

            for (int i = 0; i < passInfos.Count; ++i)
            {
                info.AddPassInfo(passInfos[i].name, passInfos[i].tags);
            }

            InitDirectory(DB_FILE_PATH);
            info.SaveToFile(Path.Combine(DB_FILE_PATH,
                                         shader.name.Replace('/', '_') + ".json"));
            return(info);
        }