Blender V4.5
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], dxt[3], dyt[3];
37
38 copy_v3_v3(co, p->co);
39 if (p->osatex) {
40 copy_v3_v3(dxt, p->dxt);
41 copy_v3_v3(dyt, p->dyt);
42 }
43 else {
44 zero_v3(dxt);
45 zero_v3(dyt);
46 }
47
48 if (node->custom2 || node->runtime->need_exec == 0) {
49 /* this node refers to its own texture tree! */
50 copy_v4_v4(out, (fabsf(co[0] - co[1]) < 0.01f) ? white : red);
51 }
52 else if (nodetex) {
53 TexResult texres;
54 int textype;
55 float col1[4], col2[4];
56
57 tex_input_rgba(col1, in[0], p, thread);
58 tex_input_rgba(col2, in[1], p, thread);
59
60 textype = multitex_nodes(
61 nodetex, co, dxt, dyt, p->osatex, &texres, thread, 0, p->mtex, nullptr);
62
63 if (textype & TEX_RGB) {
64 copy_v4_v4(out, texres.trgba);
65 }
66 else {
67 copy_v4_v4(out, col1);
68 ramp_blend(MA_RAMP_BLEND, out, texres.tin, col2);
69 }
70 }
71}
72
73static void exec(void *data,
74 int /*thread*/,
75 bNode *node,
76 bNodeExecData *execdata,
77 bNodeStack **in,
79{
80 tex_output(node, execdata, in, out[0], &colorfn, static_cast<TexCallData *>(data));
81}
82
84{
85 static blender::bke::bNodeType ntype;
86
87 tex_node_type_base(&ntype, "TextureNodeTexture", TEX_NODE_TEXTURE);
88 ntype.ui_name = "Texture";
89 ntype.enum_name_legacy = "TEXTURE";
92 ntype.exec_fn = exec;
93 ntype.flag |= NODE_PREVIEW;
94
96}
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:433
#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])
MINLINE void zero_v3(float r[3])
@ MA_RAMP_BLEND
@ NODE_PREVIEW
@ SOCK_RGBA
@ TEX_RGB
BMesh const char void * data
#define fabsf(x)
#define in
#define out
void node_register_type(bNodeType &ntype)
Definition node.cc:2748
void node_type_socket_templates(bNodeType *ntype, bNodeSocketTemplate *inputs, bNodeSocketTemplate *outputs)
Definition node.cc:5541
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)
const MTex * mtex
const float * co
float tin
Definition RE_texture.h:83
float trgba[4]
Definition RE_texture.h:84
struct ID * id
bNodeRuntimeHandle * runtime
int16_t custom2
Compact definition of a node socket.
Definition BKE_node.hh:98
Defines a node type.
Definition BKE_node.hh:226
NodeExecFunction exec_fn
Definition BKE_node.hh:328
const char * enum_name_legacy
Definition BKE_node.hh:235
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, const MTex *mtex, ImagePool *pool)
#define N_(msgid)