Beispiel #1
0
        public void TryCompileFast()
        {
            var pipe = DetectProjectPipeline();

            foreach (var variant in variants)
            {
                if (variant.Pipe == pipe)
                {
                    var overrides = new JBooth.BetterShaders.OptionOverrides();
                    var path      = GetPath();

                    overrides.shaderName = title;

                    if (System.IO.File.Exists(path) == true)
                    {
                        CompileVariant(overrides, path, variant);
                    }
                    else
                    {
                        Debug.LogError("Failed to compile shader bundle because of missing file: " + path);
                    }

                    dirty = true;

                    return;
                }
            }
        }
Beispiel #2
0
        private void CompileVariant(Pipeline pipe, JBooth.BetterShaders.OptionOverrides overrides, string path)
        {
            var variant = new ShaderVariant();

            variant.Pipe = pipe;

            CompileVariant(overrides, path, variant);

            variants.Add(variant);
        }
Beispiel #3
0
        private void CompileVariant(JBooth.BetterShaders.OptionOverrides overrides, string path, ShaderVariant variant)
        {
            var pipeline = (JBooth.BetterShaders.ShaderBuilder.RenderPipeline)variant.Pipe;

            if (path.EndsWith("surfshader"))
            {
                variant.Code = JBooth.BetterShaders.BetterShaderImporterEditor.BuildExportShader(pipeline, overrides, path);
            }
            else if (path.EndsWith("stackedshader"))
            {
                variant.Code = JBooth.BetterShaders.StackedShaderImporterEditor.BuildExportShader(pipeline, overrides, path);
            }

            variant.Code = variant.Code.Replace("\n\r", "\n");
            variant.Code = variant.Code.Replace("\r\n", "\n");
        }
Beispiel #4
0
        public void Compile()
        {
            if (target != null)
            {
                UnityEditor.Undo.RecordObject(this, "Compiling Shaders");

                if (variants == null)
                {
                    variants = new List <ShaderVariant>();
                }
                else
                {
                    variants.Clear();
                }

                var overrides = new JBooth.BetterShaders.OptionOverrides();
                var path      = GetPath();

                overrides.shaderName = title;

                if (System.IO.File.Exists(path) == true)
                {
                    for (var i = 0; i < (int)Pipeline.COUNT; i++)
                    {
                        CompileVariant((Pipeline)i, overrides, path);
                    }

                    code  = System.IO.File.ReadAllText(path);
                    dirty = false;
                }
                else
                {
                    Debug.LogError("Failed to compile shader bundle because of missing file: " + path);
                }

                UnityEditor.EditorUtility.SetDirty(this);
            }
        }