Blender  V3.3
node_texture_proc.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2005 Blender Foundation. All rights reserved. */
3 
8 #include "NOD_texture.h"
9 #include "node_texture_util.h"
10 
11 #include "RE_texture.h"
12 
13 /*
14  * In this file: wrappers to use procedural textures as nodes
15  */
16 
17 static bNodeSocketTemplate outputs_both[] = {{SOCK_RGBA, N_("Color"), 1.0f, 0.0f, 0.0f, 1.0f},
18  {-1, ""}};
19 static bNodeSocketTemplate outputs_color_only[] = {{SOCK_RGBA, N_("Color")}, {-1, ""}};
20 
21 /* Inputs common to all, #defined because nodes will need their own inputs too */
22 #define I 2 /* count */
23 #define COMMON_INPUTS \
24  {SOCK_RGBA, "Color 1", 0.0f, 0.0f, 0.0f, 1.0f}, \
25  { \
26  SOCK_RGBA, "Color 2", 1.0f, 1.0f, 1.0f, 1.0f \
27  }
28 
29 /* Calls multitex and copies the result to the outputs.
30  * Called by xxx_exec, which handles inputs. */
31 static void do_proc(float *result,
32  TexParams *p,
33  const float col1[4],
34  const float col2[4],
35  Tex *tex,
36  const short thread)
37 {
38  TexResult texres;
39  int textype;
40 
41  textype = multitex_nodes(
42  tex, p->co, p->dxt, p->dyt, p->osatex, &texres, thread, 0, p->mtex, NULL);
43 
44  if (textype & TEX_RGB) {
45  copy_v4_v4(result, texres.trgba);
46  }
47  else {
48  copy_v4_v4(result, col1);
49  ramp_blend(MA_RAMP_BLEND, result, texres.tin, col2);
50  }
51 }
52 
53 typedef void (*MapFn)(Tex *tex, bNodeStack **in, TexParams *p, const short thread);
54 
55 static void texfn(
56  float *result, TexParams *p, bNode *node, bNodeStack **in, MapFn map_inputs, short thread)
57 {
58  Tex tex = *((Tex *)(node->storage));
59  float col1[4], col2[4];
60  tex_input_rgba(col1, in[0], p, thread);
61  tex_input_rgba(col2, in[1], p, thread);
62 
63  map_inputs(&tex, in, p, thread);
64 
65  do_proc(result, p, col1, col2, &tex, thread);
66 }
67 
68 static int count_outputs(bNode *node)
69 {
70  bNodeSocket *sock;
71  int num = 0;
72  for (sock = node->outputs.first; sock; sock = sock->next) {
73  num++;
74  }
75  return num;
76 }
77 
78 /* Boilerplate generators */
79 
80 #define ProcNoInputs(name) \
81  static void name##_map_inputs( \
82  Tex *UNUSED(tex), bNodeStack **UNUSED(in), TexParams *UNUSED(p), short UNUSED(thread)) \
83  { \
84  }
85 
86 #define ProcDef(name) \
87  static void name##_colorfn( \
88  float *result, TexParams *p, bNode *node, bNodeStack **in, short thread) \
89  { \
90  texfn(result, p, node, in, &name##_map_inputs, thread); \
91  } \
92  static void name##_exec(void *data, \
93  int UNUSED(thread), \
94  bNode *node, \
95  bNodeExecData *execdata, \
96  bNodeStack **in, \
97  bNodeStack **out) \
98  { \
99  int outs = count_outputs(node); \
100  if (outs >= 1) { \
101  tex_output(node, execdata, in, out[0], &name##_colorfn, data); \
102  } \
103  }
104 
105 /* --- VORONOI -- */
108  {SOCK_FLOAT, N_("W1"), 1.0f, 0.0f, 0.0f, 0.0f, -2.0f, 2.0f, PROP_NONE},
109  {SOCK_FLOAT, N_("W2"), 0.0f, 0.0f, 0.0f, 0.0f, -2.0f, 2.0f, PROP_NONE},
110  {SOCK_FLOAT, N_("W3"), 0.0f, 0.0f, 0.0f, 0.0f, -2.0f, 2.0f, PROP_NONE},
111  {SOCK_FLOAT, N_("W4"), 0.0f, 0.0f, 0.0f, 0.0f, -2.0f, 2.0f, PROP_NONE},
112 
113  {SOCK_FLOAT, N_("iScale"), 1.0f, 0.0f, 0.0f, 0.0f, 0.01f, 10.0f, PROP_UNSIGNED},
114  {SOCK_FLOAT, N_("Size"), 0.25f, 0.0f, 0.0f, 0.0f, 0.0001f, 4.0f, PROP_UNSIGNED},
115 
116  {-1, ""}};
117 static void voronoi_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread)
118 {
119  tex->vn_w1 = tex_input_value(in[I + 0], p, thread);
120  tex->vn_w2 = tex_input_value(in[I + 1], p, thread);
121  tex->vn_w3 = tex_input_value(in[I + 2], p, thread);
122  tex->vn_w4 = tex_input_value(in[I + 3], p, thread);
123 
124  tex->ns_outscale = tex_input_value(in[I + 4], p, thread);
125  tex->noisesize = tex_input_value(in[I + 5], p, thread);
126 }
127 ProcDef(voronoi);
128 
129 /* --- BLEND -- */
133 
134 /* -- MAGIC -- */
137  {SOCK_FLOAT, N_("Turbulence"), 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 200.0f, PROP_UNSIGNED},
138  {-1, ""}};
139 static void magic_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread)
140 {
141  tex->turbul = tex_input_value(in[I + 0], p, thread);
142 }
144 
145 /* --- MARBLE --- */
148  {SOCK_FLOAT, N_("Size"), 0.25f, 0.0f, 0.0f, 0.0f, 0.0001f, 2.0f, PROP_UNSIGNED},
149  {SOCK_FLOAT, N_("Turbulence"), 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 200.0f, PROP_UNSIGNED},
150  {-1, ""}};
151 static void marble_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread)
152 {
153  tex->noisesize = tex_input_value(in[I + 0], p, thread);
154  tex->turbul = tex_input_value(in[I + 1], p, thread);
155 }
157 
158 /* --- CLOUDS --- */
161  {SOCK_FLOAT, N_("Size"), 0.25f, 0.0f, 0.0f, 0.0f, 0.0001f, 2.0f, PROP_UNSIGNED},
162  {-1, ""}};
163 static void clouds_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread)
164 {
165  tex->noisesize = tex_input_value(in[I + 0], p, thread);
166 }
168 
169 /* --- DISTORTED NOISE --- */
172  {SOCK_FLOAT, N_("Size"), 0.25f, 0.0f, 0.0f, 0.0f, 0.0001f, 2.0f, PROP_UNSIGNED},
173  {SOCK_FLOAT, N_("Distortion"), 1.00f, 0.0f, 0.0f, 0.0f, 0.0000f, 10.0f, PROP_UNSIGNED},
174  {-1, ""}};
175 static void distnoise_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread)
176 {
177  tex->noisesize = tex_input_value(in[I + 0], p, thread);
178  tex->dist_amount = tex_input_value(in[I + 1], p, thread);
179 }
180 ProcDef(distnoise);
181 
182 /* --- WOOD --- */
185  {SOCK_FLOAT, N_("Size"), 0.25f, 0.0f, 0.0f, 0.0f, 0.0001f, 2.0f, PROP_UNSIGNED},
186  {SOCK_FLOAT, N_("Turbulence"), 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 200.0f, PROP_UNSIGNED},
187  {-1, ""}};
188 static void wood_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread)
189 {
190  tex->noisesize = tex_input_value(in[I + 0], p, thread);
191  tex->turbul = tex_input_value(in[I + 1], p, thread);
192 }
194 
195 /* --- MUSGRAVE --- */
198  {SOCK_FLOAT, N_("H"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0001f, 2.0f, PROP_UNSIGNED},
199  {SOCK_FLOAT, N_("Lacunarity"), 2.0f, 0.0f, 0.0f, 0.0f, 0.0f, 6.0f, PROP_UNSIGNED},
200  {SOCK_FLOAT, N_("Octaves"), 2.0f, 0.0f, 0.0f, 0.0f, 0.0f, 8.0f, PROP_UNSIGNED},
201 
202  {SOCK_FLOAT, N_("iScale"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 10.0f, PROP_UNSIGNED},
203  {SOCK_FLOAT, N_("Size"), 0.25f, 0.0f, 0.0f, 0.0f, 0.0001f, 2.0f, PROP_UNSIGNED},
204  {-1, ""}};
205 static void musgrave_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread)
206 {
207  tex->mg_H = tex_input_value(in[I + 0], p, thread);
208  tex->mg_lacunarity = tex_input_value(in[I + 1], p, thread);
209  tex->mg_octaves = tex_input_value(in[I + 2], p, thread);
210  tex->ns_outscale = tex_input_value(in[I + 3], p, thread);
211  tex->noisesize = tex_input_value(in[I + 4], p, thread);
212 }
213 ProcDef(musgrave);
214 
215 /* --- NOISE --- */
219 
220 /* --- STUCCI --- */
223  {SOCK_FLOAT, N_("Size"), 0.25f, 0.0f, 0.0f, 0.0f, 0.0001f, 2.0f, PROP_UNSIGNED},
224  {SOCK_FLOAT, N_("Turbulence"), 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 200.0f, PROP_UNSIGNED},
225  {-1, ""}};
226 static void stucci_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread)
227 {
228  tex->noisesize = tex_input_value(in[I + 0], p, thread);
229  tex->turbul = tex_input_value(in[I + 1], p, thread);
230 }
232 
233 /* --- */
234 
236 {
237  Tex *tex = MEM_callocN(sizeof(Tex), "Tex");
238  node->storage = tex;
239 
241  tex->type = node->type - TEX_NODE_PROC;
242 
243  if (tex->type == TEX_WOOD) {
245  }
246 }
247 
248 /* Node type definitions */
249 #define TexDef(TEXTYPE, outputs, name, Name) \
250  void register_node_type_tex_proc_##name(void) \
251  { \
252  static bNodeType ntype; \
253 \
254  tex_node_type_base(&ntype, TEX_NODE_PROC + TEXTYPE, Name, NODE_CLASS_TEXTURE); \
255  node_type_socket_templates(&ntype, name##_inputs, outputs); \
256  node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); \
257  node_type_init(&ntype, init); \
258  node_type_storage(&ntype, "Tex", node_free_standard_storage, node_copy_standard_storage); \
259  node_type_exec(&ntype, NULL, NULL, name##_exec); \
260  ntype.flag |= NODE_PREVIEW; \
261 \
262  nodeRegisterType(&ntype); \
263  }
264 
265 #define C outputs_color_only
266 #define CV outputs_both
267 
268 TexDef(TEX_VORONOI, CV, voronoi, "Voronoi") TexDef(TEX_BLEND, C, blend, "Blend");
269 TexDef(TEX_MAGIC, C, magic, "Magic") TexDef(TEX_MARBLE, CV, marble, "Marble");
270 TexDef(TEX_CLOUDS, CV, clouds, "Clouds") TexDef(TEX_WOOD, CV, wood, "Wood");
271 TexDef(TEX_MUSGRAVE, CV, musgrave, "Musgrave") TexDef(TEX_NOISE, C, noise, "Noise");
272 TexDef(TEX_STUCCI, CV, stucci, "Stucci");
273 TexDef(TEX_DISTNOISE, CV, distnoise, "Distorted Noise");
void ramp_blend(int type, float r_col[3], float fac, const float col[3])
Definition: material.c:1611
#define TEX_NODE_PROC
Definition: BKE_node.h:1374
void BKE_texture_default(struct Tex *tex)
Definition: texture.c:361
MINLINE void copy_v4_v4(float r[4], const float a[4])
#define UNUSED(x)
#define MA_RAMP_BLEND
@ SOCK_FLOAT
@ SOCK_RGBA
#define TEX_CLOUDS
#define TEX_BLEND
#define TEX_DISTNOISE
#define TEX_STUCCI
#define TEX_MUSGRAVE
#define TEX_RGB
#define TEX_BANDNOISE
#define TEX_MARBLE
#define TEX_MAGIC
#define TEX_WOOD
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Sky Generate a procedural sky texture Noise Generate fractal Perlin noise Wave Generate procedural bands or rings with noise TEX_VORONOI
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Sky Generate a procedural sky texture Noise Generate fractal Perlin noise Wave Generate procedural bands or rings with noise Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a or normal between and object coordinate space Combine Create a color from its and value channels Color Retrieve a color or the default fallback if none is specified Separate Split a vector into its and Z components Generates normals with round corners and may slow down renders Vector Displace the surface along an arbitrary direction White Noise
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Sky Generate a procedural sky texture TEX_NOISE
@ PROP_NONE
Definition: RNA_types.h:126
@ PROP_UNSIGNED
Definition: RNA_types.h:142
Definition: thread.h:34
OperationNode * node
SyclQueue void void size_t num_bytes void
bNodeTree * ntree
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:31
static float noise(int n)
static bNodeSocketTemplate outputs_color_only[]
static bNodeSocketTemplate outputs_both[]
static bNodeSocketTemplate stucci_inputs[]
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 void texfn(float *result, TexParams *p, bNode *node, bNodeStack **in, MapFn map_inputs, 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 void do_proc(float *result, TexParams *p, const float col1[4], const float col2[4], Tex *tex, const short thread)
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)
#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 tin
Definition: RE_texture.h:86
float trgba[4]
Definition: RE_texture.h:87
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:84
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)
#define N_(msgid)