﻿<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ja">
	<id>https://wiki.blender.jp/index.php?action=history&amp;feed=atom&amp;title=Dev%3A2.4%2FDoc%2FHow_to%2FAdd_A_Node</id>
	<title>Dev:2.4/Doc/How to/Add A Node - 版の履歴</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.blender.jp/index.php?action=history&amp;feed=atom&amp;title=Dev%3A2.4%2FDoc%2FHow_to%2FAdd_A_Node"/>
	<link rel="alternate" type="text/html" href="https://wiki.blender.jp/index.php?title=Dev:2.4/Doc/How_to/Add_A_Node&amp;action=history"/>
	<updated>2026-08-15T23:33:04Z</updated>
	<subtitle>このウィキのこのページに関する変更履歴</subtitle>
	<generator>MediaWiki 1.31.0</generator>
	<entry>
		<id>https://wiki.blender.jp/index.php?title=Dev:2.4/Doc/How_to/Add_A_Node&amp;diff=45110&amp;oldid=prev</id>
		<title>Yamyam: 1版 をインポートしました</title>
		<link rel="alternate" type="text/html" href="https://wiki.blender.jp/index.php?title=Dev:2.4/Doc/How_to/Add_A_Node&amp;diff=45110&amp;oldid=prev"/>
		<updated>2018-06-28T17:46:38Z</updated>

		<summary type="html">&lt;p&gt;1版 をインポートしました&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;ja&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← 古い版&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;2018年6月28日 (木) 17:46時点における版&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;ja&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(相違点なし)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Yamyam</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.blender.jp/index.php?title=Dev:2.4/Doc/How_to/Add_A_Node&amp;diff=45109&amp;oldid=prev</id>
		<title>wiki&gt;Brecht: moved Dev:Doc/How to/Add A Node to Dev:2.4/Doc/How to/Add A Node</title>
		<link rel="alternate" type="text/html" href="https://wiki.blender.jp/index.php?title=Dev:2.4/Doc/How_to/Add_A_Node&amp;diff=45109&amp;oldid=prev"/>
		<updated>2011-06-15T13:04:02Z</updated>

		<summary type="html">&lt;p&gt;moved &lt;a href=&quot;/Dev:Doc/How_to/Add_A_Node&quot; class=&quot;mw-redirect&quot; title=&quot;Dev:Doc/How to/Add A Node&quot;&gt;Dev:Doc/How to/Add A Node&lt;/a&gt; to &lt;a href=&quot;/Dev:2.4/Doc/How_to/Add_A_Node&quot; title=&quot;Dev:2.4/Doc/How to/Add A Node&quot;&gt;Dev:2.4/Doc/How to/Add A Node&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新規ページ&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Adding a Shader Node ==&lt;br /&gt;
&lt;br /&gt;
There are a few files you need to edit in order to add a shader. We will add a math node in this tutorial. &lt;br /&gt;
&lt;br /&gt;
===source/blender/blenkernel/BKE_node.h===&lt;br /&gt;
&lt;br /&gt;
In this file you need to add #define for your new node you will see them listed with a line like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#define SH_NODE_OUTPUT 1&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Go to the bottom, add your node using the naming convention&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
SH_NODE_NAME&lt;br /&gt;
&amp;lt;/source&amp;gt; and then number it +1 to the last added node. So for our tutorial we will add:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#define SH_NODE_MATH 112&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===source/blender/blenkernel/intern/node_shaders.c===&lt;br /&gt;
&lt;br /&gt;
In this file the main part of the definition for our node layout is done. &lt;br /&gt;
First we define the input sockets. The define &amp;lt;code&amp;gt;SOCK_VALUE&amp;lt;/code&amp;gt; means that it is a value socket. This can be &amp;lt;code&amp;gt;SOCK_VALUE&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;SOCK_RGBA&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;SOCK_VECTOR&amp;lt;/code&amp;gt;. for each input socket there needs to be an entry. See the other nodes in the file for examples. This structure needs the &amp;lt;code&amp;gt;{-1, 0, &amp;quot;&amp;quot;}&amp;lt;/code&amp;gt; as a sentinel. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
/* **************** Value Math ******************** */ &lt;br /&gt;
static bNodeSocketType sh_node_math_in[]= { &lt;br /&gt;
	{ SOCK_VALUE, 1, &amp;quot;Value 1&amp;quot;, 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 1.0f}, &lt;br /&gt;
	{ SOCK_VALUE, 1, &amp;quot;Value 2&amp;quot;, 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 1.0f}, &lt;br /&gt;
	{ -1, 0, &amp;quot;&amp;quot; } &lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Not unlike the input sockets are the output sockets:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
static bNodeSocketType sh_node_math_out[]= { &lt;br /&gt;
	{ SOCK_VALUE, 0, &amp;quot;Value Out&amp;quot;, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, &lt;br /&gt;
	{ -1, 0, &amp;quot;&amp;quot; } &lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The syntax of bNodeSocketType is documented in the file as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
/* SocketType syntax: &lt;br /&gt;
   socket type, max connections (0 is no limit), name, 4 values for default, 2 values for range */&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next is the function that evaluates the input of the node and provides the output. The values for the &lt;br /&gt;
sockets are accessed through the in and out arrays. The index of in or out being the socket # and &lt;br /&gt;
primarily using the vec member to get the values off of it.  Please be aware that this example has no &lt;br /&gt;
protection for divide by zero. The variable &amp;lt;code&amp;gt;node-&amp;gt;custom1&amp;lt;/code&amp;gt; will be set in the next file. &lt;br /&gt;
 &lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
static void node_shader_exec_math(void *data, bNode *node, bNodeStack **in, &lt;br /&gt;
bNodeStack **out) &lt;br /&gt;
{ &lt;br /&gt;
	/* stack order in: fac, col1, col2 */ &lt;br /&gt;
	/* stack order out: col */ &lt;br /&gt;
	float val1= in[0]-&amp;gt;vec[0]; &lt;br /&gt;
	float val2= in[1]-&amp;gt;vec[0]; &lt;br /&gt;
	switch(node-&amp;gt;custom1){ &lt;br /&gt;
	&lt;br /&gt;
	case 0: // Add &lt;br /&gt;
		out[0]-&amp;gt;vec[0] = val1 + val2; &lt;br /&gt;
		break; &lt;br /&gt;
	case 1: // Subtract &lt;br /&gt;
		out[0]-&amp;gt;vec[0] = val1 - val2; &lt;br /&gt;
		break; &lt;br /&gt;
	case 2: // Multiply &lt;br /&gt;
		out[0]-&amp;gt;vec[0] = val1 * val2; &lt;br /&gt;
		break; &lt;br /&gt;
	case 3: // Divide &lt;br /&gt;
		out[0]-&amp;gt;vec[0] = val1 / val2; &lt;br /&gt;
	break; &lt;br /&gt;
	} &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and the node definition. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
static bNodeType sh_node_math= { &lt;br /&gt;
	/* type code   */ SH_NODE_MATH, &lt;br /&gt;
	/* name        */ &amp;quot;Math&amp;quot;, &lt;br /&gt;
	/* width+range */ 80, 40, 120, &lt;br /&gt;
	/* class+opts  */ NODE_CLASS_OPERATOR, NODE_OPTIONS, &lt;br /&gt;
	/* input sock  */ sh_node_math_in, &lt;br /&gt;
	/* output sock */ sh_node_math_out, &lt;br /&gt;
	/* storage     */ &amp;quot;&amp;quot;, &lt;br /&gt;
	/* execfunc    */ node_shader_exec_math &lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will also need to add this node definition to the node_all_shaders[] array at the bottom of the file &lt;br /&gt;
before the NULL entry. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
&amp;amp;sh_node_math&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===source/blender/src/drawnode.c===&lt;br /&gt;
&lt;br /&gt;
If you node needs nothing other than its inputs to generate its output, you do not need to add anything &lt;br /&gt;
to this file. Otherwise you will need to add any special controls here. In our case we want to add a &lt;br /&gt;
pulldown for the math operation to do. If you notice we are using the &amp;lt;code&amp;gt;&amp;amp;node-&amp;gt;custom1&amp;lt;/code&amp;gt; variable to &lt;br /&gt;
store the pulldown option. You will need to return the height that these widgets will take up as well. &lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
static int node_shader_buts_math(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr) &lt;br /&gt;
{ &lt;br /&gt;
	if(block) { &lt;br /&gt;
		uiBut *bt; &lt;br /&gt;
		/* blend type */ &lt;br /&gt;
		bt=uiDefButS(block, MENU, B_NODE_EXEC,  &amp;quot;Add %x0|Subtract %x1|Multiply %x2 |Divide %x3&amp;quot;, butr-&amp;gt;xmin, butr-&amp;gt;ymin, butr-&amp;gt;xmax-butr-&amp;gt;xmin, 20, &amp;amp;node-&amp;gt;custom1, 0, 0, 0, 0, &amp;quot;&amp;quot;); &lt;br /&gt;
		uiButSetFunc(bt, node_but_title_cb, node, bt); &lt;br /&gt;
	} &lt;br /&gt;
	return 20; &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then in the node_shader_set_butfunc function you need to add a case for your shader type and a call to &lt;br /&gt;
the function that you just created that will make the menu options. &lt;br /&gt;
 &lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
	case SH_NODE_MATH: &lt;br /&gt;
		ntype-&amp;gt;butfunc= node_shader_buts_math; &lt;br /&gt;
		break; &lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After all this your node *should* work. Although I have probably left something out.&lt;br /&gt;
&lt;br /&gt;
[[Category:Development]]&lt;br /&gt;
[[Category:Coding]]&lt;br /&gt;
[[Category:Script]]&lt;/div&gt;</summary>
		<author><name>wiki&gt;Brecht</name></author>
		
	</entry>
</feed>