Blender V4.3
node_texture_util.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
9/*
10 * HOW TEXTURE NODES WORK
11 *
12 * In contrast to Shader nodes, which place a color into the output
13 * stack when executed, Texture nodes place a TexDelegate* there. To
14 * obtain a color value from this, a node further up the chain reads
15 * the TexDelegate* from its input stack, and uses tex_call_delegate to
16 * retrieve the color from the delegate.
17 *
18 * comments: (ton)
19 *
20 * This system needs recode, a node system should rely on the stack, and
21 * callbacks for nodes only should evaluate their own node, not recursively go
22 * over other previous ones.
23 */
24
25#include "BKE_node_runtime.hh"
26
27#include "NOD_texture.h"
28
29#include "node_texture_util.hh"
30#include "node_util.hh"
31
33 const bNodeTree *ntree,
34 const char **r_disabled_hint)
35{
36 if (!STREQ(ntree->idname, "TextureNodeTree")) {
37 *r_disabled_hint = RPT_("Not a texture node tree");
38 return false;
39 }
40 return true;
41}
42
43void tex_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
44{
45 blender::bke::node_type_base(ntype, type, name, nclass);
46
49}
50
51static void tex_call_delegate(TexDelegate *dg, float *out, TexParams *params, short thread)
52{
53 if (dg->node->runtime->need_exec) {
54 dg->fn(out, params, dg->node, dg->in, thread);
55 }
56}
57
58static void tex_input(float *out, int num, bNodeStack *in, TexParams *params, short thread)
59{
60 TexDelegate *dg = static_cast<TexDelegate *>(in->data);
61 if (dg) {
62 tex_call_delegate(dg, in->vec, params, thread);
63
64 if (in->hasoutput && in->sockettype == SOCK_FLOAT) {
65 in->vec[1] = in->vec[2] = in->vec[0];
66 }
67 }
68 memcpy(out, in->vec, num * sizeof(float));
69}
70
71void tex_input_vec(float *out, bNodeStack *in, TexParams *params, short thread)
72{
73 tex_input(out, 3, in, params, thread);
74}
75
76void tex_input_rgba(float *out, bNodeStack *in, TexParams *params, short thread)
77{
78 tex_input(out, 4, in, params, thread);
79
80 if (in->hasoutput && in->sockettype == SOCK_FLOAT) {
81 out[1] = out[2] = out[0];
82 out[3] = 1;
83 }
84
85 if (in->hasoutput && in->sockettype == SOCK_VECTOR) {
86 out[0] = out[0] * 0.5f + 0.5f;
87 out[1] = out[1] * 0.5f + 0.5f;
88 out[2] = out[2] * 0.5f + 0.5f;
89 out[3] = 1;
90 }
91}
92
94{
95 float out[4];
96 tex_input_vec(out, in, params, thread);
97 return out[0];
98}
99
101{
102 out->co = in->co;
103 out->dxt = in->dxt;
104 out->dyt = in->dyt;
105 out->previewco = in->co;
106 out->osatex = in->osatex;
107 out->cfra = in->cfra;
108 out->mtex = in->mtex;
109}
110
111void tex_output(bNode *node,
112 bNodeExecData *execdata,
113 bNodeStack **in,
114 bNodeStack *out,
115 TexFn texfn,
116 TexCallData *cdata)
117{
118 TexDelegate *dg;
119
120 if (node->flag & NODE_MUTED) {
121 /* do not add a delegate if the node is muted */
122 return;
123 }
124
125 if (!out->data) {
126 /* Freed in tex_end_exec (node.cc) */
127 dg = MEM_cnew<TexDelegate>("tex delegate");
128 out->data = dg;
129 }
130 else {
131 dg = static_cast<TexDelegate *>(out->data);
132 }
133
134 dg->cdata = cdata;
135 dg->fn = texfn;
136 dg->node = node;
137 dg->preview = execdata->preview;
138 memcpy(dg->in, in, MAX_SOCKET * sizeof(bNodeStack *));
139 dg->type = out->sockettype;
140}
141
143{
144 LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
145
146 if (node->type == TEX_NODE_TEXTURE && node->id) {
147 /* custom2 stops the node from rendering */
148 if (node->custom1) {
149 node->custom2 = 1;
150 node->custom1 = 0;
151 }
152 else {
153 Tex *tex = (Tex *)node->id;
154
155 node->custom2 = 0;
156
157 node->custom1 = 1;
158 if (tex->use_nodes && tex->nodetree) {
160 }
161 node->custom1 = 0;
162 }
163 }
164 }
165}
#define MAX_SOCKET
Definition BKE_node.hh:29
#define LISTBASE_FOREACH(type, var, list)
#define STREQ(a, b)
#define RPT_(msgid)
@ NODE_MUTED
@ SOCK_VECTOR
@ SOCK_FLOAT
OperationNode * node
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void node_type_base(bNodeType *ntype, int type, const char *name, short nclass)
Definition node.cc:4325
static void texfn(float *result, TexParams *p, bNode *node, bNodeStack **in, MapFn map_inputs, short thread)
void tex_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
void tex_input_vec(float *out, bNodeStack *in, TexParams *params, short thread)
float tex_input_value(bNodeStack *in, TexParams *params, short thread)
bool tex_node_poll_default(const blender::bke::bNodeType *, const bNodeTree *ntree, const char **r_disabled_hint)
void tex_input_rgba(float *out, bNodeStack *in, TexParams *params, short thread)
static void tex_call_delegate(TexDelegate *dg, float *out, TexParams *params, short thread)
void tex_output(bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack *out, TexFn texfn, TexCallData *cdata)
void params_from_cdata(TexParams *out, TexCallData *in)
void ntreeTexCheckCyclics(bNodeTree *ntree)
static void tex_input(float *out, int num, bNodeStack *in, TexParams *params, short thread)
void(*)(float *out, TexParams *params, bNode *node, bNodeStack **in, short thread) TexFn
bool node_insert_link_default(bNodeTree *, bNode *, bNodeLink *)
Definition node_util.cc:281
bNodePreview * preview
bNodeStack * in[MAX_SOCKET]
TexCallData * cdata
char use_nodes
struct bNodeTree * nodetree
bNodePreview * preview
Definition node_util.hh:24
char idname[64]
ListBase nodes
bNodeRuntimeHandle * runtime
Defines a node type.
Definition BKE_node.hh:218
bool(* poll)(const bNodeType *ntype, const bNodeTree *nodetree, const char **r_disabled_hint)
Definition BKE_node.hh:299
bool(* insert_link)(bNodeTree *ntree, bNode *node, bNodeLink *link)
Definition BKE_node.hh:309