Exemplo n.º 1
0
        /// <summary>
        /// SERIALIZATION: Creates a NodeGraphView from a Serialized XML Copy
        /// </summary>
        /// <param name="p_XmlTreeNode">the parent XmlTreeNode used in serialization</param>
        /// <param name="p_Panel">the panel that will contain this NodeGraphView</param>
        public NodeGraphView(XmlTreeNode p_XmlTreeNode, NodeGraphPanel p_Panel)
        {
            System.Globalization.CultureInfo v_IntlCultureInfo = new System.Globalization.CultureInfo("en-us");
            this.m_oPanel = p_Panel;
            this.ViewX    = int.Parse(p_XmlTreeNode.m_attributes["ViewX"]);
            this.ViewY    = int.Parse(p_XmlTreeNode.m_attributes["ViewY"]);
            this.ViewZoom = float.Parse(p_XmlTreeNode.m_attributes["ViewZoom"], v_IntlCultureInfo);


            this.m_NodeCollection = new List <NodeGraphNode>();

            XmlTreeNode v_NodesXml = p_XmlTreeNode.GetFirstChild("NodeGraphNodeCollection");

            foreach (XmlTreeNode i_ChildNode in v_NodesXml.m_childNodes)
            {
                this.m_NodeCollection.Add(NodeGraphNode.DeserializeFromXML(i_ChildNode, this));
            }


            this.m_Links = new List <NodeGraphLink>();

            XmlTreeNode v_LinksXml = p_XmlTreeNode.GetFirstChild("NodeGraphLinkCollection");

            foreach (XmlTreeNode i_ChildLink in v_LinksXml.m_childNodes)
            {
                this.m_Links.Add(NodeGraphLink.DeserializeFromXML(i_ChildLink, this));
            }

            this.m_SelectedItems = new List <NodeGraphNode>();
        }
Exemplo n.º 2
0
 /// <summary>
 /// Creates a new NodeGraphView in a NodeGraphpanel
 /// </summary>
 /// <param name="p_Panel"></param>
 public NodeGraphView(NodeGraphPanel p_Panel)
 {
     this.m_NodeCollection = new List<NodeGraphNode>();
     this.m_SelectedItems = new List<NodeGraphNode>();
     this.m_Links = new List<NodeGraphLink>();
     this.ViewX = 0;
     this.ViewY = 0;
     this.ViewZoom = 1.0f;
     this.CurrentViewZoom = 1.0f;
     this.m_oPanel = p_Panel;
 }
Exemplo n.º 3
0
 /// <summary>
 /// Creates a new NodeGraphView in a NodeGraphpanel
 /// </summary>
 /// <param name="p_Panel"></param>
 public NodeGraphView(NodeGraphPanel p_Panel)
 {
     this.m_NodeCollection          = new List <NodeGraphNode>();
     this.m_NodeConnectorCollection = new List <NodeGraphConnector>();
     this.m_SelectedItems           = new List <NodeGraphNode>();
     this.m_Links         = new List <NodeGraphLink>();
     this.ViewX           = 0;
     this.ViewY           = 0;
     this.ViewZoom        = 1.0f;
     this.CurrentViewZoom = 1.0f;
     this.m_oPanel        = p_Panel;
 }
Exemplo n.º 4
0
        private void CreateGraphView()
        {
            this.nodeGraphPanelAlt = new NodeGraphControl.NodeGraphPanel();
            this.Controls.Add(this.nodeGraphPanelAlt);


            this.nodeGraphPanelAlt.BackColor                     = System.Drawing.Color.DarkGray;
            this.nodeGraphPanelAlt.ConnectorFillColor            = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))));
            this.nodeGraphPanelAlt.ConnectorFillSelectedColor    = System.Drawing.Color.FromArgb(((int)(((byte)(32)))), ((int)(((byte)(32)))), ((int)(((byte)(32)))));
            this.nodeGraphPanelAlt.ConnectorHitZoneBleed         = 4;
            this.nodeGraphPanelAlt.ConnectorOutlineColor         = System.Drawing.Color.FromArgb(((int)(((byte)(32)))), ((int)(((byte)(32)))), ((int)(((byte)(32)))));
            this.nodeGraphPanelAlt.ConnectorOutlineSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
            this.nodeGraphPanelAlt.ConnectorTextColor            = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
            this.nodeGraphPanelAlt.ContextMenuStrip              = this.contextMenuStrip;
            this.nodeGraphPanelAlt.Dock                          = System.Windows.Forms.DockStyle.Right;
            this.nodeGraphPanelAlt.DrawShadow                    = true;
            this.nodeGraphPanelAlt.EnableDrawDebug               = true;
            this.nodeGraphPanelAlt.GridAlpha                     = ((byte)(16));
            this.nodeGraphPanelAlt.GridPadding                   = 256;
            this.nodeGraphPanelAlt.LinkColor                     = System.Drawing.Color.FromArgb(((int)(((byte)(180)))), ((int)(((byte)(180)))), ((int)(((byte)(180)))));
            this.nodeGraphPanelAlt.LinkEditableColor             = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(255)))), ((int)(((byte)(0)))));
            this.nodeGraphPanelAlt.LinkHardness                  = 2F;
            this.nodeGraphPanelAlt.LinkVisualStyle               = NodeGraphControl.LinkVisualStyle.Curve;
            this.nodeGraphPanelAlt.Location                      = new System.Drawing.Point(0, 24);
            this.nodeGraphPanelAlt.Name                          = "nodeGraphPanelAlt";
            this.nodeGraphPanelAlt.NodeConnectorFont             = new System.Drawing.Font("Tahoma", 7F);
            this.nodeGraphPanelAlt.NodeConnectorTextZoomTreshold = 0.8F;
            this.nodeGraphPanelAlt.NodeFillColor                 = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(128)))), ((int)(((byte)(128)))));
            this.nodeGraphPanelAlt.NodeFillSelectedColor         = System.Drawing.Color.FromArgb(((int)(((byte)(160)))), ((int)(((byte)(128)))), ((int)(((byte)(100)))));
            this.nodeGraphPanelAlt.NodeHeaderColor               = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))));
            this.nodeGraphPanelAlt.NodeHeaderSize                = 24;
            this.nodeGraphPanelAlt.NodeOutlineColor              = System.Drawing.Color.FromArgb(((int)(((byte)(180)))), ((int)(((byte)(180)))), ((int)(((byte)(180)))));
            this.nodeGraphPanelAlt.NodeOutlineSelectedColor      = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(160)))), ((int)(((byte)(128)))));
            this.nodeGraphPanelAlt.NodeScaledConnectorFont       = new System.Drawing.Font("Tahoma", 7F);
            this.nodeGraphPanelAlt.NodeScaledTitleFont           = new System.Drawing.Font("Tahoma", 8F);
            this.nodeGraphPanelAlt.NodeSignalInvalidColor        = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))));
            this.nodeGraphPanelAlt.NodeSignalValidColor          = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(255)))), ((int)(((byte)(0)))));
            this.nodeGraphPanelAlt.NodeTextColor                 = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))));
            this.nodeGraphPanelAlt.NodeTextShadowColor           = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))));
            this.nodeGraphPanelAlt.NodeTitleFont                 = new System.Drawing.Font("Tahoma", 8F);
            this.nodeGraphPanelAlt.NodeTitleZoomThreshold        = 0.5F;
            this.nodeGraphPanelAlt.SelectionFillColor            = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(128)))), ((int)(((byte)(90)))), ((int)(((byte)(30)))));
            this.nodeGraphPanelAlt.SelectionOutlineColor         = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(255)))), ((int)(((byte)(180)))), ((int)(((byte)(60)))));
            this.nodeGraphPanelAlt.ShowGrid                      = true;
            this.nodeGraphPanelAlt.Size                          = new System.Drawing.Size(400, 400);
            this.nodeGraphPanelAlt.SmoothBehavior                = true;
            //this.nodeGraphPanelAlt.TabIndex = 4;
            //this.nodeGraphPanelAlt.onSelectionChanged += new NodeGraphControl.NodeGraphPanelSelectionEventHandler(this.nodeGraphPanel_onSelectionChanged);
            //this.nodeGraphPanelAlt.onSelectionCleared += new NodeGraphControl.NodeGraphPanelSelectionEventHandler(this.nodeGraphPanel_onSelectionCleared);
            //this.nodeGraphPanelAlt.Load += new System.EventHandler(this.nodeGraphPanel_Load);
            //this.nodeGraphPanelAlt.MouseMove += new System.Windows.Forms.MouseEventHandler(this.nodeGraphPanel_MouseMove);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Creates a new NodeGraphView in a NodeGraphpanel
 /// </summary>
 /// <param name="p_Panel"></param>
 public NodeGraphView(NodeGraphPanel p_Panel)
 {
     this.m_NodeCollection = new List<NodeGraphNode>();
     this.m_SelectedItems = new List<NodeGraphNode>();
     this.m_Links = new List<NodeGraphLink>();
     this.m_KnownDataTypes = new Dictionary<string,NodeGraphDataType>();
     this.RegisterDataType(new NodeGraphDataTypeBase());
     this.ViewX = 0;
     this.ViewY = 0;
     this.ViewZoom = 1.0f;
     this.CurrentViewZoom = 1.0f;
     this.m_oPanel = p_Panel;
 }
Exemplo n.º 6
0
 /// <summary>
 /// Creates a new NodeGraphView in a NodeGraphpanel
 /// </summary>
 /// <param name="p_Panel"></param>
 public NodeGraphView(NodeGraphPanel p_Panel)
 {
     this.m_NodeCollection = new List <NodeGraphNode>();
     this.m_SelectedItems  = new List <NodeGraphNode>();
     this.m_Links          = new List <NodeGraphLink>();
     this.m_KnownDataTypes = new Dictionary <string, NodeGraphDataType>();
     this.RegisterDataType(new NodeGraphDataTypeBase());
     this.ViewX           = 0;
     this.ViewY           = 0;
     this.ViewZoom        = 1.0f;
     this.CurrentViewZoom = 1.0f;
     this.m_oPanel        = p_Panel;
 }
Exemplo n.º 7
0
        /// <summary>
        /// SERIALIZATION: Creates a NodeGraphView from a Pipeline Descriptor
        /// </summary>
        /// <param name="p_Pipeline">Pipeline descriptor</param>
        /// <param name="p_Panel">the panel that will contain this NodeGraphView</param>
        public NodeGraphView(PipelineDescriptor p_Pipeline, NodeGraphPanel p_Panel)
        {
            //System.Globalization.CultureInfo v_IntlCultureInfo = new System.Globalization.CultureInfo("en-us");
            this.m_oPanel = p_Panel;
            this.ViewX    = 0;
            this.ViewY    = 0;
            this.ViewZoom = 1.0f;

            this.m_NodeCollection = new List <NodeGraphNode>();

            foreach (var module in p_Pipeline.modules)
            {
                this.m_NodeCollection.Add(NodeGraphNode.FromModuleDescriptor(module, this));
            }

            m_NodeConnectorCollection = new List <NodeGraphConnector>();

            foreach (var endpoint in p_Pipeline.inputEndpoints)
            {
                this.m_NodeConnectorCollection.Add(new NodeGraphConnector(endpoint, this, ConnectorType.InputConnector));
            }

            foreach (var endpoint in p_Pipeline.outputEndpoints)
            {
                this.m_NodeConnectorCollection.Add(new NodeGraphConnector(endpoint, this, ConnectorType.OutputConnector));
            }

            this.m_Links = new List <NodeGraphLink>();

            foreach (var connection in p_Pipeline.connections)
            {
                this.m_Links.Add(NodeGraphLink.FromConnectionDescriptor(connection, this));
            }

            for (int i = 0; i < this.m_NodeCollection.Count; i++)
            {
                //! TODO : normal algorythm for module placement
                this.m_NodeCollection[i].X = i * 100;
                this.m_NodeCollection[i].Y = i * 100;
                this.m_NodeCollection[i].UpdateHitRectangle();
            }

            this.m_SelectedItems = new List <NodeGraphNode>();
        }
Exemplo n.º 8
0
        private void CreateGraphView()
        {
            this.nodeGraphPanelAlt = new NodeGraphControl.NodeGraphPanel();
            this.Controls.Add(this.nodeGraphPanelAlt);


            this.nodeGraphPanelAlt.BackColor = System.Drawing.Color.DarkGray;
            this.nodeGraphPanelAlt.ConnectorFillColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))));
            this.nodeGraphPanelAlt.ConnectorFillSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(32)))), ((int)(((byte)(32)))), ((int)(((byte)(32)))));
            this.nodeGraphPanelAlt.ConnectorHitZoneBleed = 4;
            this.nodeGraphPanelAlt.ConnectorOutlineColor = System.Drawing.Color.FromArgb(((int)(((byte)(32)))), ((int)(((byte)(32)))), ((int)(((byte)(32)))));
            this.nodeGraphPanelAlt.ConnectorOutlineSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
            this.nodeGraphPanelAlt.ConnectorTextColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
            this.nodeGraphPanelAlt.ContextMenuStrip = this.contextMenuStrip;
            this.nodeGraphPanelAlt.Dock = System.Windows.Forms.DockStyle.Right;
            this.nodeGraphPanelAlt.DrawShadow = true;
            this.nodeGraphPanelAlt.EnableDrawDebug = true;
            this.nodeGraphPanelAlt.GridAlpha = ((byte)(16));
            this.nodeGraphPanelAlt.GridPadding = 256;
            this.nodeGraphPanelAlt.LinkColor = System.Drawing.Color.FromArgb(((int)(((byte)(180)))), ((int)(((byte)(180)))), ((int)(((byte)(180)))));
            this.nodeGraphPanelAlt.LinkEditableColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(255)))), ((int)(((byte)(0)))));
            this.nodeGraphPanelAlt.LinkHardness = 2F;
            this.nodeGraphPanelAlt.LinkVisualStyle = NodeGraphControl.LinkVisualStyle.Curve;
            this.nodeGraphPanelAlt.Location = new System.Drawing.Point(0, 24);
            this.nodeGraphPanelAlt.Name = "nodeGraphPanelAlt";
            this.nodeGraphPanelAlt.NodeConnectorFont = new System.Drawing.Font("Tahoma", 7F);
            this.nodeGraphPanelAlt.NodeConnectorTextZoomTreshold = 0.8F;
            this.nodeGraphPanelAlt.NodeFillColor = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(128)))), ((int)(((byte)(128)))));
            this.nodeGraphPanelAlt.NodeFillSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(160)))), ((int)(((byte)(128)))), ((int)(((byte)(100)))));
            this.nodeGraphPanelAlt.NodeHeaderColor = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))));
            this.nodeGraphPanelAlt.NodeHeaderSize = 24;
            this.nodeGraphPanelAlt.NodeOutlineColor = System.Drawing.Color.FromArgb(((int)(((byte)(180)))), ((int)(((byte)(180)))), ((int)(((byte)(180)))));
            this.nodeGraphPanelAlt.NodeOutlineSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(160)))), ((int)(((byte)(128)))));
            this.nodeGraphPanelAlt.NodeScaledConnectorFont = new System.Drawing.Font("Tahoma", 7F);
            this.nodeGraphPanelAlt.NodeScaledTitleFont = new System.Drawing.Font("Tahoma", 8F);
            this.nodeGraphPanelAlt.NodeSignalInvalidColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))));
            this.nodeGraphPanelAlt.NodeSignalValidColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(255)))), ((int)(((byte)(0)))));
            this.nodeGraphPanelAlt.NodeTextColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))));
            this.nodeGraphPanelAlt.NodeTextShadowColor = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))));
            this.nodeGraphPanelAlt.NodeTitleFont = new System.Drawing.Font("Tahoma", 8F);
            this.nodeGraphPanelAlt.NodeTitleZoomThreshold = 0.5F;
            this.nodeGraphPanelAlt.SelectionFillColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(128)))), ((int)(((byte)(90)))), ((int)(((byte)(30)))));
            this.nodeGraphPanelAlt.SelectionOutlineColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(255)))), ((int)(((byte)(180)))), ((int)(((byte)(60)))));
            this.nodeGraphPanelAlt.ShowGrid = true;
            this.nodeGraphPanelAlt.Size = new System.Drawing.Size(400, 400);
            this.nodeGraphPanelAlt.SmoothBehavior = true;
            //this.nodeGraphPanelAlt.TabIndex = 4;
            //this.nodeGraphPanelAlt.onSelectionChanged += new NodeGraphControl.NodeGraphPanelSelectionEventHandler(this.nodeGraphPanel_onSelectionChanged);
            //this.nodeGraphPanelAlt.onSelectionCleared += new NodeGraphControl.NodeGraphPanelSelectionEventHandler(this.nodeGraphPanel_onSelectionCleared);
            //this.nodeGraphPanelAlt.Load += new System.EventHandler(this.nodeGraphPanel_Load);
            //this.nodeGraphPanelAlt.MouseMove += new System.Windows.Forms.MouseEventHandler(this.nodeGraphPanel_MouseMove);
        }
Exemplo n.º 9
0
        /// <summary>
        /// SERIALIZATION: Creates a NodeGraphView from a Serialized XML Copy
        /// </summary>
        /// <param name="p_XmlTreeNode">the parent XmlTreeNode used in serialization</param>
        /// <param name="p_Panel">the panel that will contain this NodeGraphView</param>
        public NodeGraphView(XmlTreeNode p_XmlTreeNode, NodeGraphPanel p_Panel, Dictionary<string, NodeGraphDataType> knownDataTypes)
        {
            System.Globalization.CultureInfo v_IntlCultureInfo = new System.Globalization.CultureInfo("en-us");
            this.m_KnownDataTypes = knownDataTypes;
            this.m_oPanel = p_Panel;
            this.ViewX = int.Parse(p_XmlTreeNode.m_attributes["ViewX"]);
            this.ViewY = int.Parse(p_XmlTreeNode.m_attributes["ViewY"]);
            this.ViewZoom = float.Parse(p_XmlTreeNode.m_attributes["ViewZoom"], v_IntlCultureInfo);
            this.CurrentViewZoom = this.ViewZoom;

            this.m_NodeCollection = new List<NodeGraphNode>();

            XmlTreeNode v_NodesXml = p_XmlTreeNode.GetFirstChild("NodeGraphNodeCollection");
            foreach (XmlTreeNode i_ChildNode in v_NodesXml.m_childNodes)
            {

                    this.m_NodeCollection.Add(NodeGraphNode.DeserializeFromXML(i_ChildNode, this));
            }

            this.m_Links = new List<NodeGraphLink>();

            XmlTreeNode v_LinksXml = p_XmlTreeNode.GetFirstChild("NodeGraphLinkCollection");
            foreach (XmlTreeNode i_ChildLink in v_LinksXml.m_childNodes)
            {
                    this.m_Links.Add(NodeGraphLink.DeserializeFromXML(i_ChildLink, this));
            }

            this.m_SelectedItems = new List<NodeGraphNode>();
        }
Exemplo n.º 10
0
        /// <summary>
        /// SERIALIZATION: Creates a NodeGraphView from a Serialized XML Copy
        /// </summary>
        /// <param name="p_XmlTreeNode">the parent XmlTreeNode used in serialization</param>
        /// <param name="p_Panel">the panel that will contain this NodeGraphView</param>
        public NodeGraphView(PipelineDescriptor pipeline, NodeGraphPanel p_Panel)
        {
            //System.Globalization.CultureInfo v_IntlCultureInfo = new System.Globalization.CultureInfo("en-us");
            this.m_oPanel = p_Panel;
            this.ViewX = 0;
            this.ViewY = 0;
            this.ViewZoom = 1.0f;

            this.m_NodeCollection = new List<NodeGraphNode>();

            foreach (var module in pipeline.modules)
            {
                this.m_NodeCollection.Add(NodeGraphNode.FromModuleDescriptor(module, this));
            }

            this.m_Links = new List<NodeGraphLink>();

            foreach (var connection in pipeline.connections)
            {
                this.m_Links.Add(NodeGraphLink.FromConnectionDescriptor(connection, this));
            }

            for(int i = 0 ; i<this.m_NodeCollection.Count ; i++)
            {
                //! TODO : normal algorythm for module placement
                this.m_NodeCollection[i].X = i * 100;
                this.m_NodeCollection[i].Y = i * 100;
                this.m_NodeCollection[i].UpdateHitRectangle();
            }

            this.m_SelectedItems = new List<NodeGraphNode>();
        }
Exemplo n.º 11
0
        public void Compile(CompilationContext context, string inputPath, string outputPath, Database.ContentEntry contentData)
        {
            outputPath += ".mat";

            Material material;
            using (var nodeGraphPanel = new NodeGraphPanel())
            {
                nodeGraphPanel.View.RegisterDataType(new NodeGraphDataTypeFloat());
                nodeGraphPanel.View.RegisterDataType(new NodeGraphDataTypeVector3());
                nodeGraphPanel.View.RegisterDataType(new NodeGraphDataTypeVector4());

                nodeGraphPanel.LoadCurrentViewPure(inputPath);

                RootNode root = null;
                foreach (var node in nodeGraphPanel.View.NodeCollection)
                {
                    if (node is RootNode)
                    {
                        root = node as RootNode;
                        break;
                    }
                }

                var result = root.Process(0) as BuildShaderData;

                material = new Material();
                material.ShaderSource = result.Value;
                material.Defines = result.Defines;
                material.Samplers = new Dictionary<string, string>(Context.Samplers);
            }

            var murmur128 = MurmurHash.Create128(managed: false);
            var shader = Encoding.UTF8.GetBytes(material.ShaderSource);
            var hash = murmur128.ComputeHash(shader);

            var shaderName = BitConverter.ToString(hash).ToLowerInvariant().Replace("-", "");
            var shaderPath = "generated/shaders/" + shaderName;
            var shaderOutputPath = context.GetOutputPath(shaderPath + ".glsl");

            var template = context.GetShaderTemplate();
            material.ShaderSource = template.Replace("//__MATERIAL__PLACEHOLDER__", material.ShaderSource);
            if (material.Defines.Count > 0)
                material.ShaderSource = material.Defines.Select(d => "#define " + d).Aggregate((a, b) => a + "\n" + b) + "\n" + material.ShaderSource;

            using (var stream = context.OpenOutput(shaderPath + ".glsl"))
            using (var writer = new StreamWriter(stream))
            {
                writer.Write(material.ShaderSource);
            }

            using (var stream = File.Open(outputPath, FileMode.Create))
            using (var writer = new BinaryWriter(stream))
            {
                // Magic
                writer.Write('M');
                writer.Write('A');
                writer.Write('T');
                writer.Write('E');

                // Version
                writer.Write(Version);

                // Shader reference
                writer.Write("/shaders/" + shaderName);

                // Samplers
                writer.Write(material.Samplers.Count);

                foreach (var sampler in material.Samplers)
                {
                    writer.Write(sampler.Key);
                    writer.Write(sampler.Value);
                }
            }
        }