Blender  V3.3
node_texture_rotate.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 <math.h>
9 
10 #include "NOD_texture.h"
11 #include "node_texture_util.h"
12 
14  {SOCK_RGBA, N_("Color"), 0.0f, 0.0f, 0.0f, 1.0f},
15  {SOCK_FLOAT, N_("Turns"), 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f, PROP_NONE},
16  {SOCK_VECTOR, N_("Axis"), 0.0f, 0.0f, 1.0f, 0.0f, -1.0f, 1.0f, PROP_DIRECTION},
17  {-1, ""},
18 };
19 
21  {SOCK_RGBA, N_("Color")},
22  {-1, ""},
23 };
24 
25 static void rotate(float new_co[3], float a, const float ax[3], const float co[3])
26 {
27  float para[3];
28  float perp[3];
29  float cp[3];
30 
31  float cos_a = cosf(a * (float)(2 * M_PI));
32  float sin_a = sinf(a * (float)(2 * M_PI));
33 
34  /* `x' = xcosa + n(n.x)(1-cosa) + (x*n)sina`. */
35 
36  mul_v3_v3fl(perp, co, cos_a);
37  mul_v3_v3fl(para, ax, dot_v3v3(co, ax) * (1 - cos_a));
38 
39  cross_v3_v3v3(cp, ax, co);
40  mul_v3_fl(cp, sin_a);
41 
42  new_co[0] = para[0] + perp[0] + cp[0];
43  new_co[1] = para[1] + perp[1] + cp[1];
44  new_co[2] = para[2] + perp[2] + cp[2];
45 }
46 
47 static void colorfn(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **in, short thread)
48 {
49  float new_co[3], new_dxt[3], new_dyt[3], a, ax[3];
50 
51  a = tex_input_value(in[1], p, thread);
52  tex_input_vec(ax, in[2], p, thread);
53 
54  rotate(new_co, a, ax, p->co);
55  if (p->osatex) {
56  rotate(new_dxt, a, ax, p->dxt);
57  rotate(new_dyt, a, ax, p->dyt);
58  }
59 
60  {
61  TexParams np = *p;
62  np.co = new_co;
63  np.dxt = new_dxt;
64  np.dyt = new_dyt;
65  tex_input_rgba(out, in[0], &np, thread);
66  }
67 }
68 static void exec(void *data,
69  int UNUSED(thread),
70  bNode *node,
71  bNodeExecData *execdata,
72  bNodeStack **in,
73  bNodeStack **out)
74 {
75  tex_output(node, execdata, in, out[0], &colorfn, data);
76 }
77 
79 {
80  static bNodeType ntype;
81 
84  node_type_exec(&ntype, NULL, NULL, exec);
85 
86  nodeRegisterType(&ntype);
87 }
void node_type_socket_templates(struct bNodeType *ntype, struct bNodeSocketTemplate *inputs, struct bNodeSocketTemplate *outputs)
Definition: node.cc:4358
#define TEX_NODE_ROTATE
Definition: BKE_node.h:1360
#define NODE_CLASS_DISTORT
Definition: BKE_node.h:353
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
#define M_PI
Definition: BLI_math_base.h:20
MINLINE void mul_v3_fl(float r[3], float f)
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void mul_v3_v3fl(float r[3], const float a[3], float f)
#define UNUSED(x)
@ SOCK_VECTOR
@ SOCK_FLOAT
@ SOCK_RGBA
@ PROP_DIRECTION
Definition: RNA_types.h:155
@ PROP_NONE
Definition: RNA_types.h:126
Definition: thread.h:34
#define sinf(x)
Definition: cuda/compat.h:102
#define cosf(x)
Definition: cuda/compat.h:101
OperationNode * node
static unsigned a[3]
Definition: RandGen.cpp:78
static const pxr::TfToken out("out", pxr::TfToken::Immortal)
void register_node_type_tex_rotate(void)
static bNodeSocketTemplate outputs[]
static bNodeSocketTemplate inputs[]
static void colorfn(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **in, short thread)
static void rotate(float new_co[3], float a, const float ax[3], const float co[3])
static void exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out)
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)
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)
const float * co
Compact definition of a node socket.
Definition: BKE_node.h:84
Defines a node type.
Definition: BKE_node.h:226
#define N_(msgid)