Blender V5.3
node_texture_texture.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
10
11#include "BKE_material.hh"
12#include "BKE_node_runtime.hh"
13
14#include "BLI_math_vector_c.hh"
15
16#include "DNA_material_types.h"
17
18#include "RE_texture.h"
19
20namespace blender {
21
23 {SOCK_RGBA, N_("Color1"), 1.0f, 1.0f, 1.0f, 1.0f},
24 {SOCK_RGBA, N_("Color2"), 0.0f, 0.0f, 0.0f, 1.0f},
25 {-1, ""},
26};
27
29 {SOCK_RGBA, N_("Color")},
30 {-1, ""},
31};
32
33static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread)
34{
35 Tex *nodetex = id_cast<Tex *>(node->id);
36 static float red[] = {1, 0, 0, 1};
37 static float white[] = {1, 1, 1, 1};
38 float co[3];
39
40 copy_v3_v3(co, p->co);
41
42 if (node->custom2 || node->runtime->need_exec == 0) {
43 /* this node refers to its own texture tree! */
44 copy_v4_v4(out, (fabsf(co[0] - co[1]) < 0.01f) ? white : red);
45 }
46 else if (nodetex) {
47 TexResult texres;
48 int textype;
49 float col1[4], col2[4];
50
51 tex_input_rgba(col1, in[0], p, thread);
52 tex_input_rgba(col2, in[1], p, thread);
53
54 textype = multitex_nodes(nodetex, co, &texres, thread, 0, p->mtex, nullptr);
55
56 if (textype & TEX_RGB) {
57 copy_v4_v4(out, texres.trgba);
58 }
59 else {
60 copy_v4_v4(out, col1);
61 ramp_blend(MA_RAMP_BLEND, out, texres.tin, col2);
62 }
63 }
64}
65
66static void exec(void *data,
67 int /*thread*/,
68 bNode *node,
69 bNodeExecData *execdata,
70 bNodeStack **in,
72{
73 tex_output(node, execdata, in, out[0], &colorfn, static_cast<TexCallData *>(data));
74}
75
77{
78 static bke::bNodeType ntype;
79
80 tex_node_type_base(&ntype, "TextureNodeTexture"_ustr, TEX_NODE_TEXTURE);
81 ntype.ui_name = "Texture";
82 ntype.enum_name_legacy = "TEXTURE";
85 ntype.exec_fn = exec;
86 ntype.flag |= NODE_PREVIEW;
87
89}
90
91} // namespace blender
General operations, lookup, etc. for materials.
#define NODE_CLASS_INPUT
Definition BKE_node.hh:478
#define TEX_NODE_TEXTURE
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
void node_type_socket_templates(bNodeType *ntype, bNodeSocketTemplate *inputs, bNodeSocketTemplate *outputs)
Definition node.cc:6134
BMesh Iterators.
void ramp_blend(int type, float r_col[4], float fac, const float col[4])
MINLINE void copy_v3_v3(float r[3], const float a[3])
static void exec(void *data, int, bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out)
void tex_input_rgba(float *out, bNodeStack *in, TexParams *params, short thread)
static void colorfn(float *out, TexParams *p, bNode *, bNodeStack **in, short thread)
BMesh const char void * data
void tex_output(bNode *node, bNodeExecData *, bNodeStack **in, bNodeStack *out, TexFn texfn, TexCallData *cdata)
void register_node_type_tex_texture()
static bke::bNodeSocketTemplate inputs[]
void tex_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
int multitex_nodes(Tex *tex, const float texvec[3], TexResult *texres, const short thread, short which_output, const MTex *mtex, ImagePool *pool)
static bke::bNodeSocketTemplate outputs[]
MINLINE void copy_v4_v4(float r[4], const float a[4])
#define fabsf
Compact definition of a node socket.
Definition BKE_node.hh:102
Defines a node type.
Definition BKE_node.hh:265
NodeExecFunction exec_fn
Definition BKE_node.hh:371
const char * enum_name_legacy
Definition BKE_node.hh:274
#define N_(msgid)