Blender  V2.93
node_texture_rotate.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 <math.h>
25 
26 #include "NOD_texture.h"
27 #include "node_texture_util.h"
28 
30  {SOCK_RGBA, N_("Color"), 0.0f, 0.0f, 0.0f, 1.0f},
31  {SOCK_FLOAT, N_("Turns"), 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f, PROP_NONE},
32  {SOCK_VECTOR, N_("Axis"), 0.0f, 0.0f, 1.0f, 0.0f, -1.0f, 1.0f, PROP_DIRECTION},
33  {-1, ""},
34 };
35 
37  {SOCK_RGBA, N_("Color")},
38  {-1, ""},
39 };
40 
41 static void rotate(float new_co[3], float a, const float ax[3], const float co[3])
42 {
43  float para[3];
44  float perp[3];
45  float cp[3];
46 
47  float cos_a = cosf(a * (float)(2 * M_PI));
48  float sin_a = sinf(a * (float)(2 * M_PI));
49 
50  // x' = xcosa + n(n.x)(1-cosa) + (x*n)sina
51 
52  mul_v3_v3fl(perp, co, cos_a);
53  mul_v3_v3fl(para, ax, dot_v3v3(co, ax) * (1 - cos_a));
54 
55  cross_v3_v3v3(cp, ax, co);
56  mul_v3_fl(cp, sin_a);
57 
58  new_co[0] = para[0] + perp[0] + cp[0];
59  new_co[1] = para[1] + perp[1] + cp[1];
60  new_co[2] = para[2] + perp[2] + cp[2];
61 }
62 
63 static void colorfn(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **in, short thread)
64 {
65  float new_co[3], new_dxt[3], new_dyt[3], a, ax[3];
66 
67  a = tex_input_value(in[1], p, thread);
68  tex_input_vec(ax, in[2], p, thread);
69 
70  rotate(new_co, a, ax, p->co);
71  if (p->osatex) {
72  rotate(new_dxt, a, ax, p->dxt);
73  rotate(new_dyt, a, ax, p->dyt);
74  }
75 
76  {
77  TexParams np = *p;
78  np.co = new_co;
79  np.dxt = new_dxt;
80  np.dyt = new_dyt;
81  tex_input_rgba(out, in[0], &np, thread);
82  }
83 }
84 static void exec(void *data,
85  int UNUSED(thread),
86  bNode *node,
87  bNodeExecData *execdata,
88  bNodeStack **in,
89  bNodeStack **out)
90 {
91  tex_output(node, execdata, in, out[0], &colorfn, data);
92 }
93 
95 {
96  static bNodeType ntype;
97 
100  node_type_exec(&ntype, NULL, NULL, exec);
101 
102  nodeRegisterType(&ntype);
103 }
void node_type_socket_templates(struct bNodeType *ntype, struct bNodeSocketTemplate *inputs, struct bNodeSocketTemplate *outputs)
Definition: node.cc:4527
#define NODE_CLASS_DISTORT
Definition: BKE_node.h:343
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
#define M_PI
Definition: BLI_math_base.h:38
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)
#define N_(msgid)
@ SOCK_VECTOR
@ SOCK_FLOAT
@ SOCK_RGBA
Group RGB to Bright Vector Camera Vector Combine Material Light Line Style Layer Add Ambient Diffuse Glossy Refraction Transparent Toon Principled Hair Volume Principled Light Particle Volume Image Sky Noise Wave Voronoi Brick Texture Vector Combine Vertex Separate Vector White RGB Map Separate Set Z Dilate Combine Combine Color Channel Split ID Combine Luminance Directional Alpha Distance Hue Movie Ellipse Bokeh View Corner Anti Mix RGB Hue TEX_NODE_ROTATE
@ PROP_DIRECTION
Definition: RNA_types.h:141
@ PROP_NONE
Definition: RNA_types.h:113
OperationNode * node
#define sinf(x)
#define cosf(x)
static unsigned a[3]
Definition: RandGen.cpp:92
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)
void tex_node_type_base(struct bNodeType *ntype, int type, const char *name, short nclass, short flag)
float tex_input_value(bNodeStack *in, TexParams *params, short thread)
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)
const float * co
Compact definition of a node socket.
Definition: BKE_node.h:95
Defines a node type.
Definition: BKE_node.h:221