示例#1
0
        public static SlotReference DepthFirstCollectRedirectNodeFromNode(RedirectNodeData node)
        {
            var inputSlot = node.FindSlot <MaterialSlot>(RedirectNodeData.kInputSlotID);

            foreach (var edge in node.owner.GetEdges(inputSlot.slotReference))
            {
                // get the input details
                var outputSlotRef = edge.outputSlot;
                var inputNode     = outputSlotRef.node;
                // If this is a redirect node we continue to look for the top one
                if (inputNode is RedirectNodeData redirectNode)
                {
                    return(DepthFirstCollectRedirectNodeFromNode(redirectNode));
                }
                return(outputSlotRef);
            }
            // If no edges it is the first redirect node without an edge going into it and we should return the slot ref
            return(node.GetSlotReference(RedirectNodeData.kInputSlotID));
        }
        public void RedirectNodes_DoNotAffectOutput()
        {
            foreach (var slot in m_CFNode.GetInputSlots <MaterialSlot>())
            {
                var originalValue = m_CFNode.GetSlotValue(slot.id, GenerationMode.ForReals);

                // Should only be one edge per slot on this graph
                var edge = m_Graph.GetEdges(slot.slotReference).FirstOrDefault();
                if (edge == null)
                {
                    continue;
                }

                var outputNode = edge.outputSlot.node;
                var outputSlot = outputNode.GetOutputSlots <MaterialSlot>().First(s => s.id == edge.outputSlot.slotId);

                var redirNode = RedirectNodeData.Create(m_Graph, outputSlot.valueType, Vector2.zero, edge.inputSlot, edge.outputSlot, null);

                m_Graph.ValidateGraph();
                CompileNodeShader(m_CFNode, GenerationMode.Preview, m_CFNode.name);
                CompileNodeShader(null, GenerationMode.ForReals, "Master Stack Shader");

                // Verify all errors are expected
                foreach (var message in m_Graph.messageManager.GetNodeMessages())
                {
                    if (message.Value.Exists(msg => msg.severity == ShaderCompilerMessageSeverity.Error))
                    {
                        Assert.Fail(message.Value.FirstOrDefault().message);
                    }
                }

                var redirectedValue = m_CFNode.GetSlotValue(slot.id, GenerationMode.ForReals);
                var previewValue    = m_CFNode.GetSlotValue(slot.id, GenerationMode.Preview);

                Assert.AreEqual(originalValue, redirectedValue, $"Value of slot {slot.displayName} changed in final shader with redirect node");
                Assert.AreEqual(originalValue, previewValue, $"Value of slot {slot.displayName} changed in preview shader with redirect node");

                m_Graph.RemoveNode(redirNode);
                m_Graph.ClearErrorsForNode(m_CFNode);
            }
        }