Blender  V3.3
node_texture_texture.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 #include "NOD_texture.h"
9 #include "node_texture_util.h"
10 
11 #include "RE_texture.h"
12 
14  {SOCK_RGBA, N_("Color1"), 1.0f, 1.0f, 1.0f, 1.0f},
15  {SOCK_RGBA, N_("Color2"), 0.0f, 0.0f, 0.0f, 1.0f},
16  {-1, ""},
17 };
18 
20  {SOCK_RGBA, N_("Color")},
21  {-1, ""},
22 };
23 
24 static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread)
25 {
26  Tex *nodetex = (Tex *)node->id;
27  static float red[] = {1, 0, 0, 1};
28  static float white[] = {1, 1, 1, 1};
29  float co[3], dxt[3], dyt[3];
30 
31  copy_v3_v3(co, p->co);
32  if (p->osatex) {
33  copy_v3_v3(dxt, p->dxt);
34  copy_v3_v3(dyt, p->dyt);
35  }
36  else {
37  zero_v3(dxt);
38  zero_v3(dyt);
39  }
40 
41  if (node->custom2 || node->need_exec == 0) {
42  /* this node refers to its own texture tree! */
43  copy_v4_v4(out, (fabsf(co[0] - co[1]) < 0.01f) ? white : red);
44  }
45  else if (nodetex) {
46  TexResult texres;
47  int textype;
48  float col1[4], col2[4];
49 
50  tex_input_rgba(col1, in[0], p, thread);
51  tex_input_rgba(col2, in[1], p, thread);
52 
53  textype = multitex_nodes(nodetex, co, dxt, dyt, p->osatex, &texres, thread, 0, p->mtex, NULL);
54 
55  if (textype & TEX_RGB) {
56  copy_v4_v4(out, texres.trgba);
57  }
58  else {
59  copy_v4_v4(out, col1);
60  ramp_blend(MA_RAMP_BLEND, out, texres.tin, col2);
61  }
62  }
63 }
64 
65 static void exec(void *data,
66  int UNUSED(thread),
67  bNode *node,
68  bNodeExecData *execdata,
69  bNodeStack **in,
70  bNodeStack **out)
71 {
72  tex_output(node, execdata, in, out[0], &colorfn, data);
73 }
74 
76 {
77  static bNodeType ntype;
78 
81  node_type_exec(&ntype, NULL, NULL, exec);
82  ntype.flag |= NODE_PREVIEW;
83 
84  nodeRegisterType(&ntype);
85 }
void ramp_blend(int type, float r_col[3], float fac, const float col[3])
Definition: material.c:1611
void node_type_socket_templates(struct bNodeType *ntype, struct bNodeSocketTemplate *inputs, struct bNodeSocketTemplate *outputs)
Definition: node.cc:4358
#define TEX_NODE_TEXTURE
Definition: BKE_node.h:1349
#define NODE_CLASS_INPUT
Definition: BKE_node.h:345
void node_type_exec(struct bNodeType *ntype, NodeInitExecFunction init_exec_fn, NodeFreeExecFunction free_exec_fn, NodeExecFunction exec_fn)
Definition: node.cc:4455
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1357
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 MA_RAMP_BLEND
#define NODE_PREVIEW
@ SOCK_RGBA
#define TEX_RGB
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to used to fine tune the interpolation of the input Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp a value between a minimum and a maximum Vector Perform vector math operation Invert a producing a negative Combine Generate a color from its red
Definition: thread.h:34
OperationNode * node
#define fabsf(x)
Definition: metal/compat.h:219
static const pxr::TfToken out("out", pxr::TfToken::Immortal)
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_input_rgba(float *out, bNodeStack *in, TexParams *params, short thread)
void tex_node_type_base(struct bNodeType *ntype, int type, const char *name, short nclass)
void tex_output(bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack *out, TexFn texfn, TexCallData *cdata)
float tin
Definition: RE_texture.h:86
float trgba[4]
Definition: RE_texture.h:87
Compact definition of a node socket.
Definition: BKE_node.h:84
Defines a node type.
Definition: BKE_node.h:226
short flag
Definition: BKE_node.h:236
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)
#define N_(msgid)