Example #1
0
 public static void EditParameter(HyperGraph.GraphControl graphControl, String archiveName)
 {
     //var parameter = ShaderFragmentArchive.Archive.GetParameter(archiveName);
     //if (parameter != null)
     //{
     //    var dialog = new ParameterDialog();
     //    dialog.PullFrom(parameter);
     //    var result = dialog.ShowDialog();
     //    if (result == System.Windows.Forms.DialogResult.OK)
     //    {
     //        var newParam = dialog.Result;
     //
     //        //
     //        //      Have to also update the "Name" and "Type"
     //        //      fields of any ShaderFragmentNodeItems that are
     //        //      using this parameter
     //        //          (also changing the source could change input -> output...)
     //        //
     //
     //        newParam.Name = IdentifierSafeName(newParam.Name);
     //        if (newParam.ArchiveName.Length != 0
     //            && newParam.ArchiveName.Substring(0, 12).Equals("LocalArchive"))
     //        {
     //            newParam.ArchiveName = "LocalArchive[" + newParam.Name + "]";
     //        }
     //
     //        var oldArchiveName = parameter.ArchiveName;
     //        parameter.DeepCopyFrom(newParam);
     //        ShaderFragmentArchive.Archive.RenameParameter(parameter, oldArchiveName);
     //
     //        ShaderFragmentNodeUtil.UpdateGraphConnectionsForParameter(
     //            graphControl, oldArchiveName, parameter.ArchiveName);
     //    }
     //}
 }
Example #2
0
        public ExampleForm(ExportProvider exportProvider)
        {
            _shaderFragments = exportProvider.GetExport <ShaderFragmentArchive.Archive>().Value;
            _nodeCreator     = exportProvider.GetExport <NodeEditorCore.IShaderFragmentNodeCreator>().Value;
            _modelConversion = exportProvider.GetExport <NodeEditorCore.IModelConversion>().Value;

            InitializeComponent();

            _hyperGraphModel = new HyperGraph.GraphModel();
            _hyperGraphModel.CompatibilityStrategy = _nodeCreator.CreateCompatibilityStrategy();

            _graphAdapter = new HyperGraph.GraphControl();
            _graphAdapter.Attach(graphControl);
            _graphAdapter.HighlightCompatible = true;
            _graphAdapter.LargeGridStep       = 160F;
            _graphAdapter.LargeStepGridColor  = System.Drawing.Color.FromArgb(((int)(((byte)(90)))), ((int)(((byte)(90)))), ((int)(((byte)(90)))));
            _graphAdapter.ShowLabels          = false;
            _graphAdapter.SmallGridStep       = 20F;
            _graphAdapter.SmallStepGridColor  = System.Drawing.Color.FromArgb(((int)(((byte)(80)))), ((int)(((byte)(80)))), ((int)(((byte)(80)))));

            _graphAdapter.Model     = _hyperGraphModel;
            _graphAdapter.Selection = new GraphSelection();
            _graphAdapter.Selection.SelectionChanged += OnFocusChanged;

            graphControl.MouseEnter += OnGraphMouseEnter;
            graphControl.Paint      += graphControl_Paint;

            _tabGroupTextureNode = new RibbonTabGroup(_ribbon, (uint)RibbonMarkupCommands.cmdTabGroupTextureNode);

            _showLabels = new RibbonLib.Controls.RibbonCheckBox(_ribbon, (uint)RibbonMarkupCommands.cmdShowLabels);
            _showLabels.ExecuteEvent += new EventHandler <ExecuteEventArgs>(OnShowLabelsChanged);

            _generateTestScript = new RibbonLib.Controls.RibbonButton(_ribbon, (uint)RibbonMarkupCommands.cmdButtonTestScript);
            _generateTestScript.ExecuteEvent += new EventHandler <ExecuteEventArgs>(OnGenerateTestScript);

            _saveAsButton = new RibbonLib.Controls.RibbonButton(_ribbon, (uint)RibbonMarkupCommands.cmdSaveAs);
            _saveAsButton.ExecuteEvent += new EventHandler <ExecuteEventArgs>(OnSaveAs);

            _loadButton = new RibbonLib.Controls.RibbonButton(_ribbon, (uint)RibbonMarkupCommands.cmdLoad);
            _loadButton.ExecuteEvent += new EventHandler <ExecuteEventArgs>(OnLoad);

            var fragmentTreeModel = exportProvider.GetExport <NodeEditorCore.ShaderFragmentArchiveModel>().Value;

            _fragmentTree.Model                 = new Aga.Controls.Tree.SortedTreeModel(fragmentTreeModel);
            _fragmentTree.ItemDrag             += new ItemDragEventHandler(OnFragmentTreeItemDrag);
            _fragmentTree.NodeMouseDoubleClick += new EventHandler <Aga.Controls.Tree.TreeNodeAdvMouseEventArgs>(OnFragmentTreeItemDoubleClick);

            // _materialParametersGrid.SelectedObject = new DictionaryPropertyGridAdapter(_document.PreviewMaterialState);

            try
            {
                LoadFile("defaultload.sh");
            }
            catch (System.Exception) {}
        }
Example #3
0
		public ExampleForm(ExportProvider exportProvider)
		{
            _shaderFragments = exportProvider.GetExport<ShaderFragmentArchive.Archive>().Value;
            _nodeCreator = exportProvider.GetExport<NodeEditorCore.IShaderFragmentNodeCreator>().Value;
            _modelConversion = exportProvider.GetExport<NodeEditorCore.IModelConversion>().Value;

			InitializeComponent();

            _hyperGraphModel = new HyperGraph.GraphModel();
            _hyperGraphModel.CompatibilityStrategy = _nodeCreator.CreateCompatibilityStrategy();

            _graphAdapter = new HyperGraph.GraphControl();
            _graphAdapter.Attach(graphControl);
            _graphAdapter.HighlightCompatible = true;
            _graphAdapter.LargeGridStep = 160F;
            _graphAdapter.LargeStepGridColor = System.Drawing.Color.FromArgb(((int)(((byte)(90)))), ((int)(((byte)(90)))), ((int)(((byte)(90)))));
            _graphAdapter.ShowLabels = false;
            _graphAdapter.SmallGridStep = 20F;
            _graphAdapter.SmallStepGridColor = System.Drawing.Color.FromArgb(((int)(((byte)(80)))), ((int)(((byte)(80)))), ((int)(((byte)(80)))));

            _graphAdapter.Model = _hyperGraphModel;
            _graphAdapter.Selection = new GraphSelection();
            _graphAdapter.Selection.SelectionChanged += OnFocusChanged;

            graphControl.MouseEnter += OnGraphMouseEnter;
            graphControl.Paint += graphControl_Paint;

            _tabGroupTextureNode = new RibbonTabGroup(_ribbon, (uint)RibbonMarkupCommands.cmdTabGroupTextureNode);

            _showLabels = new RibbonLib.Controls.RibbonCheckBox(_ribbon, (uint)RibbonMarkupCommands.cmdShowLabels);
            _showLabels.ExecuteEvent += new EventHandler<ExecuteEventArgs>(OnShowLabelsChanged);

            _generateTestScript = new RibbonLib.Controls.RibbonButton(_ribbon, (uint)RibbonMarkupCommands.cmdButtonTestScript);
            _generateTestScript.ExecuteEvent += new EventHandler<ExecuteEventArgs>(OnGenerateTestScript);

            _saveAsButton = new RibbonLib.Controls.RibbonButton(_ribbon, (uint)RibbonMarkupCommands.cmdSaveAs);
            _saveAsButton.ExecuteEvent += new EventHandler<ExecuteEventArgs>(OnSaveAs);

            _loadButton = new RibbonLib.Controls.RibbonButton(_ribbon, (uint)RibbonMarkupCommands.cmdLoad);
            _loadButton.ExecuteEvent += new EventHandler<ExecuteEventArgs>(OnLoad);

            var fragmentTreeModel = exportProvider.GetExport<NodeEditorCore.ShaderFragmentArchiveModel>().Value;
            _fragmentTree.Model = new Aga.Controls.Tree.SortedTreeModel(fragmentTreeModel);
            _fragmentTree.ItemDrag += new ItemDragEventHandler(OnFragmentTreeItemDrag);
            _fragmentTree.NodeMouseDoubleClick += new EventHandler<Aga.Controls.Tree.TreeNodeAdvMouseEventArgs>(OnFragmentTreeItemDoubleClick);

            // _materialParametersGrid.SelectedObject = new DictionaryPropertyGridAdapter(_document.PreviewMaterialState);

            try
            {
                LoadFile("defaultload.sh");
            }
            catch(System.Exception) {}
		}
Example #4
0
 public static Node GetShaderFragmentNode(HyperGraph.GraphControl graphControl, UInt64 id)
 {
     foreach (Node n in graphControl.Nodes)
     {
         if (n.Tag is ShaderFragmentNodeTag &&
             ((ShaderFragmentNodeTag)n.Tag).Id == (UInt64)id)
         {
             return(n);
         }
     }
     return(null);
 }
Example #5
0
 public static void InvalidateAttachedConstants(HyperGraph.GraphControl graphControl)
 {
     foreach (Node n in graphControl.Nodes)
     {
         foreach (NodeItem i in n.Items)
         {
             if (i is ShaderFragmentPreviewItem)
             {
                 ((ShaderFragmentPreviewItem)i).InvalidateAttachedConstants();
             }
         }
     }
 }
Example #6
0
        public static void UpdateGraphConnectionsForParameter(
            HyperGraph.GraphControl graphControl,
            String oldArchiveName, String newArchiveName)
        {
            //      Look for connections in the graph using the "oldArchiveName" and
            //      update them with parameter state information from "newArchiveName"

            foreach (var n in graphControl.Nodes)
            {
                foreach (var item in n.Items)
                {
                    if (item is ShaderFragmentNodeItem)
                    {
                        var i = (ShaderFragmentNodeItem)item;
                        if (i.ArchiveName != null && i.ArchiveName.Equals(oldArchiveName))
                        {
                            i.ArchiveName = newArchiveName;

                            //      Name and Type are cached on the connector
                            //      so, we have to update them with the latest info...
                            var param = ShaderFragmentArchive.Archive.GetParameter(newArchiveName);
                            if (param != null)
                            {
                                i.Name = param.Name;
                                i.Type = param.Type;
                            }
                            else
                            {
                                i.Name = "<<unknown>>";
                                i.Type = "<<unknown>>";
                            }
                        }
                    }
                }
            }
        }
Example #7
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 #8
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 #9
0
 public ShaderFragmentPreviewItem(HyperGraph.GraphControl graphControl, ShaderDiagram.Document doc)
 {
     _graphControl = graphControl; _document = doc; _builder = null;
 }
Example #10
0
 public ShaderFragmentPreviewItem(HyperGraph.GraphControl graphControl, ShaderDiagram.Document doc)
 {
     _graphControl = graphControl; _document = doc; _builder = null;
 }
Example #11
0
        //
        //      Convert from the "ViewModel" to the "Model"
        //
        //      We don't maintain the ShaderPatcherLayer.NodeGraph representation
        //      permanently... But we need this for serialization and shader
        //      generation operations
        //
        //      So, let's just build it from the graph control object.
        //
        public static ShaderPatcherLayer.NodeGraph ToShaderPatcherLayer(HyperGraph.GraphControl graphControl)
        {
            ShaderPatcherLayer.NodeGraph nodeGraph          = new ShaderPatcherLayer.NodeGraph();
            Dictionary <Node, int>       nodeToVisualNodeId = new Dictionary <Node, int>();

            foreach (Node n in graphControl.Nodes)
            {
                if (n.Tag is ShaderFragmentNodeTag)
                {
                    ShaderFragmentNodeTag   nTag       = (ShaderFragmentNodeTag)n.Tag;
                    ShaderPatcherLayer.Node resultNode = new ShaderPatcherLayer.Node();
                    resultNode.FragmentArchiveName = nTag.ArchiveName;
                    resultNode.NodeId = nTag.Id;

                    if (n.Tag is ShaderParameterNodeTag)
                    {
                        //  This is a hack... But there should be a drop down list that
                        //  can tell us the type of this parameter struct box.
                        foreach (var i in n.Items)
                        {
                            if (i is HyperGraph.Items.NodeDropDownItem)
                            {
                                var dropDown        = (HyperGraph.Items.NodeDropDownItem)i;
                                var stringForm      = dropDown.Items[dropDown.SelectedIndex];
                                var parameterSource = ShaderFragmentNodeCreator.AsSourceType(stringForm);
                                resultNode.NodeType = AsNodeType(parameterSource);
                            }
                        }
                    }
                    else
                    {
                        resultNode.NodeType = ShaderPatcherLayer.Node.Type.Procedure;
                    }

                    {
                        if (nodeToVisualNodeId.ContainsKey(n))
                        {
                            resultNode.VisualNodeId = nodeToVisualNodeId[n];
                        }
                        else
                        {
                            resultNode.VisualNodeId = nodeGraph.VisualNodes.Count();
                            nodeToVisualNodeId.Add(n, resultNode.VisualNodeId);
                            var visualNode = new ShaderPatcherLayer.VisualNode();
                            visualNode.Location = n.Location;
                            if (n.Collapsed)
                            {
                                visualNode.State = ShaderPatcherLayer.VisualNode.StateType.Collapsed;
                            }
                            else
                            {
                                visualNode.State = ShaderPatcherLayer.VisualNode.StateType.Normal;
                            }
                            nodeGraph.VisualNodes.Add(visualNode);
                        }
                    }

                    nodeGraph.Nodes.Add(resultNode);

                    foreach (NodeConnection connection in n.Connections)
                    {
                        if (connection.From == null)
                        {
                            // this is a direct constant connection. It connects the value either to a constant value, or some named variable
                            if (connection.To != null)
                            {
                                Node destination = connection.To.Node;
                                if (destination.Tag is ShaderFragmentNodeTag)
                                {
                                    ShaderFragmentNodeTag dTag = (ShaderFragmentNodeTag)destination.Tag;
                                    ShaderPatcherLayer.NodeConstantConnection resultConnection = new ShaderPatcherLayer.NodeConstantConnection();
                                    resultConnection.Value        = connection.Name;
                                    resultConnection.OutputNodeID = dTag.Id;
                                    if (connection.To.Item is ShaderFragmentNodeItem)
                                    {
                                        ShaderFragmentNodeItem destinationItem = (ShaderFragmentNodeItem)connection.To.Item;
                                        resultConnection.OutputParameterName = destinationItem.Name;
                                    }

                                    nodeGraph.NodeConstantConnections.Add(resultConnection);
                                }
                            }
                        }
                        else if (connection.From.Node == n)
                        {
                            // This is an output to the next node
                            Node destination = connection.To.Node;
                            if (destination.Tag is ShaderFragmentNodeTag)
                            {
                                ShaderFragmentNodeTag             dTag             = (ShaderFragmentNodeTag)destination.Tag;
                                ShaderPatcherLayer.NodeConnection resultConnection = new ShaderPatcherLayer.NodeConnection();
                                resultConnection.InputNodeID  = nTag.Id;
                                resultConnection.OutputNodeID = dTag.Id;
                                if (connection.To.Item is ShaderFragmentNodeItem)
                                {
                                    ShaderFragmentNodeItem destinationItem = (ShaderFragmentNodeItem)connection.To.Item;
                                    resultConnection.OutputParameterName = destinationItem.Name;
                                    resultConnection.OutputType          = TypeFromNodeItem(destinationItem);
                                }
                                if (connection.From.Item is ShaderFragmentNodeItem)
                                {
                                    ShaderFragmentNodeItem sourceItem = (ShaderFragmentNodeItem)connection.From.Item;
                                    resultConnection.InputParameterName = sourceItem.Name;
                                    resultConnection.InputType          = TypeFromNodeItem(sourceItem);
                                }

                                nodeGraph.NodeConnections.Add(resultConnection);
                            }
                        }
                    }
                }
            }

            return(nodeGraph);
        }
Example #12
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);
                    }
                }
            }
        }