Blender  V2.93
node_texture_texture.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2005 Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #include "NOD_texture.h"
25 #include "node_texture_util.h"
26 
27 #include "RE_texture.h"
28 
30  {SOCK_RGBA, N_("Color1"), 1.0f, 1.0f, 1.0f, 1.0f},
31  {SOCK_RGBA, N_("Color2"), 0.0f, 0.0f, 0.0f, 1.0f},
32  {-1, ""},
33 };
34 
36  {SOCK_RGBA, N_("Color")},
37  {-1, ""},
38 };
39 
40 static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread)
41 {
42  Tex *nodetex = (Tex *)node->id;
43  static float red[] = {1, 0, 0, 1};
44  static float white[] = {1, 1, 1, 1};
45  float co[3], dxt[3], dyt[3];
46 
47  copy_v3_v3(co, p->co);
48  if (p->osatex) {
49  copy_v3_v3(dxt, p->dxt);
50  copy_v3_v3(dyt, p->dyt);
51  }
52  else {
53  zero_v3(dxt);
54  zero_v3(dyt);
55  }
56 
57  if (node->custom2 || node->need_exec == 0) {
58  /* this node refers to its own texture tree! */
59  copy_v4_v4(out, (fabsf(co[0] - co[1]) < 0.01f) ? white : red);
60  }
61  else if (nodetex) {
62  TexResult texres;
63  int textype;
64  float nor[] = {0, 0, 0};
65  float col1[4], col2[4];
66 
67  tex_input_rgba(col1, in[0], p, thread);
68  tex_input_rgba(col2, in[1], p, thread);
69 
70  texres.nor = nor;
71  textype = multitex_nodes(nodetex, co, dxt, dyt, p->osatex, &texres, thread, 0, p->mtex, NULL);
72 
73  if (textype & TEX_RGB) {
74  copy_v4_v4(out, &texres.tr);
75  }
76  else {
77  copy_v4_v4(out, col1);
78  ramp_blend(MA_RAMP_BLEND, out, texres.tin, col2);
79  }
80  }
81 }
82 
83 static void exec(void *data,
84  int UNUSED(thread),
85  bNode *node,
86  bNodeExecData *execdata,
87  bNodeStack **in,
88  bNodeStack **out)
89 {
90  tex_output(node, execdata, in, out[0], &colorfn, data);
91 }
92 
94 {
95  static bNodeType ntype;
96 
99  node_type_exec(&ntype, NULL, NULL, exec);
100 
101  nodeRegisterType(&ntype);
102 }
void ramp_blend(int type, float r_col[3], const float fac, const float col[3])
Definition: material.c:1395
void node_type_socket_templates(struct bNodeType *ntype, struct bNodeSocketTemplate *inputs, struct bNodeSocketTemplate *outputs)
Definition: node.cc:4527
#define TEX_NODE_TEXTURE
Definition: BKE_node.h:1327
#define NODE_CLASS_INPUT
Definition: BKE_node.h:334
void node_type_exec(struct bNodeType *ntype, NodeInitExecFunction init_exec_fn, NodeFreeExecFunction free_exec_fn, NodeExecFunction exec_fn)
Definition: node.cc:4635
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1298
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])
#define UNUSED(x)
#define N_(msgid)
#define MA_RAMP_BLEND
#define NODE_PREVIEW
@ SOCK_RGBA
#define TEX_RGB
OperationNode * node
uint nor
#define fabsf(x)
static bNodeSocketTemplate outputs[]
static bNodeSocketTemplate inputs[]
static void exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out)
static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread)
void register_node_type_tex_texture(void)
void tex_node_type_base(struct bNodeType *ntype, int type, const char *name, short nclass, short flag)
void tex_input_rgba(float *out, bNodeStack *in, TexParams *params, short thread)
void tex_output(bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack *out, TexFn texfn, TexCallData *cdata)
float * nor
Definition: RE_texture.h:86
float tin
Definition: RE_texture.h:84
float tr
Definition: RE_texture.h:84
Compact definition of a node socket.
Definition: BKE_node.h:95
Defines a node type.
Definition: BKE_node.h:221
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, MTex *mtex, struct ImagePool *pool)