Blender  V3.3
node_texture_util.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2005 Blender Foundation. All rights reserved. */
3 
8 /*
9  * HOW TEXTURE NODES WORK
10  *
11  * In contrast to Shader nodes, which place a color into the output
12  * stack when executed, Texture nodes place a TexDelegate* there. To
13  * obtain a color value from this, a node further up the chain reads
14  * the TexDelegate* from its input stack, and uses tex_call_delegate to
15  * retrieve the color from the delegate.
16  *
17  * comments: (ton)
18  *
19  * This system needs recode, a node system should rely on the stack, and
20  * callbacks for nodes only should evaluate own node, not recursively go
21  * over other previous ones.
22  */
23 
24 #include "node_texture_util.h"
25 
28  const char **r_disabled_hint)
29 {
30  if (!STREQ(ntree->idname, "TextureNodeTree")) {
31  *r_disabled_hint = TIP_("Not a texture node tree");
32  return false;
33  }
34  return true;
35 }
36 
37 void tex_node_type_base(struct bNodeType *ntype, int type, const char *name, short nclass)
38 {
39  node_type_base(ntype, type, name, nclass);
40 
41  ntype->poll = tex_node_poll_default;
43 }
44 
45 static void tex_call_delegate(TexDelegate *dg, float *out, TexParams *params, short thread)
46 {
47  if (dg->node->need_exec) {
48  dg->fn(out, params, dg->node, dg->in, thread);
49  }
50 }
51 
52 static void tex_input(float *out, int num, bNodeStack *in, TexParams *params, short thread)
53 {
54  TexDelegate *dg = in->data;
55  if (dg) {
57 
58  if (in->hasoutput && in->sockettype == SOCK_FLOAT) {
59  in->vec[1] = in->vec[2] = in->vec[0];
60  }
61  }
62  memcpy(out, in->vec, num * sizeof(float));
63 }
64 
65 void tex_input_vec(float *out, bNodeStack *in, TexParams *params, short thread)
66 {
67  tex_input(out, 3, in, params, thread);
68 }
69 
70 void tex_input_rgba(float *out, bNodeStack *in, TexParams *params, short thread)
71 {
72  tex_input(out, 4, in, params, thread);
73 
74  if (in->hasoutput && in->sockettype == SOCK_FLOAT) {
75  out[1] = out[2] = out[0];
76  out[3] = 1;
77  }
78 
79  if (in->hasoutput && in->sockettype == SOCK_VECTOR) {
80  out[0] = out[0] * 0.5f + 0.5f;
81  out[1] = out[1] * 0.5f + 0.5f;
82  out[2] = out[2] * 0.5f + 0.5f;
83  out[3] = 1;
84  }
85 }
86 
88 {
89  float out[4];
91  return out[0];
92 }
93 
95 {
96  out->co = in->co;
97  out->dxt = in->dxt;
98  out->dyt = in->dyt;
99  out->previewco = in->co;
100  out->osatex = in->osatex;
101  out->cfra = in->cfra;
102  out->mtex = in->mtex;
103 }
104 
106  bNodeExecData *execdata,
107  bNodeStack **in,
108  bNodeStack *out,
109  TexFn texfn,
110  TexCallData *cdata)
111 {
112  TexDelegate *dg;
113 
114  if (node->flag & NODE_MUTED) {
115  /* do not add a delegate if the node is muted */
116  return;
117  }
118 
119  if (!out->data) {
120  /* Freed in tex_end_exec (node.cc) */
121  dg = out->data = MEM_mallocN(sizeof(TexDelegate), "tex delegate");
122  }
123  else {
124  dg = out->data;
125  }
126 
127  dg->cdata = cdata;
128  dg->fn = texfn;
129  dg->node = node;
130  dg->preview = execdata->preview;
131  memcpy(dg->in, in, MAX_SOCKET * sizeof(bNodeStack *));
132  dg->type = out->sockettype;
133 }
134 
136 {
137  bNode *node;
138  for (node = ntree->nodes.first; node; node = node->next) {
139 
140  if (node->type == TEX_NODE_TEXTURE && node->id) {
141  /* custom2 stops the node from rendering */
142  if (node->custom1) {
143  node->custom2 = 1;
144  node->custom1 = 0;
145  }
146  else {
147  Tex *tex = (Tex *)node->id;
148 
149  node->custom2 = 0;
150 
151  node->custom1 = 1;
152  if (tex->use_nodes && tex->nodetree) {
154  }
155  node->custom1 = 0;
156  }
157  }
158  }
159 }
void node_type_base(struct bNodeType *ntype, int type, const char *name, short nclass)
Definition: node.cc:4277
#define TEX_NODE_TEXTURE
Definition: BKE_node.h:1349
#define MAX_SOCKET
Definition: BKE_node.h:30
#define UNUSED(x)
#define STREQ(a, b)
#define TIP_(msgid)
#define NODE_MUTED
@ SOCK_VECTOR
@ SOCK_FLOAT
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
Definition: thread.h:34
OperationNode * node
bNodeTree * ntree
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void *(* MEM_mallocN)(size_t len, const char *str)
Definition: mallocn.c:33
static const pxr::TfToken out("out", pxr::TfToken::Immortal)
static void texfn(float *result, TexParams *p, bNode *node, bNodeStack **in, MapFn map_inputs, short thread)
void tex_input_vec(float *out, bNodeStack *in, TexParams *params, short thread)
float tex_input_value(bNodeStack *in, TexParams *params, short thread)
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_node_type_base(struct bNodeType *ntype, int type, const char *name, short nclass)
bool tex_node_poll_default(bNodeType *UNUSED(ntype), bNodeTree *ntree, const char **r_disabled_hint)
void tex_output(bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack *out, TexFn texfn, TexCallData *cdata)
void ntreeTexCheckCyclics(struct bNodeTree *ntree)
void params_from_cdata(TexParams *out, TexCallData *in)
static void tex_input(float *out, int num, bNodeStack *in, TexParams *params, short thread)
void(* TexFn)(float *out, TexParams *params, bNode *node, bNodeStack **in, short thread)
void node_insert_link_default(bNodeTree *ntree, bNode *node, bNodeLink *link)
Definition: node_util.c:326
void * first
Definition: DNA_listBase.h:31
const float * co
bNodePreview * preview
bNodeStack * in[MAX_SOCKET]
TexCallData * cdata
char use_nodes
struct bNodeTree * nodetree
short hasoutput
short sockettype
float vec[4]
char idname[64]
ListBase nodes
Defines a node type.
Definition: BKE_node.h:226
bool(* poll)(struct bNodeType *ntype, struct bNodeTree *nodetree, const char **r_disabled_hint)
Definition: BKE_node.h:292
void(* insert_link)(struct bNodeTree *ntree, struct bNode *node, struct bNodeLink *link)
Definition: BKE_node.h:301
uint8_t need_exec