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