bool GenerateUberShader(ICollection <INode> errNodes, out GenerationResults results) { ShaderUtil.ClearCachedData(m_UberShader); results = m_Graph.GetUberColorShader(errNodes); m_OutputIdName = results.outputIdProperty.referenceName; ShaderUtil.UpdateShaderAsset(m_UberShader, results.shader); return(ShaderUtil.ShaderHasError(m_UberShader)); }
void UpdateShaders() { if (m_DirtyShaders.Any()) { PropagateNodeSet(m_DirtyShaders); var masterNodes = new List <INode>(); var colorNodes = new List <INode>(); var wireframeNodes = new List <INode>(); foreach (var index in m_DirtyShaders) { var node = m_Graph.GetNodeFromTempId(m_Identifiers[index]) as AbstractMaterialNode; if (node == null) { continue; } var masterNode = node as IMasterNode; if (masterNode != null) { masterNodes.Add(node); } else if (node.previewMode == PreviewMode.Wireframe) { wireframeNodes.Add(node); } else { colorNodes.Add(node); } } var count = Math.Min(colorNodes.Count, 1) + masterNodes.Count; try { var i = 0; EditorUtility.DisplayProgressBar("Shader Graph", string.Format("Compiling preview shaders ({0}/{1})", i, count), 0f); foreach (var node in masterNodes) { UpdateShader(node.tempId); i++; EditorUtility.DisplayProgressBar("Shader Graph", string.Format("Compiling preview shaders ({0}/{1})", i, count), 0f); } if (colorNodes.Count > 0) { var results = m_Graph.GetUberColorShader(); m_OutputIdName = results.outputIdProperty.referenceName; ShaderUtil.UpdateShaderAsset(m_ColorShader, results.shader); var debugOutputPath = DefaultShaderIncludes.GetDebugOutputPath(); if (debugOutputPath != null) { File.WriteAllText(debugOutputPath + "/ColorShader.shader", (results.shader ?? "null").Replace("UnityEngine.MaterialGraph", "Generated")); } bool uberShaderHasError = false; if (MaterialGraphAsset.ShaderHasError(m_ColorShader)) { var errors = MaterialGraphAsset.GetShaderErrors(m_ColorShader); var message = new ShaderStringBuilder(); message.AppendLine(@"Preview shader for graph has {0} error{1}:", errors.Length, errors.Length != 1 ? "s" : ""); foreach (var error in errors) { INode node; try { node = results.sourceMap.FindNode(error.line); message.AppendLine("Shader compilation error in {3} at line {1} (on {2}):\n{0}", error.message, error.line, error.platform, node != null ? string.Format("node {0} ({1})", node.name, node.guid) : "graph"); message.AppendLine(error.messageDetails); message.AppendNewLine(); } catch { message.AppendLine("Shader compilation error in {3} at line {1} (on {2}):\n{0}", error.message, error.line, error.platform, "graph"); } } Debug.LogWarning(message.ToString()); ShaderUtil.ClearShaderErrors(m_ColorShader); ShaderUtil.UpdateShaderAsset(m_ColorShader, k_EmptyShader); uberShaderHasError = true; } foreach (var node in colorNodes) { var renderData = GetRenderData(node.tempId); if (renderData == null) { continue; } var shaderData = renderData.shaderData; shaderData.shader = m_ColorShader; shaderData.hasError = uberShaderHasError; } i++; EditorUtility.DisplayProgressBar("Shader Graph", string.Format("Compiling preview shaders ({0}/{1})", i, count), 0f); } } finally { EditorUtility.ClearProgressBar(); } // Union dirty shaders into dirty previews m_DirtyPreviews.UnionWith(m_DirtyShaders); m_DirtyShaders.Clear(); } }