Example #1
0
 public LargePreview(PreviewRender.PreviewBuilder preview, ShaderDiagram.Document doc)
 {
     _preview = preview;
     _document = doc;
     InitializeComponent();
     SetStyle(System.Windows.Forms.ControlStyles.AllPaintingInWmPaint, true);
     SetStyle(System.Windows.Forms.ControlStyles.UserPaint, true);
 }
Example #2
0
 public LargePreview(PreviewRender.PreviewBuilder preview, ShaderDiagram.Document doc)
 {
     _preview  = preview;
     _document = doc;
     InitializeComponent();
     SetStyle(System.Windows.Forms.ControlStyles.AllPaintingInWmPaint, true);
     SetStyle(System.Windows.Forms.ControlStyles.UserPaint, true);
 }
Example #3
0
        public static bool FillInMaterialParameters(ShaderDiagram.Document document, HyperGraph.GraphControl graphControl)
        {
            //
            //      Look for new or removed material parameters
            //      and update the material parameters dictionary
            //
            Dictionary <String, String> newMaterialParameters = new Dictionary <String, String>();

            foreach (Node n in graphControl.Nodes)
            {
                if (n.Tag is ShaderParameterNodeTag && n.Items.Count() > 0)
                {
                    // look for a drop down list element -- this will tell us the type
                    ShaderFragmentArchive.Parameter.SourceType type =
                        ShaderFragmentArchive.Parameter.SourceType.System;
                    foreach (var i in n.Items)
                    {
                        if (i is HyperGraph.Items.NodeDropDownItem)
                        {
                            var dropDown   = (HyperGraph.Items.NodeDropDownItem)i;
                            var stringForm = dropDown.Items[dropDown.SelectedIndex];
                            type = ShaderFragmentNodeCreator.AsSourceType(stringForm);
                            break;
                        }
                    }

                    if (type == ShaderFragmentArchive.Parameter.SourceType.Material)
                    {
                        foreach (var i in n.Items)
                        {
                            if (i is ShaderFragmentNodeItem)
                            {
                                ShaderFragmentNodeItem item = (ShaderFragmentNodeItem)i;
                                if (item.Output != null)
                                {
                                    if (!newMaterialParameters.ContainsKey(item.ArchiveName))
                                    {
                                        var param = ShaderFragmentArchive.Archive.GetParameter(item.ArchiveName);
                                        if (param != null)
                                        {
                                            newMaterialParameters.Add(item.ArchiveName, param.Type);
                                        }
                                        else
                                        {
                                            newMaterialParameters.Add(item.ArchiveName, "<<unknown>>");
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            bool          didSomething    = false;
            List <String> entriesToRemove = new List <String>();

            foreach (String s in document.PreviewMaterialState.Keys)
            {
                if (!newMaterialParameters.ContainsKey(s))
                {
                    entriesToRemove.Add(s);
                }
            }

            foreach (String s in entriesToRemove)
            {
                document.PreviewMaterialState.Remove(s);      // does this invalidate the iteration?
                didSomething = true;
            }

            foreach (KeyValuePair <String, String> s in newMaterialParameters)
            {
                if (!document.PreviewMaterialState.ContainsKey(s.Key))
                {
                    var           parameter = ShaderFragmentArchive.Archive.GetParameter(s.Key);
                    System.Object def       = null;
                    if (parameter != null && parameter.Default != null && parameter.Default.Length > 0)
                    {
                        def = ShaderPatcherLayer.TypeRules.CreateFromString(parameter.Default, parameter.Type);
                    }

                    var parameterName = s.Key;
                    if (parameter != null)
                    {
                        parameterName = parameter.Name;
                    }

                    if (def != null)
                    {
                        document.PreviewMaterialState.Add(parameterName, def);
                    }
                    else
                    {
                        document.PreviewMaterialState.Add(parameterName, ShaderPatcherLayer.TypeRules.CreateDefaultObject(s.Value));
                    }

                    didSomething = true;
                }
            }

            return(didSomething);
        }
Example #4
0
        public static Node CreateNode(ShaderFragmentArchive.Function fn, String archiveName, HyperGraph.GraphControl graphControl, ShaderDiagram.Document doc)
        {
            var node = new Node(fn.Name);

            node.Tag = new ShaderProcedureNodeTag(archiveName);
            node.AddItem(new ShaderFragmentPreviewItem(graphControl, doc));
            foreach (var param in fn.InputParameters)
            {
                node.AddItem(new ShaderFragmentNodeItem(param.Name, param.Type, archiveName + ":" + param.Name, true, false));
            }
            foreach (var output in fn.Outputs)
            {
                node.AddItem(new ShaderFragmentNodeItem(output.Name, output.Type, archiveName + ":" + output.Name, false, true));
            }
            return(node);
        }
Example #5
0
 public ShaderFragmentPreviewItem(HyperGraph.GraphControl graphControl, ShaderDiagram.Document doc)
 {
     _graphControl = graphControl; _document = doc; _builder = null;
 }
Example #6
0
 public ShaderFragmentPreviewItem(HyperGraph.GraphControl graphControl, ShaderDiagram.Document doc)
 {
     _graphControl = graphControl; _document = doc; _builder = null;
 }
Example #7
0
        public static void AddToHyperGraph(ShaderPatcherLayer.NodeGraph nodeGraph, HyperGraph.GraphControl graphControl, ShaderDiagram.Document doc)
        {
            //
            //      Convert from the "ShaderPatcherLayer" representation back to
            //      our graph control nodes.
            //
            //      This is required for robust serialisation. We can't easily
            //      serialise in and out the graph control objects directly, because
            //      it risks problems if the rendering code or shader fragment objects
            //      change. That is, it's not very version-robust.
            //
            //      It's better to serialise a slightly higher level representation
            //      that just contains the node names and connections. That way, we
            //      can adapt to changes in the tool and data.
            //
            {
                // --------< Basic Nodes >--------
                var newNodes            = new Dictionary <int, Node>();
                var nodeIdToControlNode = new Dictionary <UInt64, Node>();
                foreach (var n in nodeGraph.Nodes)
                {
                    if (!newNodes.ContainsKey(n.VisualNodeId))
                    {
                        if (n.NodeType == ShaderPatcherLayer.Node.Type.Procedure)
                        {
                            var fn = ShaderFragmentArchive.Archive.GetFunction(n.FragmentArchiveName);
                            if (fn != null)
                            {
                                var visualNode = nodeGraph.VisualNodes[n.VisualNodeId];
                                var newNode    = ShaderFragmentNodeCreator.CreateNode(fn, n.FragmentArchiveName, graphControl, doc);
                                newNode.Location              = visualNode.Location;
                                newNode.Collapsed             = visualNode.State == ShaderPatcherLayer.VisualNode.StateType.Collapsed;
                                newNodes[n.VisualNodeId]      = newNode;
                                nodeIdToControlNode[n.NodeId] = newNode;
                            }
                        }
                        else
                        {
                            var ps = ShaderFragmentArchive.Archive.GetParameterStruct(n.FragmentArchiveName);
                            if (ps != null)
                            {
                                var visualNode = nodeGraph.VisualNodes[n.VisualNodeId];
                                var newNode    = ShaderFragmentNodeCreator.CreateParameterNode(ps, n.FragmentArchiveName, AsSourceType(n.NodeType));
                                newNode.Location              = visualNode.Location;
                                newNode.Collapsed             = visualNode.State == ShaderPatcherLayer.VisualNode.StateType.Collapsed;
                                newNodes[n.VisualNodeId]      = newNode;
                                nodeIdToControlNode[n.NodeId] = newNode;
                            }
                        }
                    }
                }

                graphControl.AddNodes(newNodes.Values);

                // --------< Node Connections >--------
                foreach (var c in nodeGraph.NodeConnections)
                {
                    if (nodeIdToControlNode.ContainsKey(c.InputNodeID) && nodeIdToControlNode.ContainsKey(c.OutputNodeID))
                    {
                        var inputItem = FindOrCreateNodeItem(nodeIdToControlNode[c.InputNodeID],
                                                             (item) => (item.Output != null && item.Output.Enabled && item is ShaderFragmentNodeItem && ((ShaderFragmentNodeItem)item).Name.Equals(c.InputParameterName)),
                                                             () => new ShaderFragmentNodeItem("return", c.InputType, null, false, true));

                        var outputItem = FindOrCreateNodeItem(nodeIdToControlNode[c.OutputNodeID],
                                                              (item) => (item.Input != null && item.Input.Enabled && item is ShaderFragmentNodeItem && ((ShaderFragmentNodeItem)item).Name.Equals(c.OutputParameterName)),
                                                              () => new ShaderFragmentNodeItem(c.OutputParameterName, c.OutputType, null, true, false));

                        graphControl.Connect(inputItem.Output, outputItem.Input);
                    }
                }

                // --------< Node Constant Connections >--------
                foreach (var c in nodeGraph.NodeConstantConnections)
                {
                    if (nodeIdToControlNode.ContainsKey(c.OutputNodeID))
                    {
                        var node       = nodeIdToControlNode[c.OutputNodeID];
                        var outputItem = FindOrCreateNodeItem(node,
                                                              (item) => (item.Input != null && item.Input.Enabled && item is ShaderFragmentNodeItem && ((ShaderFragmentNodeItem)item).Name.Equals(c.OutputParameterName)),
                                                              () => new ShaderFragmentNodeItem(c.OutputParameterName, "float", null, true, false));

                        var connection = new NodeConnection();
                        connection.To   = outputItem.Input;
                        connection.Name = c.Value;
                        node.AddConnection(connection);
                    }
                }
            }
        }