Blender  V2.93
node_texture_proc.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2005 Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #include "NOD_texture.h"
25 #include "node_texture_util.h"
26 
27 #include "RE_texture.h"
28 
29 /*
30  * In this file: wrappers to use procedural textures as nodes
31  */
32 
34  {SOCK_RGBA, N_("Color"), 1.0f, 0.0f, 0.0f, 1.0f},
35  {SOCK_VECTOR, N_("Normal"), 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, PROP_DIRECTION},
36  {-1, ""}};
37 static bNodeSocketTemplate outputs_color_only[] = {{SOCK_RGBA, N_("Color")}, {-1, ""}};
38 
39 /* Inputs common to all, #defined because nodes will need their own inputs too */
40 #define I 2 /* count */
41 #define COMMON_INPUTS \
42  {SOCK_RGBA, "Color 1", 0.0f, 0.0f, 0.0f, 1.0f}, \
43  { \
44  SOCK_RGBA, "Color 2", 1.0f, 1.0f, 1.0f, 1.0f \
45  }
46 
47 /* Calls multitex and copies the result to the outputs.
48  * Called by xxx_exec, which handles inputs. */
49 static void do_proc(float *result,
50  TexParams *p,
51  const float col1[4],
52  const float col2[4],
53  char is_normal,
54  Tex *tex,
55  const short thread)
56 {
57  TexResult texres;
58  int textype;
59 
60  if (is_normal) {
61  texres.nor = result;
62  }
63  else {
64  texres.nor = NULL;
65  }
66 
67  textype = multitex_nodes(
68  tex, p->co, p->dxt, p->dyt, p->osatex, &texres, thread, 0, p->mtex, NULL);
69 
70  if (is_normal) {
71  return;
72  }
73 
74  if (textype & TEX_RGB) {
75  copy_v4_v4(result, &texres.tr);
76  }
77  else {
78  copy_v4_v4(result, col1);
79  ramp_blend(MA_RAMP_BLEND, result, texres.tin, col2);
80  }
81 }
82 
83 typedef void (*MapFn)(Tex *tex, bNodeStack **in, TexParams *p, const short thread);
84 
85 static void texfn(float *result,
86  TexParams *p,
87  bNode *node,
88  bNodeStack **in,
89  char is_normal,
90  MapFn map_inputs,
91  short thread)
92 {
93  Tex tex = *((Tex *)(node->storage));
94  float col1[4], col2[4];
95  tex_input_rgba(col1, in[0], p, thread);
96  tex_input_rgba(col2, in[1], p, thread);
97 
98  map_inputs(&tex, in, p, thread);
99 
100  do_proc(result, p, col1, col2, is_normal, &tex, thread);
101 }
102 
104 {
105  bNodeSocket *sock;
106  int num = 0;
107  for (sock = node->outputs.first; sock; sock = sock->next) {
108  num++;
109  }
110  return num;
111 }
112 
113 /* Boilerplate generators */
114 
115 #define ProcNoInputs(name) \
116  static void name##_map_inputs( \
117  Tex *UNUSED(tex), bNodeStack **UNUSED(in), TexParams *UNUSED(p), short UNUSED(thread)) \
118  { \
119  }
120 
121 #define ProcDef(name) \
122  static void name##_colorfn( \
123  float *result, TexParams *p, bNode *node, bNodeStack **in, short thread) \
124  { \
125  texfn(result, p, node, in, 0, &name##_map_inputs, thread); \
126  } \
127  static void name##_normalfn( \
128  float *result, TexParams *p, bNode *node, bNodeStack **in, short thread) \
129  { \
130  texfn(result, p, node, in, 1, &name##_map_inputs, thread); \
131  } \
132  static void name##_exec(void *data, \
133  int UNUSED(thread), \
134  bNode *node, \
135  bNodeExecData *execdata, \
136  bNodeStack **in, \
137  bNodeStack **out) \
138  { \
139  int outs = count_outputs(node); \
140  if (outs >= 1) { \
141  tex_output(node, execdata, in, out[0], &name##_colorfn, data); \
142  } \
143  if (outs >= 2) { \
144  tex_output(node, execdata, in, out[1], &name##_normalfn, data); \
145  } \
146  }
147 
148 /* --- VORONOI -- */
151  {SOCK_FLOAT, N_("W1"), 1.0f, 0.0f, 0.0f, 0.0f, -2.0f, 2.0f, PROP_NONE},
152  {SOCK_FLOAT, N_("W2"), 0.0f, 0.0f, 0.0f, 0.0f, -2.0f, 2.0f, PROP_NONE},
153  {SOCK_FLOAT, N_("W3"), 0.0f, 0.0f, 0.0f, 0.0f, -2.0f, 2.0f, PROP_NONE},
154  {SOCK_FLOAT, N_("W4"), 0.0f, 0.0f, 0.0f, 0.0f, -2.0f, 2.0f, PROP_NONE},
155 
156  {SOCK_FLOAT, N_("iScale"), 1.0f, 0.0f, 0.0f, 0.0f, 0.01f, 10.0f, PROP_UNSIGNED},
157  {SOCK_FLOAT, N_("Size"), 0.25f, 0.0f, 0.0f, 0.0f, 0.0001f, 4.0f, PROP_UNSIGNED},
158 
159  {-1, ""}};
160 static void voronoi_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread)
161 {
162  tex->vn_w1 = tex_input_value(in[I + 0], p, thread);
163  tex->vn_w2 = tex_input_value(in[I + 1], p, thread);
164  tex->vn_w3 = tex_input_value(in[I + 2], p, thread);
165  tex->vn_w4 = tex_input_value(in[I + 3], p, thread);
166 
167  tex->ns_outscale = tex_input_value(in[I + 4], p, thread);
168  tex->noisesize = tex_input_value(in[I + 5], p, thread);
169 }
170 ProcDef(voronoi);
171 
172 /* --- BLEND -- */
176 
177 /* -- MAGIC -- */
180  {SOCK_FLOAT, N_("Turbulence"), 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 200.0f, PROP_UNSIGNED},
181  {-1, ""}};
182 static void magic_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread)
183 {
184  tex->turbul = tex_input_value(in[I + 0], p, thread);
185 }
187 
188 /* --- MARBLE --- */
191  {SOCK_FLOAT, N_("Size"), 0.25f, 0.0f, 0.0f, 0.0f, 0.0001f, 2.0f, PROP_UNSIGNED},
192  {SOCK_FLOAT, N_("Turbulence"), 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 200.0f, PROP_UNSIGNED},
193  {-1, ""}};
194 static void marble_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread)
195 {
196  tex->noisesize = tex_input_value(in[I + 0], p, thread);
197  tex->turbul = tex_input_value(in[I + 1], p, thread);
198 }
200 
201 /* --- CLOUDS --- */
204  {SOCK_FLOAT, N_("Size"), 0.25f, 0.0f, 0.0f, 0.0f, 0.0001f, 2.0f, PROP_UNSIGNED},
205  {-1, ""}};
206 static void clouds_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread)
207 {
208  tex->noisesize = tex_input_value(in[I + 0], p, thread);
209 }
211 
212 /* --- DISTORTED NOISE --- */
215  {SOCK_FLOAT, N_("Size"), 0.25f, 0.0f, 0.0f, 0.0f, 0.0001f, 2.0f, PROP_UNSIGNED},
216  {SOCK_FLOAT, N_("Distortion"), 1.00f, 0.0f, 0.0f, 0.0f, 0.0000f, 10.0f, PROP_UNSIGNED},
217  {-1, ""}};
218 static void distnoise_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread)
219 {
220  tex->noisesize = tex_input_value(in[I + 0], p, thread);
221  tex->dist_amount = tex_input_value(in[I + 1], p, thread);
222 }
223 ProcDef(distnoise);
224 
225 /* --- WOOD --- */
228  {SOCK_FLOAT, N_("Size"), 0.25f, 0.0f, 0.0f, 0.0f, 0.0001f, 2.0f, PROP_UNSIGNED},
229  {SOCK_FLOAT, N_("Turbulence"), 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 200.0f, PROP_UNSIGNED},
230  {-1, ""}};
231 static void wood_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread)
232 {
233  tex->noisesize = tex_input_value(in[I + 0], p, thread);
234  tex->turbul = tex_input_value(in[I + 1], p, thread);
235 }
237 
238 /* --- MUSGRAVE --- */
241  {SOCK_FLOAT, N_("H"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0001f, 2.0f, PROP_UNSIGNED},
242  {SOCK_FLOAT, N_("Lacunarity"), 2.0f, 0.0f, 0.0f, 0.0f, 0.0f, 6.0f, PROP_UNSIGNED},
243  {SOCK_FLOAT, N_("Octaves"), 2.0f, 0.0f, 0.0f, 0.0f, 0.0f, 8.0f, PROP_UNSIGNED},
244 
245  {SOCK_FLOAT, N_("iScale"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 10.0f, PROP_UNSIGNED},
246  {SOCK_FLOAT, N_("Size"), 0.25f, 0.0f, 0.0f, 0.0f, 0.0001f, 2.0f, PROP_UNSIGNED},
247  {-1, ""}};
248 static void musgrave_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread)
249 {
250  tex->mg_H = tex_input_value(in[I + 0], p, thread);
251  tex->mg_lacunarity = tex_input_value(in[I + 1], p, thread);
252  tex->mg_octaves = tex_input_value(in[I + 2], p, thread);
253  tex->ns_outscale = tex_input_value(in[I + 3], p, thread);
254  tex->noisesize = tex_input_value(in[I + 4], p, thread);
255 }
256 ProcDef(musgrave);
257 
258 /* --- NOISE --- */
262 
263 /* --- STUCCI --- */
266  {SOCK_FLOAT, N_("Size"), 0.25f, 0.0f, 0.0f, 0.0f, 0.0001f, 2.0f, PROP_UNSIGNED},
267  {SOCK_FLOAT, N_("Turbulence"), 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 200.0f, PROP_UNSIGNED},
268  {-1, ""}};
269 static void stucci_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread)
270 {
271  tex->noisesize = tex_input_value(in[I + 0], p, thread);
272  tex->turbul = tex_input_value(in[I + 1], p, thread);
273 }
275 
276 /* --- */
277 
279 {
280  Tex *tex = MEM_callocN(sizeof(Tex), "Tex");
281  node->storage = tex;
282 
284  tex->type = node->type - TEX_NODE_PROC;
285 
286  if (tex->type == TEX_WOOD) {
288  }
289 }
290 
291 /* Node type definitions */
292 #define TexDef(TEXTYPE, outputs, name, Name) \
293  void register_node_type_tex_proc_##name(void) \
294  { \
295  static bNodeType ntype; \
296 \
297  tex_node_type_base(&ntype, TEX_NODE_PROC + TEXTYPE, Name, NODE_CLASS_TEXTURE, NODE_PREVIEW); \
298  node_type_socket_templates(&ntype, name##_inputs, outputs); \
299  node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); \
300  node_type_init(&ntype, init); \
301  node_type_storage(&ntype, "Tex", node_free_standard_storage, node_copy_standard_storage); \
302  node_type_exec(&ntype, NULL, NULL, name##_exec); \
303 \
304  nodeRegisterType(&ntype); \
305  }
306 
307 #define C outputs_color_only
308 #define CV outputs_both
309 
310 TexDef(TEX_VORONOI, CV, voronoi, "Voronoi") TexDef(TEX_BLEND, C, blend, "Blend");
311 TexDef(TEX_MAGIC, C, magic, "Magic") TexDef(TEX_MARBLE, CV, marble, "Marble");
313 TexDef(TEX_MUSGRAVE, CV, musgrave, "Musgrave") TexDef(TEX_NOISE, C, noise, "Noise");
315 TexDef(TEX_DISTNOISE, CV, distnoise, "Distorted Noise");
void ramp_blend(int type, float r_col[3], const float fac, const float col[3])
Definition: material.c:1395
#define TEX_NODE_PROC
Definition: BKE_node.h:1350
void BKE_texture_default(struct Tex *tex)
Definition: texture.c:375
MINLINE void copy_v4_v4(float r[4], const float a[4])
#define UNUSED(x)
#define N_(msgid)
#define MA_RAMP_BLEND
@ SOCK_VECTOR
@ SOCK_FLOAT
@ SOCK_RGBA
#define TEX_BLEND
#define TEX_DISTNOISE
#define TEX_RGB
#define TEX_BANDNOISE
#define TEX_MARBLE
#define TEX_WOOD
Group RGB to Bright Vector Camera Vector Combine Material Light Line Style Layer Add Ambient Diffuse Glossy Refraction Transparent Toon Principled Hair Volume Principled Light Particle Volume Image Sky Noise Wave Voronoi Brick Texture Vector Combine Vertex Separate Vector White RGB Map Separate Set Z Dilate Combine Combine Color Channel Split ID Combine Luminance Directional Alpha Distance Hue Movie Ellipse Bokeh View Corner Anti Mix RGB Hue Separate TEX_NODE_PROC TEX_NODE_PROC TEX_NODE_PROC TEX_NODE_PROC TEX_NODE_PROC Stucci
Group RGB to Bright Vector Camera Vector Combine Material Light Line Style Layer Add Ambient Diffuse Glossy Refraction Transparent Toon Principled Hair Volume Principled Light Particle Volume Image Sky Noise Wave Voronoi Brick Texture Vector Combine Vertex Separate Vector White RGB Map Separate Set Z Dilate Combine Combine Color Channel Split ID Combine Luminance Directional Alpha Distance Hue Movie Ellipse Bokeh View Corner Anti Mix RGB Hue Separate TEX_NODE_PROC TEX_NODE_PROC TEX_NODE_PROC TEX_NODE_PROC TEX_NODE_PROC TEX_STUCCI
Group RGB to Bright Vector Camera Vector Combine Material Light Line Style Layer Add Ambient Diffuse Glossy Refraction Transparent Toon Principled Hair Volume Principled Light Particle Volume Image Sky Noise Wave Voronoi Brick Texture Vector Combine Vertex Separate Vector White RGB Map Separate Set Z Dilate Combine Combine Color Channel Split ID Combine Luminance Directional Alpha Distance Hue Movie Ellipse Bokeh View Corner Anti Mix RGB Hue Separate TEX_NODE_PROC TEX_NODE_PROC TEX_NODE_PROC Clouds
Group RGB to Bright Vector Camera Vector Combine Material Light Line Style Layer Add Ambient Diffuse Glossy Refraction Transparent Toon Principled Hair Volume Principled Light Particle Volume Image Sky Noise Wave Voronoi Brick Texture Vector Combine Vertex Separate Vector White RGB Map Separate Set Z Dilate Combine Combine Color Channel Split ID Combine Luminance Directional Alpha Distance Hue Movie Ellipse Bokeh View Corner Anti Mix RGB Hue Separate TEX_NODE_PROC TEX_NODE_PROC TEX_NODE_PROC TEX_NODE_PROC TEX_MUSGRAVE
Group RGB to Bright Vector Camera Vector Combine Material Light Line Style Layer Add Ambient Diffuse Glossy Refraction Transparent Toon Principled Hair Volume Principled Light Particle Volume Image Sky Noise Wave Voronoi Brick Texture Vector Combine Vertex Separate Vector White RGB Map Separate Set Z Dilate Combine Combine Color Channel Split ID Combine Luminance Directional Alpha Distance Hue Movie Ellipse Bokeh View Corner Anti Mix RGB Hue Separate TEX_NODE_PROC TEX_NODE_PROC TEX_NODE_PROC TEX_CLOUDS
Group RGB to Bright Vector Camera Vector Combine Material Light Line Style Layer Add Ambient Diffuse Glossy Refraction Transparent Toon Principled Hair Volume Principled Light Particle Volume Image Sky Noise Wave Voronoi Brick Texture Vector Combine Vertex Separate Vector White RGB Map Separate Set Z Dilate Combine Combine Color Channel Split ID Combine Luminance Directional Alpha Distance Hue Movie Ellipse Bokeh View Corner Anti Mix RGB Hue Separate TEX_NODE_PROC TEX_NODE_PROC TEX_NODE_PROC TEX_NODE_PROC Musgrave
Group RGB to Bright Vector Camera Vector Combine Material Light Line Style Layer Add Ambient Diffuse Glossy Refraction Transparent Toon Principled Hair Volume Principled Light Particle Volume Image Sky TEX_NOISE
Group RGB to Bright Vector Camera Vector Combine Material Light Line Style Layer Add Ambient Diffuse Glossy Refraction Transparent Toon Principled Hair Volume Principled Light Particle Volume Image Sky Noise Wave TEX_VORONOI
Group RGB to Bright Vector Camera Vector Combine Material Light Line Style Layer Add Ambient Diffuse Glossy Refraction Transparent Toon Principled Hair Volume Principled Light Particle Volume Image Sky Noise Wave Voronoi Brick Texture Vector Combine Vertex Separate Vector White Noise
Group RGB to Bright Vector Camera Vector Combine Material Light Line Style Layer Add Ambient Diffuse Glossy Refraction Transparent Toon Principled Hair Volume Principled Light Particle Volume Image Sky Noise Wave Voronoi Brick Texture Vector Combine Vertex Separate Vector White RGB Map Separate Set Z Dilate Combine Combine Color Channel Split ID Combine Luminance Directional Alpha Distance Hue Movie Ellipse Bokeh View Corner Anti Mix RGB Hue Separate TEX_NODE_PROC TEX_NODE_PROC Magic
Group RGB to Bright Vector Camera Vector Combine Material Light Line Style Layer Add Ambient Diffuse Glossy Refraction Transparent Toon Principled Hair Volume Principled Light Particle Volume Image Sky Noise Wave Voronoi Brick Texture Vector Combine Vertex Separate Vector White RGB Map Separate Set Z Dilate Combine Combine Color Channel Split ID Combine Luminance Directional Alpha Distance Hue Movie Ellipse Bokeh View Corner Anti Mix RGB Hue Separate TEX_NODE_PROC TEX_NODE_PROC TEX_MAGIC
@ PROP_DIRECTION
Definition: RNA_types.h:141
@ PROP_NONE
Definition: RNA_types.h:113
@ PROP_UNSIGNED
Definition: RNA_types.h:129
OperationNode * node
bNodeTree * ntree
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:45
static float noise(int n)
static bNodeSocketTemplate outputs_color_only[]
static bNodeSocketTemplate outputs_both[]
static bNodeSocketTemplate stucci_inputs[]
static void do_proc(float *result, TexParams *p, const float col1[4], const float col2[4], char is_normal, Tex *tex, const short thread)
static void voronoi_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread)
static void distnoise_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread)
static bNodeSocketTemplate distnoise_inputs[]
static int count_outputs(bNode *node)
static void clouds_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread)
static void wood_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread)
static void magic_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread)
#define I
#define ProcNoInputs(name)
#define TexDef(TEXTYPE, outputs, name, Name)
static bNodeSocketTemplate clouds_inputs[]
static bNodeSocketTemplate musgrave_inputs[]
static bNodeSocketTemplate wood_inputs[]
#define CV
static void marble_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread)
static bNodeSocketTemplate magic_inputs[]
static bNodeSocketTemplate noise_inputs[]
#define COMMON_INPUTS
static void musgrave_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread)
void(* MapFn)(Tex *tex, bNodeStack **in, TexParams *p, const short thread)
static void stucci_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread)
static void texfn(float *result, TexParams *p, bNode *node, bNodeStack **in, char is_normal, MapFn map_inputs, short thread)
#define C
static bNodeSocketTemplate marble_inputs[]
#define ProcDef(name)
static bNodeSocketTemplate blend_inputs[]
static void init(bNodeTree *UNUSED(ntree), bNode *node)
static bNodeSocketTemplate voronoi_inputs[]
float tex_input_value(bNodeStack *in, TexParams *params, short thread)
void tex_input_rgba(float *out, bNodeStack *in, TexParams *params, short thread)
const float * co
float * nor
Definition: RE_texture.h:86
float tin
Definition: RE_texture.h:84
float tr
Definition: RE_texture.h:84
float dist_amount
float noisesize
float vn_w4
float ns_outscale
float vn_w2
float mg_lacunarity
short stype
float mg_octaves
float mg_H
short type
float vn_w3
float vn_w1
float turbul
Compact definition of a node socket.
Definition: BKE_node.h:95
struct bNodeSocket * next
static int marble(const Tex *tex, const float texvec[3], TexResult *texres)
static int stucci(const Tex *tex, const float texvec[3], TexResult *texres)
int multitex_nodes(Tex *tex, const float texvec[3], float dxt[3], float dyt[3], int osatex, TexResult *texres, const short thread, short which_output, MTex *mtex, struct ImagePool *pool)
static int wood(const Tex *tex, const float texvec[3], TexResult *texres)
static int magic(const Tex *tex, const float texvec[3], TexResult *texres)
static int blend(const Tex *tex, const float texvec[3], TexResult *texres)
static int clouds(const Tex *tex, const float texvec[3], TexResult *texres)