public CyclesNode(string name, string nickname, string description, string category, string subcategory, Type nodetype) : base(name, nickname, description, category, subcategory) { string[] p = { Utils.cleanName(nickname) }; ShaderNode = Activator.CreateInstance(nodetype, p) as ShaderNode; base.PostConstructor(); }
/// <summary> /// Make the actual connection between nodes. /// </summary> /// <param name="from"></param> /// <param name="fromout"></param> /// <param name="to"></param> /// <param name="toin"></param> private void Connect(ShaderNode from, string fromout, ShaderNode to, string toin) { if (m_nodes.Contains(from) && m_nodes.Contains(to)) { CSycles.shader_connect_nodes(Client.Id, Id, from.Id, fromout, to.Id, toin); } else { throw new ArgumentException(String.Format("Cannot connect {0} to {1}", from, to)); } }
public ShaderNode Parse() { var result = new ShaderNode(); Eat(TokenType.Shader); result.Name = ParseString().Value; Eat(TokenType.OpenCurly); result.Properties = ParseProperties(); result.Technique = ParseTechnique(); Eat(TokenType.CloseCurly); Eat(TokenType.Eof); return(result); }
/// <summary> /// Add a ShaderNode to the shader. This will create the node in Cycles, set /// any values for sockets and direct members. /// </summary> /// <param name="node">ShaderNode to add</param> public void AddNode(ShaderNode node) { if (node is OutputNode) { node.Id = CSycles.OUTPUT_SHADERNODE_ID; m_nodes.Add(node); return; } if (created_in_cycles) { m_nodes.Add(node); return; } var nodeid = CSycles.add_shader_node(Client.Id, Id, node.Type); node.Id = nodeid; m_nodes.Add(node); }
public override ShaderContent Import(string filename, ContentImporterContext context) { if (context == null) { throw new ArgumentNullException("context"); } if (string.IsNullOrEmpty(filename)) { throw new ArgumentException("Filename cannot be null or empty.", "filename"); } FileInfo info = new FileInfo(filename); if (!info.Exists) { throw new FileNotFoundException("File not found", filename); } ContentIdentity identity = new ContentIdentity(info.FullName, ImporterName); string text = File.ReadAllText(filename); Lexer lexer = new Lexer(filename, text); lexer.Error += (sender, e) => ThrowParserException(e, info); Token[] tokens = lexer.GetTokens(); ShaderParser parser = new ShaderParser(filename, tokens); parser.Error += (sender, e) => ThrowParserException(e, info); ShaderNode shaderNode = parser.Parse(); ShaderContent content = new ShaderContent { ShaderNode = shaderNode }; content.Identity = identity; return(content); }
public static Shader getShaderHandle(List <string> shaderDescription) { ShaderNode current = root; ShaderNode next = null; foreach (string element in shaderDescription) { next = current.getChild(element); if (next == null) { next = new ShaderNode(element); current.children.Add(next); } current = next; } if (current.shader == -1) { current.shader = shaders.Count; shaders.Add(buildShader(shaderDescription)); } return(shaders[current.shader]); }
/// <summary> /// Create a new FloatSocket. /// /// The name of the socket has to correspond to the names in Cycles. /// </summary> /// <param name="parentNode">The ShaderNode for which the socket is created</param> /// <param name="name">Name of the socket</param> public FloatSocket(ShaderNode parentNode, string name) : base(parentNode, name) { Value = 0.0f; }
public IntSocket(ShaderNode parentNode, string name) : base(parentNode, name) { Value = 0; }
/// <summary> /// Create a new FloatSocket. /// /// The name of the socket has to correspond to the names in Cycles. /// </summary> /// <param name="parentNode">The ShaderNode for which the socket is created</param> /// <param name="name">Name of the socket</param> public FloatSocket(ShaderNode parentNode, string name) : base(parentNode, name) { Value = 0.0f; }
/// <summary> /// Update the buffers with the current values /// </summary> void UpdateBuffers() { // update compute buffers if (shaderNodes == null || nodes.Count > shaderNodesCount) { if (shaderNodes == null || nodes.Count > shaderNodes.Length) { if (shaderNodesBuffer != null) { shaderNodesBuffer.Dispose(); } int newSize = Mathf.CeilToInt(nodes.Count / (float)computeRepulsionForcesNbThreads) * (int)computeRepulsionForcesNbThreads; newSize = newSize == 0 ? (int)computeRepulsionForcesNbThreads : newSize; var existingNodes = nodes.Values.Cast <Node>().Select(n => new ShaderNode { transform = n.transform.position, velocity = Vector3.zero }); var emtyPading = new List <ShaderNode>(newSize - nodes.Count); shaderNodes = existingNodes.Concat(emtyPading).ToArray(); shaderNodesBuffer = new ComputeBuffer(shaderNodes.Length, sizeof(float) * 3 * 3); shaderNodesBuffer.SetData(shaderNodes); } else { for (int i = shaderNodesCount; i < nodes.Count; i++) { Node n = nodes.Values.Cast <Node>().ElementAt(i); shaderNodes[i] = new ShaderNode { transform = n.transform.position, velocity = Vector3.zero }; } shaderNodesBuffer.SetData(shaderNodes, shaderNodesCount, shaderNodesCount, nodes.Count - shaderNodesCount); } shaderNodesCount = nodes.Count; graphPhysicsShader.SetInt("NbNodes", shaderNodesCount); } if (shaderLinks == null || links.Count > shaderLinksCount) { if (shaderLinks == null || links.Count > shaderLinks.Length) { if (shaderLinksBuffer != null) { shaderLinksBuffer.Dispose(); } int newSize = Mathf.CeilToInt(links.Count / (float)computeSpringForcesNbThreads) * (int)computeSpringForcesNbThreads; newSize = newSize == 0 ? (int)computeSpringForcesNbThreads : newSize; var existingLinks = links.Select(l => new ShaderLink { toIndex = l.to.Id, fromIndex = l.from.Id }); var emtyPading = new List <ShaderLink>(newSize - links.Count); shaderLinks = existingLinks.Concat(emtyPading).ToArray(); shaderLinksBuffer = new ComputeBuffer(shaderLinks.Length, sizeof(int) * 2); shaderLinksBuffer.SetData(shaderLinks); } else { for (int i = shaderLinksCount; i < links.Count; i++) { shaderLinks[i] = new ShaderLink { toIndex = links[i].to.Id, fromIndex = links[i].from.Id }; } shaderLinksBuffer.SetData(shaderLinks, shaderLinksCount, shaderLinksCount, links.Count - shaderLinksCount); } shaderLinksCount = links.Count; graphPhysicsShader.SetInt("NbLinks", shaderLinksCount); } }
/// <summary> /// Create socket for parentNode. The name has to correspond to the socket name in Cycles. /// </summary> /// <param name="parentNode"></param> /// <param name="name"></param> public Float4Socket(ShaderNode parentNode, string name) : base(parentNode, name) { Value = new float4(); }
/// <summary> /// Create socket for parentNode. The name has to correspond to the socket name in Cycles. /// </summary> /// <param name="parentNode"></param> /// <param name="name"></param> public Float4Socket(ShaderNode parentNode, string name) : base(parentNode, name) { Value = new float4(); }
public StringSocket(ShaderNode parentNode, string name) : base(parentNode, name) { Value = ""; }
public ClosureSocket(ShaderNode parentNode, string name) : base(parentNode, name) { }
protected override void SolveInstance(IGH_DataAccess da) { base.SolveInstance(da); Message = ""; // create our code shader var theshader = new ccl.CodeShader(ccl.Shader.ShaderType.Material); // determine all nodes used for this shader var usednodes = UsedNodes(this, da.Iteration); bool isBg = false; // add all nodes to the shader foreach (var n in usednodes) { if (n is CyclesNode cn) { isBg |= (cn is BSDF.BackgroundNode); theshader.AddNode(cn.ShaderNode); } } // finalize the shader theshader.FinalizeGraph(); var xmlgraph = theshader.Xml.Trim().Replace("\n", "").Replace(">", ">\n") + ShaderNode.CreateConnectXml().Trim().Replace("\n", "").Replace(">", ">\n"); var codegraph = theshader.Code.Trim().Replace("\n", "").Replace(";", ";\n") + ShaderNode.CreateConnectCode().Trim().Replace("\n", "").Replace(";", ";\n"); var xmlcode = xmlgraph + "<!--\n" + codegraph + "\n-->"; // Update XmlMaterial with shader. if (matId.Count() > 0 && xmlgraph.Length > 0) { var midx = da.Iteration < matId.Count ? da.Iteration : matId.Count - 1; if (Rhino.RhinoDoc.ActiveDoc.RenderMaterials.Where(i => i.Id.Equals(matId[midx])).FirstOrDefault() is XmlMaterial m) { m.BeginChange(Rhino.Render.RenderContent.ChangeContexts.Program); m.SetParameter("xmlcode", xmlgraph); m.EndChange(); if (matId.Count() > 1) { Message = "multiple materials set"; } else { Message = m.Name; } } else { Message = "NO MATERIAL"; } } da.SetData(0, xmlcode); }
public StringSocket(ShaderNode parentNode, string name) : base(parentNode, name) { Value = ""; }
public ClosureSocket(ShaderNode parentNode, string name) : base(parentNode, name) { }
internal SocketBase(ShaderNode parentNode, string name) { Parent = parentNode; Name = name; }
internal SocketBase(ShaderNode parentNode, string name) { Parent = parentNode; Name = name; }
public void ReadNodeGraph(ref Shader shader, XmlReader xmlNode) { var nodes = new Dictionary <string, ShaderNode> { { "output", shader.Output } }; while (xmlNode.Read()) { ShaderNode shader_node = null; if (!xmlNode.IsStartElement()) { continue; } var nodename = xmlNode.GetAttribute("name"); if (string.IsNullOrEmpty(nodename) && xmlNode.Name != "connect") { continue; } if (string.IsNullOrEmpty(nodename)) { nodename = ""; } switch (xmlNode.Name) { case "connect": var fromstring = xmlNode.GetAttribute("from"); var tostring = xmlNode.GetAttribute("to"); if (fromstring != null && tostring != null) { var from = fromstring.Split(' '); var to = tostring.Split(' '); if (!nodes.ContainsKey(from[0])) { throw new KeyNotFoundException(string.Format("'from' node [{0}] not defined prior to connection.", from[0])); } var fromnode = nodes[from[0]]; var fromsocket = fromnode.outputs.Socket(from[1]); if (!nodes.ContainsKey(to[0])) { throw new KeyNotFoundException(string.Format("'to' node [{0}] not defined prior to connection.", to[0])); } var tonode = nodes[to[0]]; var tosocket = tonode.inputs.Socket(to[1]); fromsocket.Connect(tosocket); } break; default: shader_node = CSycles.CreateShaderNode(xmlNode.Name, nodename); break; } if (shader_node != null) { shader_node.ParseXml(xmlNode); nodes.Add(nodename, shader_node); shader.AddNode(shader_node); } } shader.FinalizeGraph(); }