Blender  V2.93
node_shader_tex_voronoi.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 
20 #include "../node_shader_util.h"
21 
22 /* **************** VORONOI ******************** */
23 
25  {SOCK_VECTOR, N_("Vector"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE},
26  {SOCK_FLOAT, N_("W"), 0.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f},
27  {SOCK_FLOAT, N_("Scale"), 5.0f, 0.0f, 0.0f, 0.0f, -1000.0f, 1000.0f},
28  {SOCK_FLOAT, N_("Smoothness"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
29  {SOCK_FLOAT, N_("Exponent"), 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 32.0f},
30  {SOCK_FLOAT, N_("Randomness"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
31  {-1, ""},
32 };
33 
35  {SOCK_FLOAT,
36  N_("Distance"),
37  0.0f,
38  0.0f,
39  0.0f,
40  0.0f,
41  0.0f,
42  1.0f,
43  PROP_NONE,
45  {SOCK_RGBA, N_("Color"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_NO_INTERNAL_LINK},
46  {SOCK_VECTOR,
47  N_("Position"),
48  0.0f,
49  0.0f,
50  0.0f,
51  0.0f,
52  0.0f,
53  1.0f,
54  PROP_NONE,
56  {SOCK_FLOAT, N_("W"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_NO_INTERNAL_LINK},
57  {SOCK_FLOAT,
58  N_("Radius"),
59  0.0f,
60  0.0f,
61  0.0f,
62  0.0f,
63  0.0f,
64  1.0f,
65  PROP_NONE,
67  {-1, ""},
68 };
69 
71 {
72  NodeTexVoronoi *tex = MEM_callocN(sizeof(NodeTexVoronoi), "NodeTexVoronoi");
74  BKE_texture_colormapping_default(&tex->base.color_mapping);
75  tex->dimensions = 3;
76  tex->distance = SHD_VORONOI_EUCLIDEAN;
77  tex->feature = SHD_VORONOI_F1;
78 
79  node->storage = tex;
80 }
81 
83  bNode *node,
84  bNodeExecData *UNUSED(execdata),
85  GPUNodeStack *in,
86  GPUNodeStack *out)
87 {
88  node_shader_gpu_default_tex_coord(mat, node, &in[0].link);
89  node_shader_gpu_tex_mapping(mat, node, in, out);
90 
91  static const char *names[][5] = {
92  [SHD_VORONOI_F1] =
93  {
94  "",
95  "node_tex_voronoi_f1_1d",
96  "node_tex_voronoi_f1_2d",
97  "node_tex_voronoi_f1_3d",
98  "node_tex_voronoi_f1_4d",
99  },
100  [SHD_VORONOI_F2] =
101  {
102  "",
103  "node_tex_voronoi_f2_1d",
104  "node_tex_voronoi_f2_2d",
105  "node_tex_voronoi_f2_3d",
106  "node_tex_voronoi_f2_4d",
107  },
109  {
110  "",
111  "node_tex_voronoi_smooth_f1_1d",
112  "node_tex_voronoi_smooth_f1_2d",
113  "node_tex_voronoi_smooth_f1_3d",
114  "node_tex_voronoi_smooth_f1_4d",
115  },
117  {
118  "",
119  "node_tex_voronoi_distance_to_edge_1d",
120  "node_tex_voronoi_distance_to_edge_2d",
121  "node_tex_voronoi_distance_to_edge_3d",
122  "node_tex_voronoi_distance_to_edge_4d",
123  },
125  {
126  "",
127  "node_tex_voronoi_n_sphere_radius_1d",
128  "node_tex_voronoi_n_sphere_radius_2d",
129  "node_tex_voronoi_n_sphere_radius_3d",
130  "node_tex_voronoi_n_sphere_radius_4d",
131  },
132  };
133 
134  NodeTexVoronoi *tex = (NodeTexVoronoi *)node->storage;
135  float metric = tex->distance;
136 
137  BLI_assert(tex->feature >= 0 && tex->feature < 5);
138  BLI_assert(tex->dimensions > 0 && tex->dimensions < 5);
139 
140  return GPU_stack_link(
141  mat, node, names[tex->feature][tex->dimensions], in, out, GPU_constant(&metric));
142 }
143 
145 {
146  bNodeSocket *inVectorSock = nodeFindSocket(node, SOCK_IN, "Vector");
147  bNodeSocket *inWSock = nodeFindSocket(node, SOCK_IN, "W");
148  bNodeSocket *inSmoothnessSock = nodeFindSocket(node, SOCK_IN, "Smoothness");
149  bNodeSocket *inExponentSock = nodeFindSocket(node, SOCK_IN, "Exponent");
150 
151  bNodeSocket *outDistanceSock = nodeFindSocket(node, SOCK_OUT, "Distance");
152  bNodeSocket *outColorSock = nodeFindSocket(node, SOCK_OUT, "Color");
153  bNodeSocket *outPositionSock = nodeFindSocket(node, SOCK_OUT, "Position");
154  bNodeSocket *outWSock = nodeFindSocket(node, SOCK_OUT, "W");
155  bNodeSocket *outRadiusSock = nodeFindSocket(node, SOCK_OUT, "Radius");
156 
157  NodeTexVoronoi *tex = (NodeTexVoronoi *)node->storage;
158 
159  nodeSetSocketAvailability(inWSock, tex->dimensions == 1 || tex->dimensions == 4);
160  nodeSetSocketAvailability(inVectorSock, tex->dimensions != 1);
162  inExponentSock,
163  tex->distance == SHD_VORONOI_MINKOWSKI && tex->dimensions != 1 &&
165  nodeSetSocketAvailability(inSmoothnessSock, tex->feature == SHD_VORONOI_SMOOTH_F1);
166  nodeSetSocketAvailability(outDistanceSock, tex->feature != SHD_VORONOI_N_SPHERE_RADIUS);
167  nodeSetSocketAvailability(outColorSock,
168  tex->feature != SHD_VORONOI_DISTANCE_TO_EDGE &&
169  tex->feature != SHD_VORONOI_N_SPHERE_RADIUS);
170  nodeSetSocketAvailability(outPositionSock,
171  tex->feature != SHD_VORONOI_DISTANCE_TO_EDGE &&
172  tex->feature != SHD_VORONOI_N_SPHERE_RADIUS &&
173  tex->dimensions != 1);
174  nodeSetSocketAvailability(outWSock,
175  tex->feature != SHD_VORONOI_DISTANCE_TO_EDGE &&
176  tex->feature != SHD_VORONOI_N_SPHERE_RADIUS &&
177  (tex->dimensions == 1 || tex->dimensions == 4));
178  nodeSetSocketAvailability(outRadiusSock, tex->feature == SHD_VORONOI_N_SPHERE_RADIUS);
179 }
180 
182 {
183  static bNodeType ntype;
184 
185  sh_node_type_base(&ntype, SH_NODE_TEX_VORONOI, "Voronoi Texture", NODE_CLASS_TEXTURE, 0);
189  &ntype, "NodeTexVoronoi", node_free_standard_storage, node_copy_standard_storage);
192 
193  nodeRegisterType(&ntype);
194 }
void node_type_gpu(struct bNodeType *ntype, NodeGPUExecFunction gpu_fn)
Definition: node.cc:4645
void nodeSetSocketAvailability(struct bNodeSocket *sock, bool is_available)
Definition: node.cc:3726
void node_type_socket_templates(struct bNodeType *ntype, struct bNodeSocketTemplate *inputs, struct bNodeSocketTemplate *outputs)
Definition: node.cc:4527
void node_type_update(struct bNodeType *ntype, void(*updatefunc)(struct bNodeTree *ntree, struct bNode *node))
Definition: node.cc:4623
void node_type_init(struct bNodeType *ntype, void(*initfunc)(struct bNodeTree *ntree, struct bNode *node))
Definition: node.cc:4559
void node_type_storage(struct bNodeType *ntype, const char *storagename, void(*freefunc)(struct bNode *node), void(*copyfunc)(struct bNodeTree *dest_ntree, struct bNode *dest_node, const struct bNode *src_node))
Definition: node.cc:4599
struct bNodeSocket * nodeFindSocket(const struct bNode *node, eNodeSocketInOut in_out, const char *identifier)
#define NODE_CLASS_TEXTURE
Definition: BKE_node.h:346
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1298
void BKE_texture_mapping_default(struct TexMapping *texmap, int type)
Definition: texture.c:252
void BKE_texture_colormapping_default(struct ColorMapping *colormap)
Definition: texture.c:354
#define BLI_assert(a)
Definition: BLI_assert.h:58
#define UNUSED(x)
#define ELEM(...)
#define N_(msgid)
@ SHD_VORONOI_F2
@ SHD_VORONOI_SMOOTH_F1
@ SHD_VORONOI_DISTANCE_TO_EDGE
@ SHD_VORONOI_F1
@ SHD_VORONOI_N_SPHERE_RADIUS
@ SOCK_OUT
@ SOCK_IN
@ SOCK_HIDE_VALUE
@ SOCK_NO_INTERNAL_LINK
@ SOCK_VECTOR
@ SOCK_FLOAT
@ SOCK_RGBA
@ SHD_VORONOI_EUCLIDEAN
@ SHD_VORONOI_MINKOWSKI
#define TEXMAP_TYPE_POINT
GPUNodeLink * GPU_constant(const float *num)
bool GPU_stack_link(GPUMaterial *mat, struct bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
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 SH_NODE_TEX_VORONOI
@ PROP_NONE
Definition: RNA_types.h:113
@ PROP_FACTOR
Definition: RNA_types.h:131
OperationNode * node
bNodeTree * ntree
static char ** names
Definition: makesdna.c:162
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:45
static bNodeSocketTemplate sh_node_tex_voronoi_in[]
void register_node_type_sh_tex_voronoi(void)
static bNodeSocketTemplate sh_node_tex_voronoi_out[]
static void node_shader_init_tex_voronoi(bNodeTree *UNUSED(ntree), bNode *node)
static void node_shader_update_tex_voronoi(bNodeTree *UNUSED(ntree), bNode *node)
static int node_shader_gpu_tex_voronoi(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
void node_shader_gpu_tex_mapping(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *UNUSED(out))
void sh_node_type_base(struct bNodeType *ntype, int type, const char *name, short nclass, short flag)
void node_shader_gpu_default_tex_coord(GPUMaterial *mat, bNode *node, GPUNodeLink **link)
void node_copy_standard_storage(bNodeTree *UNUSED(dest_ntree), bNode *dest_node, const bNode *src_node)
Definition: node_util.c:67
void node_free_standard_storage(bNode *node)
Definition: node_util.c:55
Compact definition of a node socket.
Definition: BKE_node.h:95
Defines a node type.
Definition: BKE_node.h:221