Blender V5.3
node_texture_proc.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2005 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BKE_material.hh"
10#include "BKE_texture.h"
11#include "BLI_listbase.hh"
12#include "BLI_math_vector_c.hh"
13#include "DNA_material_types.h"
14#include "node_texture_util.hh"
15#include "node_util.hh"
16
17#include "RE_texture.h"
18
19namespace blender {
20
21/*
22 * In this file: wrappers to use procedural textures as nodes
23 */
24
25static bke::bNodeSocketTemplate outputs_both[] = {{SOCK_RGBA, N_("Color"), 1.0f, 0.0f, 0.0f, 1.0f},
26 {-1, ""}};
27static bke::bNodeSocketTemplate outputs_color_only[] = {{SOCK_RGBA, N_("Color")}, {-1, ""}};
28
29/* Inputs common to all, #defined because nodes will need their own inputs too */
30#define I 2 /* count */
31#define COMMON_INPUTS \
32 {SOCK_RGBA, "Color 1", 0.0f, 0.0f, 0.0f, 1.0f}, {SOCK_RGBA, "Color 2", 1.0f, 1.0f, 1.0f, 1.0f}
33
34/* Calls multitex and copies the result to the outputs.
35 * Called by xxx_exec, which handles inputs. */
36static void do_proc(float *result,
37 TexParams *p,
38 const float col1[4],
39 const float col2[4],
40 Tex *tex,
41 const short thread)
42{
43 TexResult texres;
44 int textype;
45
46 textype = multitex_nodes(tex, p->co, &texres, thread, 0, p->mtex, nullptr);
47
48 if (textype & TEX_RGB) {
49 copy_v4_v4(result, texres.trgba);
50 }
51 else {
52 copy_v4_v4(result, col1);
53 ramp_blend(MA_RAMP_BLEND, result, texres.tin, col2);
54 }
55}
56
57using MapFn = void (*)(Tex *tex, bNodeStack **in, TexParams *p, const short thread);
58
59static void texfn(
60 float *result, TexParams *p, bNode *node, bNodeStack **in, MapFn map_inputs, short thread)
61{
62 Tex tex = dna::shallow_copy(*(static_cast<Tex *>(node->storage)));
63 float col1[4], col2[4];
64 tex_input_rgba(col1, in[0], p, thread);
65 tex_input_rgba(col2, in[1], p, thread);
66
67 map_inputs(&tex, in, p, thread);
68
69 do_proc(result, p, col1, col2, &tex, thread);
70}
71
73{
74 return node->outputs.count();
75}
76
77/* Boilerplate generators */
78
79#define ProcNoInputs(name) \
80 static void name##_map_inputs( \
81 Tex * /*tex*/, bNodeStack ** /*in*/, TexParams * /*p*/, short /*thread*/) \
82 { \
83 }
84
85#define ProcDef(name) \
86 static void name##_colorfn( \
87 float *result, TexParams *p, bNode *node, bNodeStack **in, short thread) \
88 { \
89 texfn(result, p, node, in, &name##_map_inputs, thread); \
90 } \
91 static void name##_exec(void *data, \
92 int /*thread*/, \
93 bNode *node, \
94 bNodeExecData *execdata, \
95 bNodeStack **in, \
96 bNodeStack **out) \
97 { \
98 int outs = count_outputs(node); \
99 if (outs >= 1) { \
100 tex_output(node, execdata, in, out[0], &name##_colorfn, static_cast<TexCallData *>(data)); \
101 } \
102 }
103
104/* --- VORONOI -- */
107 {SOCK_FLOAT, N_("W1"), 1.0f, 0.0f, 0.0f, 0.0f, -2.0f, 2.0f, PROP_NONE},
108 {SOCK_FLOAT, N_("W2"), 0.0f, 0.0f, 0.0f, 0.0f, -2.0f, 2.0f, PROP_NONE},
109 {SOCK_FLOAT, N_("W3"), 0.0f, 0.0f, 0.0f, 0.0f, -2.0f, 2.0f, PROP_NONE},
110 {SOCK_FLOAT, N_("W4"), 0.0f, 0.0f, 0.0f, 0.0f, -2.0f, 2.0f, PROP_NONE},
111
112 {SOCK_FLOAT, N_("iScale"), 1.0f, 0.0f, 0.0f, 0.0f, 0.01f, 10.0f, PROP_UNSIGNED},
113 {SOCK_FLOAT, N_("Size"), 0.25f, 0.0f, 0.0f, 0.0f, 0.0001f, 4.0f, PROP_UNSIGNED},
114
115 {-1, ""}};
116static void voronoi_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread)
117{
118 tex->vn_w1 = tex_input_value(in[I + 0], p, thread);
119 tex->vn_w2 = tex_input_value(in[I + 1], p, thread);
120 tex->vn_w3 = tex_input_value(in[I + 2], p, thread);
121 tex->vn_w4 = tex_input_value(in[I + 3], p, thread);
122
123 tex->ns_outscale = tex_input_value(in[I + 4], p, thread);
124 tex->noisesize = tex_input_value(in[I + 5], p, thread);
125}
126ProcDef(voronoi);
127
128/* --- BLEND -- */
131ProcDef(blend);
132
133/* -- MAGIC -- */
136 {SOCK_FLOAT, N_("Turbulence"), 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 200.0f, PROP_UNSIGNED},
137 {-1, ""}};
138static void magic_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread)
139{
140 tex->turbul = tex_input_value(in[I + 0], p, thread);
141}
142ProcDef(magic);
143
144/* --- MARBLE --- */
147 {SOCK_FLOAT, N_("Size"), 0.25f, 0.0f, 0.0f, 0.0f, 0.0001f, 2.0f, PROP_UNSIGNED},
148 {SOCK_FLOAT, N_("Turbulence"), 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 200.0f, PROP_UNSIGNED},
149 {-1, ""}};
150static void marble_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread)
151{
152 tex->noisesize = tex_input_value(in[I + 0], p, thread);
153 tex->turbul = tex_input_value(in[I + 1], p, thread);
154}
155ProcDef(marble);
156
157/* --- CLOUDS --- */
160 {SOCK_FLOAT, N_("Size"), 0.25f, 0.0f, 0.0f, 0.0f, 0.0001f, 2.0f, PROP_UNSIGNED},
161 {-1, ""}};
162static void clouds_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread)
163{
164 tex->noisesize = tex_input_value(in[I + 0], p, thread);
165}
166ProcDef(clouds);
167
168/* --- DISTORTED NOISE --- */
171 {SOCK_FLOAT, N_("Size"), 0.25f, 0.0f, 0.0f, 0.0f, 0.0001f, 2.0f, PROP_UNSIGNED},
172 {SOCK_FLOAT, N_("Distortion"), 1.00f, 0.0f, 0.0f, 0.0f, 0.0000f, 10.0f, PROP_UNSIGNED},
173 {-1, ""}};
174static void distnoise_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread)
175{
176 tex->noisesize = tex_input_value(in[I + 0], p, thread);
177 tex->dist_amount = tex_input_value(in[I + 1], p, thread);
178}
179ProcDef(distnoise);
180
181/* --- WOOD --- */
184 {SOCK_FLOAT, N_("Size"), 0.25f, 0.0f, 0.0f, 0.0f, 0.0001f, 2.0f, PROP_UNSIGNED},
185 {SOCK_FLOAT, N_("Turbulence"), 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 200.0f, PROP_UNSIGNED},
186 {-1, ""}};
187static void wood_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread)
188{
189 tex->noisesize = tex_input_value(in[I + 0], p, thread);
190 tex->turbul = tex_input_value(in[I + 1], p, thread);
191}
193
194/* --- MUSGRAVE --- */
197 {SOCK_FLOAT, N_("H"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0001f, 2.0f, PROP_UNSIGNED},
198 {SOCK_FLOAT, N_("Lacunarity"), 2.0f, 0.0f, 0.0f, 0.0f, 0.0f, 6.0f, PROP_UNSIGNED},
199 {SOCK_FLOAT, N_("Octaves"), 2.0f, 0.0f, 0.0f, 0.0f, 0.0f, 8.0f, PROP_UNSIGNED},
200
201 {SOCK_FLOAT, N_("iScale"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 10.0f, PROP_UNSIGNED},
202 {SOCK_FLOAT, N_("Size"), 0.25f, 0.0f, 0.0f, 0.0f, 0.0001f, 2.0f, PROP_UNSIGNED},
203 {-1, ""}};
204static void musgrave_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread)
205{
206 tex->mg_H = tex_input_value(in[I + 0], p, thread);
207 tex->mg_lacunarity = tex_input_value(in[I + 1], p, thread);
208 tex->mg_octaves = tex_input_value(in[I + 2], p, thread);
209 tex->ns_outscale = tex_input_value(in[I + 3], p, thread);
210 tex->noisesize = tex_input_value(in[I + 4], p, thread);
211}
212ProcDef(musgrave);
213
214/* --- NOISE --- */
218
219/* --- STUCCI --- */
222 {SOCK_FLOAT, N_("Size"), 0.25f, 0.0f, 0.0f, 0.0f, 0.0001f, 2.0f, PROP_UNSIGNED},
223 {SOCK_FLOAT, N_("Turbulence"), 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 200.0f, PROP_UNSIGNED},
224 {-1, ""}};
225static void stucci_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread)
226{
227 tex->noisesize = tex_input_value(in[I + 0], p, thread);
228 tex->turbul = tex_input_value(in[I + 1], p, thread);
229}
230ProcDef(stucci);
231
232/* --- */
233
234static void init(bNodeTree * /*ntree*/, bNode *node)
235{
236 Tex *tex = MEM_new<Tex>("Tex");
237 node->storage = tex;
238
240 tex->type = eTex_Type(node->type_legacy - TEX_NODE_PROC);
241
242 if (tex->type == TEX_WOOD) {
243 tex->stype = TEX_BANDNOISE;
244 }
245}
246
247/* Node type definitions */
248#define TexDef(TEXTYPE, idname, outputs, name, Name, EnumNameLegacy) \
249 void register_node_type_tex_proc_##name(void) \
250 { \
251 static bke::bNodeType ntype; \
252\
253 tex_node_type_base(&ntype, UString(idname), TEX_NODE_PROC + TEXTYPE); \
254 ntype.ui_name = Name; \
255 ntype.enum_name_legacy = EnumNameLegacy; \
256 ntype.nclass = NODE_CLASS_TEXTURE; \
257 bke::node_type_socket_templates(&ntype, name##_inputs, outputs); \
258 ntype.default_width = bke::NodeWidth::_160; \
259 ntype.initfunc = init; \
260 bke::node_type_storage(ntype, "Tex", node_free_standard_storage, node_copy_standard_storage); \
261 ntype.exec_fn = name##_exec; \
262 ntype.flag |= NODE_PREVIEW; \
263\
264 bke::node_register_type(ntype); \
265 }
266
267#define C outputs_color_only
268#define CV outputs_both
269
270TexDef(TEX_VORONOI, "TextureNodeTexVoronoi", CV, voronoi, "Voronoi", "TEX_VORONOI");
271TexDef(TEX_BLEND, "TextureNodeTexBlend", C, blend, "Blend", "TEX_BLEND");
272TexDef(TEX_MAGIC, "TextureNodeTexMagic", C, magic, "Magic", "TEX_MAGIC");
273TexDef(TEX_MARBLE, "TextureNodeTexMarble", CV, marble, "Marble", "TEX_MARBLE");
274TexDef(TEX_CLOUDS, "TextureNodeTexClouds", CV, clouds, "Clouds", "TEX_CLOUDS");
275TexDef(TEX_WOOD, "TextureNodeTexWood", CV, wood, "Wood", "TEX_WOOD");
276TexDef(TEX_MUSGRAVE, "TextureNodeTexMusgrave", CV, musgrave, "Musgrave", "TEX_MUSGRAVE");
277TexDef(TEX_NOISE, "TextureNodeTexNoise", C, noise, "Noise", "TEX_NOISE");
278TexDef(TEX_STUCCI, "TextureNodeTexStucci", CV, stucci, "Stucci", "TEX_STUCCI");
280 TEX_DISTNOISE, "TextureNodeTexDistNoise", CV, distnoise, "Distorted Noise", "TEX_DISTNOISE");
281
282} // namespace blender
General operations, lookup, etc. for materials.
#define TEX_NODE_PROC
#define C
Definition RandGen.cpp:29
internal::ShallowDataConstRef< T > shallow_copy(const T &other)
Definition DNA_defs.h:147
BMesh Iterators.
void ramp_blend(int type, float r_col[4], float fac, const float col[4])
static void stucci_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread)
static bke::bNodeSocketTemplate outputs_both[]
void tex_input_rgba(float *out, bNodeStack *in, TexParams *params, short thread)
static void clouds_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread)
static void distnoise_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread)
static bke::bNodeSocketTemplate outputs_color_only[]
static void texfn(float *result, TexParams *p, bNode *node, bNodeStack **in, MapFn map_inputs, short thread)
static bke::bNodeSocketTemplate blend_inputs[]
static bke::bNodeSocketTemplate noise_inputs[]
static void musgrave_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread)
static void voronoi_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread)
static bke::bNodeSocketTemplate clouds_inputs[]
ProcDef(voronoi)
static bke::bNodeSocketTemplate marble_inputs[]
void BKE_texture_default(struct Tex *tex)
Definition texture.cc:358
static bke::bNodeSocketTemplate magic_inputs[]
static int count_outputs(bNode *node)
ProcNoInputs(blend)
static bke::bNodeSocketTemplate wood_inputs[]
TexDef(TEX_VORONOI, "TextureNodeTexVoronoi", CV, voronoi, "Voronoi", "TEX_VORONOI")
int multitex_nodes(Tex *tex, const float texvec[3], TexResult *texres, const short thread, short which_output, const MTex *mtex, ImagePool *pool)
float tex_input_value(bNodeStack *in, TexParams *params, short thread)
static void do_proc(float *result, TexParams *p, const float col1[4], const float col2[4], Tex *tex, const short thread)
static bke::bNodeSocketTemplate voronoi_inputs[]
void(*)(Tex *tex, bNodeStack **in, TexParams *p, const short thread) MapFn
static bke::bNodeSocketTemplate distnoise_inputs[]
MINLINE void copy_v4_v4(float r[4], const float a[4])
@ PROP_UNSIGNED
Definition RNA_types.hh:306
static void marble_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread)
static bke::bNodeSocketTemplate musgrave_inputs[]
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)
static bke::bNodeSocketTemplate stucci_inputs[]
#define I
#define CV
#define COMMON_INPUTS
Compact definition of a node socket.
Definition BKE_node.hh:102
#define N_(msgid)