public string GetSubshader(IMasterNode masterNode, GenerationMode mode, List <string> sourceAssetDependencyPaths = null)
        {
            if (sourceAssetDependencyPaths != null)
            {
                // LightWeightPBRSubShader.cs
                sourceAssetDependencyPaths.Add(AssetDatabase.GUIDToAssetPath("ca91dbeb78daa054c9bbe15fef76361c"));
            }

            var templatePath            = GetTemplatePath("lightweightPBRForwardPass.template");
            var extraPassesTemplatePath = GetTemplatePath("lightweightPBRExtraPasses.template");

            if (!File.Exists(templatePath) || !File.Exists(extraPassesTemplatePath))
            {
                return(string.Empty);
            }

            if (sourceAssetDependencyPaths != null)
            {
                sourceAssetDependencyPaths.Add(templatePath);
                sourceAssetDependencyPaths.Add(extraPassesTemplatePath);

                var shaderFiles = Directory.GetFiles(
                    Path.GetFullPath("Packages/com.unity.render-pipelines.lightweight/ShaderLibrary"));
                sourceAssetDependencyPaths.AddRange(shaderFiles);
            }

            string forwardTemplate = File.ReadAllText(templatePath);
            string extraTemplate   = File.ReadAllText(extraPassesTemplatePath);

            var pbrMasterNode = masterNode as PBRMasterNode;
            var pass          = pbrMasterNode.model == PBRMasterNode.Model.Metallic ? m_ForwardPassMetallic : m_ForwardPassSpecular;
            var subShader     = new ShaderStringBuilder();

            subShader.AppendLine("SubShader");
            using (subShader.BlockScope())
            {
                var materialTags = ShaderGenerator.BuildMaterialTags(pbrMasterNode.surfaceType);
                var tagsBuilder  = new ShaderStringBuilder(0);
                materialTags.GetTags(tagsBuilder, LightweightRenderPipeline.k_ShaderTagName);
                subShader.AppendLines(tagsBuilder.ToString());

                var materialOptions = ShaderGenerator.GetMaterialOptions(pbrMasterNode.surfaceType, pbrMasterNode.alphaMode, pbrMasterNode.twoSided.isOn);
                subShader.AppendLines(GetShaderPassFromTemplate(
                                          forwardTemplate,
                                          pbrMasterNode,
                                          pass,
                                          mode,
                                          materialOptions));

                subShader.AppendLines(GetShaderPassFromTemplate(
                                          extraTemplate,
                                          pbrMasterNode,
                                          m_DepthShadowPass,
                                          mode,
                                          materialOptions));
            }
            subShader.Append("CustomEditor \"UnityEditor.ShaderGraph.PBRMasterGUI\"");

            return(subShader.ToString());
        }
Ejemplo n.º 2
0
        public string GetSubshader(IMasterNode masterNode, GenerationMode mode, List <string> sourceAssetDependencyPaths = null)
        {
            if (sourceAssetDependencyPaths != null)
            {
                // LightWeightPBRSubShader.cs
                sourceAssetDependencyPaths.Add(AssetDatabase.GUIDToAssetPath("f37ee8a3fc1e43646bab579fc6c4c68d"));
            }

            var templatePath            = GetTemplatePath("AILWForwardPass.template", "2f6cfbf8aef97dc4d952a059147e69a6");
            var extraPassesTemplatePath = GetTemplatePath("AILWExtraPasses.template", "e700d3e5b71bb764f83ce12de610be58");

            if (!File.Exists(templatePath) || !File.Exists(extraPassesTemplatePath))
            {
                return(string.Empty);
            }

            if (sourceAssetDependencyPaths != null)
            {
                sourceAssetDependencyPaths.Add(templatePath);
                sourceAssetDependencyPaths.Add(extraPassesTemplatePath);
            }

            string forwardTemplate = File.ReadAllText(templatePath);
            string extraTemplate   = File.ReadAllText(extraPassesTemplatePath);

            var pbrMasterNode = masterNode as AILWMasterNode;
            var pass          = pbrMasterNode.model == AILWMasterNode.Model.Metallic ? m_ForwardPassMetallic : m_ForwardPassSpecular;
            var subShader     = new ShaderStringBuilder();

            subShader.AppendLine("SubShader");
            using (subShader.BlockScope())
            {
                var materialTags = ShaderGenerator.BuildMaterialTags(pbrMasterNode.surfaceType);
                var tagsBuilder  = new ShaderStringBuilder(0);
                materialTags.GetTags(tagsBuilder, LightweightRenderPipeline.k_ShaderTagName);
                subShader.AppendLines(tagsBuilder.ToString());

                var materialOptions = ShaderGenerator.GetMaterialOptions(pbrMasterNode.surfaceType, pbrMasterNode.alphaMode, pbrMasterNode.twoSided.isOn);
                subShader.AppendLines(GetShaderPassFromTemplate(
                                          forwardTemplate,
                                          pbrMasterNode,
                                          pass,
                                          mode,
                                          materialOptions));

                subShader.AppendLines(GetShaderPassFromTemplate(
                                          extraTemplate,
                                          pbrMasterNode,
                                          m_DepthShadowPass,
                                          mode,
                                          materialOptions));
            }
            subShader.Append("CustomEditor \"UnityEditor.ShaderGraph.PBRMasterGUI\"");

            return(subShader.ToString());
        }
        public static string GetSubShader <T>(T masterNode, SurfaceMaterialTags tags, SurfaceMaterialOptions options, Pass[] passes,
                                              GenerationMode mode, string customEditorPath = null, List <string> sourceAssetDependencyPaths = null) where T : IMasterNode
        {
            if (sourceAssetDependencyPaths != null)
            {
                var relativePath = "Packages/com.unity.render-pipelines.universal/";
                var fullPath     = Path.GetFullPath(relativePath);
                var shaderFiles  = Directory.GetFiles(Path.Combine(fullPath, "ShaderLibrary")).Select(x => Path.Combine(relativePath, x.Substring(fullPath.Length)));
                sourceAssetDependencyPaths.AddRange(shaderFiles);
            }

            var subShader = new ShaderStringBuilder();

            subShader.AppendLine("SubShader");
            using (subShader.BlockScope())
            {
                var tagsBuilder = new ShaderStringBuilder(0);
                tags.GetTags(tagsBuilder, UnityEngine.Rendering.Universal.UniversalRenderPipeline.k_ShaderTagName);
                subShader.AppendLines(tagsBuilder.ToString());

                foreach (Pass pass in passes)
                {
                    var templatePath = GetTemplatePath(pass.TemplatePath);
                    if (!File.Exists(templatePath))
                    {
                        continue;
                    }

                    if (sourceAssetDependencyPaths != null)
                    {
                        sourceAssetDependencyPaths.Add(templatePath);
                    }

                    string template = File.ReadAllText(templatePath);

                    subShader.AppendLines(GetShaderPassFromTemplate(
                                              template,
                                              masterNode,
                                              pass,
                                              mode,
                                              options));
                }
            }

            if (!string.IsNullOrEmpty(customEditorPath))
            {
                subShader.Append($"CustomEditor \"{customEditorPath}\"");
            }

            return(subShader.ToString());
        }
        public string GetSubshader(IMasterNode masterNode, GenerationMode mode, List <string> sourceAssetDependencyPaths = null)
        {
            if (sourceAssetDependencyPaths != null)
            {
                // LightWeightPBRSubShader.cs
                sourceAssetDependencyPaths.Add(AssetDatabase.GUIDToAssetPath("16b8a010f96947c4f866705d757bc0a3"));
            }

            var templatePath            = GetTemplatePath("lightweightToonForwardPass.template");
            var extraPassesTemplatePath = GetTemplatePath("lightweightToonExtraPasses.template");

            if (!File.Exists(templatePath) || !File.Exists(extraPassesTemplatePath))
            {
                return(string.Empty);
            }

            if (sourceAssetDependencyPaths != null)
            {
                sourceAssetDependencyPaths.Add(templatePath);
                sourceAssetDependencyPaths.Add(extraPassesTemplatePath);

                var relativePath = "Packages/com.unity.render-pipelines.lightweight/";
                var fullPath     = Path.GetFullPath(relativePath);
                var shaderFiles  = Directory.GetFiles(Path.Combine(fullPath, "ShaderLibrary")).Select(x => Path.Combine(relativePath, x.Substring(fullPath.Length)));
                sourceAssetDependencyPaths.AddRange(shaderFiles);
            }

            string forwardTemplate = File.ReadAllText(templatePath);
            string extraTemplate   = File.ReadAllText(extraPassesTemplatePath);

            var pbrMasterNode = masterNode as ToonMasterNode;
            var pass          = pbrMasterNode.model == ToonMasterNode.Model.Metallic ? m_ForwardPassMetallic : m_ForwardPassSpecular;
            var subShader     = new ShaderStringBuilder();

            subShader.AppendLine("SubShader");
            using (subShader.BlockScope())
            {
                var materialTags = ShaderGenerator.BuildMaterialTags(pbrMasterNode.surfaceType);
                var tagsBuilder  = new ShaderStringBuilder(0);
                materialTags.GetTags(tagsBuilder, LightweightRenderPipeline.k_ShaderTagName);
                subShader.AppendLines(tagsBuilder.ToString());

                var materialOptions = ShaderGenerator.GetMaterialOptions(pbrMasterNode.surfaceType, pbrMasterNode.alphaMode, pbrMasterNode.twoSided.isOn);
                subShader.AppendLines(GetShaderPassFromTemplate(
                                          forwardTemplate,
                                          pbrMasterNode,
                                          pass,
                                          mode,
                                          materialOptions));

                subShader.AppendLines(GetShaderPassFromTemplate(
                                          extraTemplate,
                                          pbrMasterNode,
                                          m_DepthShadowPass,
                                          mode,
                                          materialOptions));
            }
            subShader.Append("CustomEditor \"LiliumEditor.Toon.ToonMasterGUI\"");

            return(subShader.ToString());
        }