public override List <Port> GetCompatiblePorts(Port startAnchor, NodeAdapter nodeAdapter) { var compatibleAnchors = new List <Port>(); var startSlot = startAnchor.GetSlot(); if (startSlot == null) { return(compatibleAnchors); } var startStage = startSlot.shaderStage; if (startStage == ShaderStage.Dynamic) { startStage = NodeUtils.FindEffectiveShaderStage(startSlot.owner, startSlot.isOutputSlot); } foreach (var candidateAnchor in ports.ToList()) { var candidateSlot = candidateAnchor.GetSlot(); if (!startSlot.IsCompatibleWith(candidateSlot)) { continue; } if (startStage != ShaderStage.Dynamic) { var candidateStage = candidateSlot.shaderStage; if (candidateStage == ShaderStage.Dynamic) { candidateStage = NodeUtils.FindEffectiveShaderStage(candidateSlot.owner, !startSlot.isOutputSlot); } if (candidateStage != ShaderStage.Dynamic && candidateStage != startStage) { continue; } } compatibleAnchors.Add(candidateAnchor); } return(compatibleAnchors); }
void UpdateShader(Identifier nodeId) { var node = m_Graph.GetNodeFromTempId(nodeId) as AbstractMaterialNode; if (node == null) { return; } var renderData = Get(m_RenderDatas, nodeId); if (renderData == null || renderData.shaderData == null) { return; } var shaderData = renderData.shaderData; if (!(node is IMasterNode) && (!node.hasPreview || NodeUtils.FindEffectiveShaderStage(node, true) == ShaderStage.Vertex)) { shaderData.shaderString = null; } else { var masterNode = node as IMasterNode; if (masterNode != null) { List <PropertyCollector.TextureInfo> configuredTextures; shaderData.shaderString = masterNode.GetShader(GenerationMode.Preview, node.name, out configuredTextures); } else { shaderData.shaderString = m_Graph.GetPreviewShader(node).shader; } } #if UNITY_SHADER_GRAPH_DEVMODE File.WriteAllText(Application.dataPath + "/../GeneratedShader.shader", (shaderData.shaderString ?? "null").Replace("UnityEngine.MaterialGraph", "Generated")); #endif if (string.IsNullOrEmpty(shaderData.shaderString)) { if (shaderData.shader != null) { ShaderUtil.ClearShaderErrors(shaderData.shader); Object.DestroyImmediate(shaderData.shader, true); shaderData.shader = null; } return; } if (shaderData.shader == null) { shaderData.shader = ShaderUtil.CreateShaderAsset(shaderData.shaderString); shaderData.shader.hideFlags = HideFlags.HideAndDontSave; } else { ShaderUtil.ClearShaderErrors(shaderData.shader); ShaderUtil.UpdateShaderAsset(shaderData.shader, shaderData.shaderString); } // Debug output #if UNITY_SHADER_GRAPH_DEVMODE var message = "RecreateShader: " + node.GetVariableNameForNode() + Environment.NewLine + shaderData.shaderString; #endif if (MaterialGraphAsset.ShaderHasError(shaderData.shader)) { shaderData.hasError = true; Debug.LogWarning(message); ShaderUtil.ClearShaderErrors(shaderData.shader); Object.DestroyImmediate(shaderData.shader, true); shaderData.shader = null; } else { shaderData.hasError = false; } }