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 #pragma once
21
22 /** \file
23 * \ingroup bke
24 */
25
26 #include "BLI_compiler_compat.h"
27 #include "BLI_ghash.h"
28
29 #include "DNA_listBase.h"
30
31 /* for FOREACH_NODETREE_BEGIN */
32 #include "DNA_node_types.h"
33
34 #include "RNA_types.h"
35
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39
40 /* not very important, but the stack solver likes to know a maximum */
41 #define MAX_SOCKET 512
42
43 struct ARegion;
44 struct BlendDataReader;
45 struct BlendExpander;
46 struct BlendLibReader;
47 struct BlendWriter;
48 struct ColorManagedDisplaySettings;
49 struct ColorManagedViewSettings;
50 struct FreestyleLineStyle;
51 struct GPUMaterial;
52 struct GPUNodeStack;
53 struct ID;
54 struct ImBuf;
55 struct ImageFormatData;
56 struct Light;
57 struct ListBase;
58 struct MTex;
59 struct Main;
60 struct Material;
61 struct PointerRNA;
62 struct RenderData;
63 struct Scene;
64 struct SpaceNode;
65 struct Tex;
66 struct World;
67 struct bContext;
68 struct bNode;
69 struct bNodeExecContext;
70 struct bNodeExecData;
71 struct bNodeInstanceHash;
72 struct bNodeLink;
73 struct bNodeSocket;
74 struct bNodeStack;
75 struct bNodeTree;
76 struct bNodeTreeExec;
77 struct bNodeTreeType;
78 struct uiLayout;
79
80 /* -------------------------------------------------------------------- */
81 /** \name Node Type Definitions
82 * \{ */
83
84 /**
85 * \brief Compact definition of a node socket.
86 *
87 * Can be used to quickly define a list of static sockets for a node,
88 * which are added to each new node of that type.
89 *
90 * \deprecated This struct is used by C nodes to define templates as simple
91 * static struct lists. These are converted to the new template collections
92 * in RNA types automatically.
93 */
94 typedef struct bNodeSocketTemplate {
95 int type;
96 char name[64]; /* MAX_NAME */
97 float val1, val2, val3, val4; /* default alloc value for inputs */
98 float min, max;
99 int subtype; /* would use PropertySubType but this is a bad level include to use RNA */
100 int flag;
101
102 /* after this line is used internal only */
103 struct bNodeSocket *sock; /* used to hold verified socket */
104 char identifier[64]; /* generated from name */
105 } bNodeSocketTemplate;
106
107 /* Use `void *` for callbacks that require C++. This is rather ugly, but works well for now. This
108 * would not be necessary if we would use bNodeSocketType and bNodeType only in C++ code.
109 * However, achieving this requires quite a few changes currently. */
110 #ifdef __cplusplus
111 namespace blender {
112 namespace nodes {
113 class SocketMFNetworkBuilder;
114 class NodeMFNetworkBuilder;
115 } // namespace nodes
116 namespace fn {
117 class MFDataType;
118 }
119 } // namespace blender
120
121 using NodeExpandInMFNetworkFunction = void (*)(blender::nodes::NodeMFNetworkBuilder &builder);
122 using SocketGetMFDataTypeFunction = blender::fn::MFDataType (*)();
123 using SocketExpandInMFNetworkFunction = void (*)(blender::nodes::SocketMFNetworkBuilder &builder);
124
125 #else
126 typedef void *NodeExpandInMFNetworkFunction;
127 typedef void *SocketGetMFDataTypeFunction;
128 typedef void *SocketExpandInMFNetworkFunction;
129 #endif
130
131 /**
132 * \brief Defines a socket type.
133 *
134 * Defines the appearance and behavior of a socket in the UI.
135 */
136 typedef struct bNodeSocketType {
137 char idname[64]; /* identifier name */
138
139 void (*draw)(struct bContext *C,
140 struct uiLayout *layout,
141 struct PointerRNA *ptr,
142 struct PointerRNA *node_ptr,
143 const char *text);
144 void (*draw_color)(struct bContext *C,
145 struct PointerRNA *ptr,
146 struct PointerRNA *node_ptr,
147 float *r_color);
148
149 void (*interface_draw)(struct bContext *C, struct uiLayout *layout, struct PointerRNA *ptr);
150 void (*interface_draw_color)(struct bContext *C, struct PointerRNA *ptr, float *r_color);
151 void (*interface_register_properties)(struct bNodeTree *ntree,
152 struct bNodeSocket *stemp,
153 struct StructRNA *data_srna);
154 void (*interface_init_socket)(struct bNodeTree *ntree,
155 struct bNodeSocket *stemp,
156 struct bNode *node,
157 struct bNodeSocket *sock,
158 const char *data_path);
159 void (*interface_verify_socket)(struct bNodeTree *ntree,
160 struct bNodeSocket *stemp,
161 struct bNode *node,
162 struct bNodeSocket *sock,
163 const char *data_path);
164 void (*interface_from_socket)(struct bNodeTree *ntree,
165 struct bNodeSocket *stemp,
166 struct bNode *node,
167 struct bNodeSocket *sock);
168
169 /* RNA integration */
170 ExtensionRNA ext_socket;
171 ExtensionRNA ext_interface;
172
173 /* for standard socket types in C */
174 int type, subtype;
175
176 /* When set, bNodeSocket->limit does not have any effect anymore. */
177 bool use_link_limits_of_type;
178 int input_link_limit;
179 int output_link_limit;
180
181 /* Callback to free the socket type. */
182 void (*free_self)(struct bNodeSocketType *stype);
183
184 /* Returns the multi-function data type of this socket type. */
185 SocketGetMFDataTypeFunction get_mf_data_type;
186 /* Expands the socket into a multi-function node that outputs the socket value. */
187 SocketExpandInMFNetworkFunction expand_in_mf_network;
188 } bNodeSocketType;
189
190 typedef void *(*NodeInitExecFunction)(struct bNodeExecContext *context,
191 struct bNode *node,
192 bNodeInstanceKey key);
193 typedef void (*NodeFreeExecFunction)(void *nodedata);
194 typedef void (*NodeExecFunction)(void *data,
195 int thread,
196 struct bNode *,
197 struct bNodeExecData *execdata,
198 struct bNodeStack **in,
199 struct bNodeStack **out);
200 typedef int (*NodeGPUExecFunction)(struct GPUMaterial *mat,
201 struct bNode *node,
202 struct bNodeExecData *execdata,
203 struct GPUNodeStack *in,
204 struct GPUNodeStack *out);
205
206 /**
207 * \brief Defines a node type.
208 *
209 * Initial attributes and constants for a node as well as callback functions
210 * implementing the node behavior.
211 */
212 typedef struct bNodeType {
213 void *next, *prev;
214
215 char idname[64]; /* identifier name */
216 int type;
217
218 char ui_name[64]; /* MAX_NAME */
219 char ui_description[256];
220 int ui_icon;
221
222 float width, minwidth, maxwidth;
223 float height, minheight, maxheight;
224 short nclass, flag;
225
226 /* templates for static sockets */
227 bNodeSocketTemplate *inputs, *outputs;
228
229 char storagename[64]; /* struct name for DNA */
230
231 /* Main draw function for the node */
232 void (*draw_nodetype)(const struct bContext *C,
233 struct ARegion *region,
234 struct SpaceNode *snode,
235 struct bNodeTree *ntree,
236 struct bNode *node,
237 bNodeInstanceKey key);
238 /* Updates the node geometry attributes according to internal state before actual drawing */
239 void (*draw_nodetype_prepare)(const struct bContext *C,
240 struct bNodeTree *ntree,
241 struct bNode *node);
242
243 /* Draw the option buttons on the node */
244 void (*draw_buttons)(struct uiLayout *, struct bContext *C, struct PointerRNA *ptr);
245 /* Additional parameters in the side panel */
246 void (*draw_buttons_ex)(struct uiLayout *, struct bContext *C, struct PointerRNA *ptr);
247
248 /* Additional drawing on backdrop */
249 void (*draw_backdrop)(
250 struct SpaceNode *snode, struct ImBuf *backdrop, struct bNode *node, int x, int y);
251
252 /**
253 * Optional custom label function for the node header.
254 * \note Used as a fallback when #bNode.label isn't set.
255 */
256 void (*labelfunc)(struct bNodeTree *ntree, struct bNode *node, char *label, int maxlen);
257 /** Optional custom resize handle polling. */
258 int (*resize_area_func)(struct bNode *node, int x, int y);
259 /** Optional selection area polling. */
260 int (*select_area_func)(struct bNode *node, int x, int y);
261 /** Optional tweak area polling (for grabbing). */
262 int (*tweak_area_func)(struct bNode *node, int x, int y);
263
264 /** Called when the node is updated in the editor. */
265 void (*updatefunc)(struct bNodeTree *ntree, struct bNode *node);
266 /** Check and update if internal ID data has changed. */
267 void (*group_update_func)(struct bNodeTree *ntree, struct bNode *node);
268
269 /** Initialize a new node instance of this type after creation. */
270 void (*initfunc)(struct bNodeTree *ntree, struct bNode *node);
271 /** Free the node instance. */
272 void (*freefunc)(struct bNode *node);
273 /** Make a copy of the node instance. */
274 void (*copyfunc)(struct bNodeTree *dest_ntree,
275 struct bNode *dest_node,
276 const struct bNode *src_node);
277
278 /* Registerable API callback versions, called in addition to C callbacks */
279 void (*initfunc_api)(const struct bContext *C, struct PointerRNA *ptr);
280 void (*freefunc_api)(struct PointerRNA *ptr);
281 void (*copyfunc_api)(struct PointerRNA *ptr, const struct bNode *src_node);
282
283 /* can this node type be added to a node tree */
284 bool (*poll)(struct bNodeType *ntype, struct bNodeTree *nodetree);
285 /* can this node be added to a node tree */
286 bool (*poll_instance)(struct bNode *node, struct bNodeTree *nodetree);
287
288 /* optional handling of link insertion */
289 void (*insert_link)(struct bNodeTree *ntree, struct bNode *node, struct bNodeLink *link);
290 /* Update the internal links list, for muting and disconnect operators. */
291 void (*update_internal_links)(struct bNodeTree *, struct bNode *node);
292
293 void (*free_self)(struct bNodeType *ntype);
294
295 /* **** execution callbacks **** */
296 NodeInitExecFunction initexecfunc;
297 NodeFreeExecFunction freeexecfunc;
298 NodeExecFunction execfunc;
299 /* gpu */
300 NodeGPUExecFunction gpufunc;
301
302 /* Expands the bNode into nodes in a multi-function network, which will be evaluated later on. */
303 NodeExpandInMFNetworkFunction expand_in_mf_network;
304
305 /* RNA integration */
306 ExtensionRNA rna_ext;
307 } bNodeType;
308
309 /* nodetype->nclass, for add-menu and themes */
310 #define NODE_CLASS_INPUT 0
311 #define NODE_CLASS_OUTPUT 1
312 #define NODE_CLASS_OP_COLOR 3
313 #define NODE_CLASS_OP_VECTOR 4
314 #define NODE_CLASS_OP_FILTER 5
315 #define NODE_CLASS_GROUP 6
316 // #define NODE_CLASS_FILE 7
317 #define NODE_CLASS_CONVERTOR 8
318 #define NODE_CLASS_MATTE 9
319 #define NODE_CLASS_DISTORT 10
320 // #define NODE_CLASS_OP_DYNAMIC 11 /* deprecated */
321 #define NODE_CLASS_PATTERN 12
322 #define NODE_CLASS_TEXTURE 13
323 // #define NODE_CLASS_EXECUTION 14
324 // #define NODE_CLASS_GETDATA 15
325 // #define NODE_CLASS_SETDATA 16
326 // #define NODE_CLASS_MATH 17
327 // #define NODE_CLASS_MATH_VECTOR 18
328 // #define NODE_CLASS_MATH_ROTATION 19
329 // #define NODE_CLASS_PARTICLES 25
330 // #define NODE_CLASS_TRANSFORM 30
331 // #define NODE_CLASS_COMBINE 31
332 #define NODE_CLASS_SCRIPT 32
333 #define NODE_CLASS_INTERFACE 33
334 #define NODE_CLASS_SHADER 40
335 #define NODE_CLASS_LAYOUT 100
336
337 /* node resize directions */
338 #define NODE_RESIZE_TOP 1
339 #define NODE_RESIZE_BOTTOM 2
340 #define NODE_RESIZE_RIGHT 4
341 #define NODE_RESIZE_LEFT 8
342
343 typedef enum eNodeSizePreset {
344 NODE_SIZE_DEFAULT,
345 NODE_SIZE_SMALL,
346 NODE_SIZE_MIDDLE,
347 NODE_SIZE_LARGE,
348 } eNodeSizePreset;
349
350 struct bNodeTreeExec;
351
352 typedef void (*bNodeClassCallback)(void *calldata, int nclass, const char *name);
353 typedef struct bNodeTreeType {
354 int type; /* type identifier */
355 char idname[64]; /* identifier name */
356
357 char ui_name[64];
358 char ui_description[256];
359 int ui_icon;
360
361 /* callbacks */
362 void (*free_cache)(struct bNodeTree *ntree);
363 void (*free_node_cache)(struct bNodeTree *ntree, struct bNode *node);
364 /* Iteration over all node classes. */
365 void (*foreach_nodeclass)(struct Scene *scene, void *calldata, bNodeClassCallback func);
366 /* Check visibility in the node editor */
367 bool (*poll)(const struct bContext *C, struct bNodeTreeType *ntreetype);
368 /* Select a node tree from the context */
369 void (*get_from_context)(const struct bContext *C,
370 struct bNodeTreeType *ntreetype,
371 struct bNodeTree **r_ntree,
372 struct ID **r_id,
373 struct ID **r_from);
374
375 /* calls allowing threaded composite */
376 void (*localize)(struct bNodeTree *localtree, struct bNodeTree *ntree);
377 void (*local_sync)(struct bNodeTree *localtree, struct bNodeTree *ntree);
378 void (*local_merge)(struct Main *bmain, struct bNodeTree *localtree, struct bNodeTree *ntree);
379
380 /* Tree update. Overrides nodetype->updatetreefunc! */
381 void (*update)(struct bNodeTree *ntree);
382
383 bool (*validate_link)(struct bNodeTree *ntree, struct bNodeLink *link);
384
385 void (*node_add_init)(struct bNodeTree *ntree, struct bNode *bnode);
386
387 /* RNA integration */
388 ExtensionRNA rna_ext;
389 } bNodeTreeType;
390
391 /** \} */
392
393 /* -------------------------------------------------------------------- */
394 /** \name Generic API, Trees
395 * \{ */
396
397 struct bNodeTreeType *ntreeTypeFind(const char *idname);
398 void ntreeTypeAdd(struct bNodeTreeType *nt);
399 void ntreeTypeFreeLink(const struct bNodeTreeType *nt);
400 bool ntreeIsRegistered(struct bNodeTree *ntree);
401 struct GHashIterator *ntreeTypeGetIterator(void);
402
403 /* helper macros for iterating over tree types */
404 #define NODE_TREE_TYPES_BEGIN(ntype) \
405 { \
406 GHashIterator *__node_tree_type_iter__ = ntreeTypeGetIterator(); \
407 for (; !BLI_ghashIterator_done(__node_tree_type_iter__); \
408 BLI_ghashIterator_step(__node_tree_type_iter__)) { \
409 bNodeTreeType *ntype = BLI_ghashIterator_getValue(__node_tree_type_iter__);
410
411 #define NODE_TREE_TYPES_END \
412 } \
413 BLI_ghashIterator_free(__node_tree_type_iter__); \
414 } \
415 (void)0
416
417 void ntreeSetTypes(const struct bContext *C, struct bNodeTree *ntree);
418
419 struct bNodeTree *ntreeAddTree(struct Main *bmain, const char *name, const char *idname);
420
421 /* copy/free funcs, need to manage ID users */
422 void ntreeFreeTree(struct bNodeTree *ntree);
423 /* Free tree which is embedded into another datablock. */
424 void ntreeFreeEmbeddedTree(struct bNodeTree *ntree);
425 struct bNodeTree *ntreeCopyTree_ex(const struct bNodeTree *ntree,
426 struct Main *bmain,
427 const bool do_id_user);
428 struct bNodeTree *ntreeCopyTree(struct Main *bmain, const struct bNodeTree *ntree);
429
430 struct bNodeTree **BKE_ntree_ptr_from_id(struct ID *id);
431 struct bNodeTree *ntreeFromID(struct ID *id);
432 struct ID *BKE_node_tree_find_owner_ID(struct Main *bmain, struct bNodeTree *ntree);
433
434 void ntreeFreeLocalNode(struct bNodeTree *ntree, struct bNode *node);
435 void ntreeFreeLocalTree(struct bNodeTree *ntree);
436 struct bNode *ntreeFindType(const struct bNodeTree *ntree, int type);
437 bool ntreeHasType(const struct bNodeTree *ntree, int type);
438 bool ntreeHasTree(const struct bNodeTree *ntree, const struct bNodeTree *lookup);
439 void ntreeUpdateTree(struct Main *main, struct bNodeTree *ntree);
440 void ntreeUpdateAllNew(struct Main *main);
441 void ntreeUpdateAllUsers(struct Main *main, struct ID *ngroup);
442
443 void ntreeGetDependencyList(struct bNodeTree *ntree, struct bNode ***deplist, int *totnodes);
444
445 /* XXX old trees handle output flags automatically based on special output
446 * node types and last active selection.
447 * New tree types have a per-output socket flag to indicate the final output to use explicitly.
448 */
449 void ntreeSetOutput(struct bNodeTree *ntree);
450
451 void ntreeFreeCache(struct bNodeTree *ntree);
452
453 bool ntreeNodeExists(struct bNodeTree *ntree, struct bNode *testnode);
454 bool ntreeOutputExists(struct bNode *node, struct bNodeSocket *testsock);
455 void ntreeNodeFlagSet(const bNodeTree *ntree, const int flag, const bool enable);
456 struct bNodeTree *ntreeLocalize(struct bNodeTree *ntree);
457 void ntreeLocalSync(struct bNodeTree *localtree, struct bNodeTree *ntree);
458 void ntreeLocalMerge(struct Main *bmain, struct bNodeTree *localtree, struct bNodeTree *ntree);
459
460 void ntreeBlendWrite(struct BlendWriter *writer, struct bNodeTree *ntree);
461 void ntreeBlendReadData(struct BlendDataReader *reader, struct bNodeTree *ntree);
462 void ntreeBlendReadLib(struct BlendLibReader *reader, struct bNodeTree *ntree);
463 void ntreeBlendReadExpand(struct BlendExpander *expander, struct bNodeTree *ntree);
464
465 /** \} */
466
467 /* -------------------------------------------------------------------- */
468 /** \name Node Tree Interface
469 * \{ */
470 struct bNodeSocket *ntreeFindSocketInterface(struct bNodeTree *ntree,
471 int in_out,
472 const char *identifier);
473 struct bNodeSocket *ntreeAddSocketInterface(struct bNodeTree *ntree,
474 int in_out,
475 const char *idname,
476 const char *name);
477 struct bNodeSocket *ntreeInsertSocketInterface(struct bNodeTree *ntree,
478 int in_out,
479 const char *idname,
480 struct bNodeSocket *next_sock,
481 const char *name);
482 struct bNodeSocket *ntreeAddSocketInterfaceFromSocket(struct bNodeTree *ntree,
483 struct bNode *from_node,
484 struct bNodeSocket *from_sock);
485 struct bNodeSocket *ntreeInsertSocketInterfaceFromSocket(struct bNodeTree *ntree,
486 struct bNodeSocket *next_sock,
487 struct bNode *from_node,
488 struct bNodeSocket *from_sock);
489 void ntreeRemoveSocketInterface(struct bNodeTree *ntree, struct bNodeSocket *sock);
490
491 struct StructRNA *ntreeInterfaceTypeGet(struct bNodeTree *ntree, int create);
492 void ntreeInterfaceTypeFree(struct bNodeTree *ntree);
493 void ntreeInterfaceTypeUpdate(struct bNodeTree *ntree);
494
495 /** \} */
496
497 /* -------------------------------------------------------------------- */
498 /** \name Generic API, Nodes
499 * \{ */
500
501 struct bNodeType *nodeTypeFind(const char *idname);
502 void nodeRegisterType(struct bNodeType *ntype);
503 void nodeUnregisterType(struct bNodeType *ntype);
504 bool nodeIsRegistered(struct bNode *node);
505 struct GHashIterator *nodeTypeGetIterator(void);
506
507 /* helper macros for iterating over node types */
508 #define NODE_TYPES_BEGIN(ntype) \
509 { \
510 GHashIterator *__node_type_iter__ = nodeTypeGetIterator(); \
511 for (; !BLI_ghashIterator_done(__node_type_iter__); \
512 BLI_ghashIterator_step(__node_type_iter__)) { \
513 bNodeType *ntype = BLI_ghashIterator_getValue(__node_type_iter__);
514
515 #define NODE_TYPES_END \
516 } \
517 BLI_ghashIterator_free(__node_type_iter__); \
518 } \
519 ((void)0)
520
521 struct bNodeSocketType *nodeSocketTypeFind(const char *idname);
522 void nodeRegisterSocketType(struct bNodeSocketType *stype);
523 void nodeUnregisterSocketType(struct bNodeSocketType *stype);
524 bool nodeSocketIsRegistered(struct bNodeSocket *sock);
525 struct GHashIterator *nodeSocketTypeGetIterator(void);
526 const char *nodeStaticSocketType(int type, int subtype);
527 const char *nodeStaticSocketInterfaceType(int type, int subtype);
528
529 /* helper macros for iterating over node types */
530 #define NODE_SOCKET_TYPES_BEGIN(stype) \
531 { \
532 GHashIterator *__node_socket_type_iter__ = nodeSocketTypeGetIterator(); \
533 for (; !BLI_ghashIterator_done(__node_socket_type_iter__); \
534 BLI_ghashIterator_step(__node_socket_type_iter__)) { \
535 bNodeSocketType *stype = BLI_ghashIterator_getValue(__node_socket_type_iter__);
536
537 #define NODE_SOCKET_TYPES_END \
538 } \
539 BLI_ghashIterator_free(__node_socket_type_iter__); \
540 } \
541 ((void)0)
542
543 struct bNodeSocket *nodeFindSocket(const struct bNode *node, int in_out, const char *identifier);
544 struct bNodeSocket *nodeAddSocket(struct bNodeTree *ntree,
545 struct bNode *node,
546 int in_out,
547 const char *idname,
548 const char *identifier,
549 const char *name);
550 struct bNodeSocket *nodeInsertSocket(struct bNodeTree *ntree,
551 struct bNode *node,
552 int in_out,
553 const char *idname,
554 struct bNodeSocket *next_sock,
555 const char *identifier,
556 const char *name);
557 struct bNodeSocket *nodeAddStaticSocket(struct bNodeTree *ntree,
558 struct bNode *node,
559 int in_out,
560 int type,
561 int subtype,
562 const char *identifier,
563 const char *name);
564 struct bNodeSocket *nodeInsertStaticSocket(struct bNodeTree *ntree,
565 struct bNode *node,
566 int in_out,
567 int type,
568 int subtype,
569 struct bNodeSocket *next_sock,
570 const char *identifier,
571 const char *name);
572 void nodeRemoveSocket(struct bNodeTree *ntree, struct bNode *node, struct bNodeSocket *sock);
573 void nodeRemoveAllSockets(struct bNodeTree *ntree, struct bNode *node);
574 void nodeModifySocketType(
575 struct bNodeTree *ntree, struct bNode *node, struct bNodeSocket *sock, int type, int subtype);
576
577 struct bNode *nodeAddNode(const struct bContext *C, struct bNodeTree *ntree, const char *idname);
578 struct bNode *nodeAddStaticNode(const struct bContext *C, struct bNodeTree *ntree, int type);
579 void nodeUnlinkNode(struct bNodeTree *ntree, struct bNode *node);
580 void nodeUniqueName(struct bNodeTree *ntree, struct bNode *node);
581
582 /* Delete node, associated animation data and ID user count. */
583 void nodeRemoveNode(struct Main *bmain,
584 struct bNodeTree *ntree,
585 struct bNode *node,
586 bool do_id_user);
587
588 struct bNode *BKE_node_copy_ex(struct bNodeTree *ntree,
589 const struct bNode *node_src,
590 const int flag,
591 const bool unique_name);
592
593 /* Same as BKE_node_copy_ex() but stores pointers to a new node and its sockets in the source
594 * node.
595 *
596 * NOTE: DANGER ZONE!
597 *
598 * TODO(sergey): Maybe it's better to make BKE_node_copy_ex() return a mapping from old node and
599 * sockets to new one. */
600 struct bNode *BKE_node_copy_store_new_pointers(struct bNodeTree *ntree,
601 struct bNode *node_src,
602 const int flag);
603 struct bNodeTree *ntreeCopyTree_ex_new_pointers(const struct bNodeTree *ntree,
604 struct Main *bmain,
605 const bool do_id_user);
606
607 struct bNodeLink *nodeAddLink(struct bNodeTree *ntree,
608 struct bNode *fromnode,
609 struct bNodeSocket *fromsock,
610 struct bNode *tonode,
611 struct bNodeSocket *tosock);
612 void nodeRemLink(struct bNodeTree *ntree, struct bNodeLink *link);
613 void nodeRemSocketLinks(struct bNodeTree *ntree, struct bNodeSocket *sock);
614 bool nodeLinkIsHidden(struct bNodeLink *link);
615 void nodeInternalRelink(struct bNodeTree *ntree, struct bNode *node);
616
617 void nodeToView(struct bNode *node, float x, float y, float *rx, float *ry);
618 void nodeFromView(struct bNode *node, float x, float y, float *rx, float *ry);
619 bool nodeAttachNodeCheck(struct bNode *node, struct bNode *parent);
620 void nodeAttachNode(struct bNode *node, struct bNode *parent);
621 void nodeDetachNode(struct bNode *node);
622
623 void nodePositionRelative(struct bNode *from_node,
624 struct bNode *to_node,
625 struct bNodeSocket *from_sock,
626 struct bNodeSocket *to_sock);
627 void nodePositionPropagate(struct bNode *node);
628
629 struct bNode *nodeFindNodebyName(struct bNodeTree *ntree, const char *name);
630 bool nodeFindNode(struct bNodeTree *ntree,
631 struct bNodeSocket *sock,
632 struct bNode **r_node,
633 int *r_sockindex);
634 struct bNode *nodeFindRootParent(bNode *node);
635
636 bool nodeIsChildOf(const bNode *parent, const bNode *child);
637
638 void nodeChainIter(const bNodeTree *ntree,
639 const bNode *node_start,
640 bool (*callback)(bNode *, bNode *, void *, const bool),
641 void *userdata,
642 const bool reversed);
643 void nodeChainIterBackwards(const bNodeTree *ntree,
644 const bNode *node_start,
645 bool (*callback)(bNode *, bNode *, void *),
646 void *userdata,
647 int recursion_lvl);
648 void nodeParentsIter(bNode *node, bool (*callback)(bNode *, void *), void *userdata);
649
650 struct bNodeLink *nodeFindLink(struct bNodeTree *ntree,
651 struct bNodeSocket *from,
652 struct bNodeSocket *to);
653 int nodeCountSocketLinks(struct bNodeTree *ntree, struct bNodeSocket *sock);
654
655 void nodeSetSelected(struct bNode *node, bool select);
656 void nodeSetActive(struct bNodeTree *ntree, struct bNode *node);
657 struct bNode *nodeGetActive(struct bNodeTree *ntree);
658 struct bNode *nodeGetActiveID(struct bNodeTree *ntree, short idtype);
659 bool nodeSetActiveID(struct bNodeTree *ntree, short idtype, struct ID *id);
660 void nodeClearActive(struct bNodeTree *ntree);
661 void nodeClearActiveID(struct bNodeTree *ntree, short idtype);
662 struct bNode *nodeGetActiveTexture(struct bNodeTree *ntree);
663
664 void nodeUpdate(struct bNodeTree *ntree, struct bNode *node);
665 bool nodeUpdateID(struct bNodeTree *ntree, struct ID *id);
666 void nodeUpdateInternalLinks(struct bNodeTree *ntree, struct bNode *node);
667
668 int nodeSocketIsHidden(struct bNodeSocket *sock);
669 void ntreeTagUsedSockets(struct bNodeTree *ntree);
670 void nodeSetSocketAvailability(struct bNodeSocket *sock, bool is_available);
671
672 int nodeSocketLinkLimit(struct bNodeSocket *sock);
673
674 /* Node Clipboard */
675 void BKE_node_clipboard_init(struct bNodeTree *ntree);
676 void BKE_node_clipboard_clear(void);
677 void BKE_node_clipboard_free(void);
678 bool BKE_node_clipboard_validate(void);
679 void BKE_node_clipboard_add_node(struct bNode *node);
680 void BKE_node_clipboard_add_link(struct bNodeLink *link);
681 const struct ListBase *BKE_node_clipboard_get_nodes(void);
682 const struct ListBase *BKE_node_clipboard_get_links(void);
683 int BKE_node_clipboard_get_type(void);
684
685 /* Node Instance Hash */
686 typedef struct bNodeInstanceHash {
687 GHash *ghash; /* XXX should be made a direct member, GHash allocation needs to support it */
688 } bNodeInstanceHash;
689
690 typedef void (*bNodeInstanceValueFP)(void *value);
691
692 extern const bNodeInstanceKey NODE_INSTANCE_KEY_BASE;
693 extern const bNodeInstanceKey NODE_INSTANCE_KEY_NONE;
694
695 bNodeInstanceKey BKE_node_instance_key(bNodeInstanceKey parent_key,
696 struct bNodeTree *ntree,
697 struct bNode *node);
698
699 bNodeInstanceHash *BKE_node_instance_hash_new(const char *info);
700 void BKE_node_instance_hash_free(bNodeInstanceHash *hash, bNodeInstanceValueFP valfreefp);
701 void BKE_node_instance_hash_insert(bNodeInstanceHash *hash, bNodeInstanceKey key, void *value);
702 void *BKE_node_instance_hash_lookup(bNodeInstanceHash *hash, bNodeInstanceKey key);
703 int BKE_node_instance_hash_remove(bNodeInstanceHash *hash,
704 bNodeInstanceKey key,
705 bNodeInstanceValueFP valfreefp);
706 void BKE_node_instance_hash_clear(bNodeInstanceHash *hash, bNodeInstanceValueFP valfreefp);
707 void *BKE_node_instance_hash_pop(bNodeInstanceHash *hash, bNodeInstanceKey key);
708 int BKE_node_instance_hash_haskey(bNodeInstanceHash *hash, bNodeInstanceKey key);
709 int BKE_node_instance_hash_size(bNodeInstanceHash *hash);
710
711 void BKE_node_instance_hash_clear_tags(bNodeInstanceHash *hash);
712 void BKE_node_instance_hash_tag(bNodeInstanceHash *hash, void *value);
713 bool BKE_node_instance_hash_tag_key(bNodeInstanceHash *hash, bNodeInstanceKey key);
714 void BKE_node_instance_hash_remove_untagged(bNodeInstanceHash *hash,
715 bNodeInstanceValueFP valfreefp);
716
717 typedef GHashIterator bNodeInstanceHashIterator;
718
BKE_node_instance_hash_iterator_new(bNodeInstanceHash * hash)719 BLI_INLINE bNodeInstanceHashIterator *BKE_node_instance_hash_iterator_new(bNodeInstanceHash *hash)
720 {
721 return BLI_ghashIterator_new(hash->ghash);
722 }
BKE_node_instance_hash_iterator_init(bNodeInstanceHashIterator * iter,bNodeInstanceHash * hash)723 BLI_INLINE void BKE_node_instance_hash_iterator_init(bNodeInstanceHashIterator *iter,
724 bNodeInstanceHash *hash)
725 {
726 BLI_ghashIterator_init(iter, hash->ghash);
727 }
BKE_node_instance_hash_iterator_free(bNodeInstanceHashIterator * iter)728 BLI_INLINE void BKE_node_instance_hash_iterator_free(bNodeInstanceHashIterator *iter)
729 {
730 BLI_ghashIterator_free(iter);
731 }
732 BLI_INLINE bNodeInstanceKey
BKE_node_instance_hash_iterator_get_key(bNodeInstanceHashIterator * iter)733 BKE_node_instance_hash_iterator_get_key(bNodeInstanceHashIterator *iter)
734 {
735 return *(bNodeInstanceKey *)BLI_ghashIterator_getKey(iter);
736 }
BKE_node_instance_hash_iterator_get_value(bNodeInstanceHashIterator * iter)737 BLI_INLINE void *BKE_node_instance_hash_iterator_get_value(bNodeInstanceHashIterator *iter)
738 {
739 return BLI_ghashIterator_getValue(iter);
740 }
BKE_node_instance_hash_iterator_step(bNodeInstanceHashIterator * iter)741 BLI_INLINE void BKE_node_instance_hash_iterator_step(bNodeInstanceHashIterator *iter)
742 {
743 BLI_ghashIterator_step(iter);
744 }
BKE_node_instance_hash_iterator_done(bNodeInstanceHashIterator * iter)745 BLI_INLINE bool BKE_node_instance_hash_iterator_done(bNodeInstanceHashIterator *iter)
746 {
747 return BLI_ghashIterator_done(iter);
748 }
749
750 #define NODE_INSTANCE_HASH_ITER(iter_, hash_) \
751 for (BKE_node_instance_hash_iterator_init(&iter_, hash_); \
752 BKE_node_instance_hash_iterator_done(&iter_) == false; \
753 BKE_node_instance_hash_iterator_step(&iter_))
754
755 /* Node Previews */
756
757 int BKE_node_preview_used(struct bNode *node);
758 bNodePreview *BKE_node_preview_verify(
759 struct bNodeInstanceHash *previews, bNodeInstanceKey key, int xsize, int ysize, bool create);
760 bNodePreview *BKE_node_preview_copy(struct bNodePreview *preview);
761 void BKE_node_preview_free(struct bNodePreview *preview);
762 void BKE_node_preview_init_tree(struct bNodeTree *ntree,
763 int xsize,
764 int ysize,
765 int create_previews);
766 void BKE_node_preview_free_tree(struct bNodeTree *ntree);
767 void BKE_node_preview_remove_unused(struct bNodeTree *ntree);
768 void BKE_node_preview_clear(struct bNodePreview *preview);
769 void BKE_node_preview_clear_tree(struct bNodeTree *ntree);
770
771 void BKE_node_preview_sync_tree(struct bNodeTree *to_ntree, struct bNodeTree *from_ntree);
772 void BKE_node_preview_merge_tree(struct bNodeTree *to_ntree,
773 struct bNodeTree *from_ntree,
774 bool remove_old);
775
776 void BKE_node_preview_set_pixel(
777 struct bNodePreview *preview, const float col[4], int x, int y, bool do_manage);
778
779 /** \} */
780
781 /* -------------------------------------------------------------------- */
782 /** \name Node Type Access
783 * \{ */
784
785 void nodeLabel(struct bNodeTree *ntree, struct bNode *node, char *label, int maxlen);
786 const char *nodeSocketLabel(const struct bNodeSocket *sock);
787
788 int nodeGroupPoll(struct bNodeTree *nodetree, struct bNodeTree *grouptree);
789
790 /* Init a new node type struct with default values and callbacks */
791 void node_type_base(struct bNodeType *ntype, int type, const char *name, short nclass, short flag);
792 void node_type_base_custom(
793 struct bNodeType *ntype, const char *idname, const char *name, short nclass, short flag);
794 void node_type_socket_templates(struct bNodeType *ntype,
795 struct bNodeSocketTemplate *inputs,
796 struct bNodeSocketTemplate *outputs);
797 void node_type_size(struct bNodeType *ntype, int width, int minwidth, int maxwidth);
798 void node_type_size_preset(struct bNodeType *ntype, eNodeSizePreset size);
799 void node_type_init(struct bNodeType *ntype,
800 void (*initfunc)(struct bNodeTree *ntree, struct bNode *node));
801 void node_type_storage(struct bNodeType *ntype,
802 const char *storagename,
803 void (*freefunc)(struct bNode *node),
804 void (*copyfunc)(struct bNodeTree *dest_ntree,
805 struct bNode *dest_node,
806 const struct bNode *src_node));
807 void node_type_label(
808 struct bNodeType *ntype,
809 void (*labelfunc)(struct bNodeTree *ntree, struct bNode *, char *label, int maxlen));
810 void node_type_update(struct bNodeType *ntype,
811 void (*updatefunc)(struct bNodeTree *ntree, struct bNode *node));
812 void node_type_group_update(struct bNodeType *ntype,
813 void (*group_update_func)(struct bNodeTree *ntree,
814 struct bNode *node));
815
816 void node_type_exec(struct bNodeType *ntype,
817 NodeInitExecFunction initexecfunc,
818 NodeFreeExecFunction freeexecfunc,
819 NodeExecFunction execfunc);
820 void node_type_gpu(struct bNodeType *ntype, NodeGPUExecFunction gpufunc);
821 void node_type_internal_links(struct bNodeType *ntype,
822 void (*update_internal_links)(struct bNodeTree *, struct bNode *));
823
824 /** \} */
825
826 /* -------------------------------------------------------------------- */
827 /** \name Node Generic Functions
828 * \{ */
829
830 bool BKE_node_is_connected_to_output(struct bNodeTree *ntree, struct bNode *node);
831
832 /* ************** COMMON NODES *************** */
833
834 #define NODE_UNDEFINED -2 /* node type is not registered */
835 #define NODE_CUSTOM -1 /* for dynamically registered custom types */
836 #define NODE_GROUP 2
837 // #define NODE_FORLOOP 3 /* deprecated */
838 // #define NODE_WHILELOOP 4 /* deprecated */
839 #define NODE_FRAME 5
840 #define NODE_REROUTE 6
841 #define NODE_GROUP_INPUT 7
842 #define NODE_GROUP_OUTPUT 8
843 #define NODE_CUSTOM_GROUP 9
844
845 void BKE_node_tree_unlink_id(ID *id, struct bNodeTree *ntree);
846
847 /** \} */
848
849 /* -------------------------------------------------------------------- */
850 /** \name Node Tree Iterator
851 *
852 * Utility macro for visiting every node tree in the library data,
853 * including local bNodeTree blocks in other IDs.
854 * This avoids the need for callback functions and allows executing code
855 * in a single inner code block.
856 *
857 * Variables:
858 *
859 * - nodetree:
860 * The actual bNodeTree data block.
861 * Check nodetree->idname or nodetree->typeinfo to use only specific types.
862 *
863 * - id:
864 * The owner of the bNodeTree data block.
865 * Same as nodetree if it's a linkable node tree from the library.
866 *
867 * Examples:
868 *
869 * \code{.c}
870 * FOREACH_NODETREE_BEGIN(bmain, nodetree, id) {
871 * if (id == nodetree)
872 * printf("This is a linkable node tree");
873 * } FOREACH_NODETREE_END;
874 *
875 * FOREACH_NODETREE_BEGIN(bmain, nodetree, id) {
876 * if (nodetree->idname == "ShaderNodeTree")
877 * printf("This is a shader node tree);
878 * if (GS(id) == ID_MA)
879 * printf(" and it's owned by a material");
880 * } FOREACH_NODETREE_END;
881 * \endcode
882 *
883 * \{
884 */
885
886 /* should be an opaque type, only for internal use by BKE_node_tree_iter_*** */
887 struct NodeTreeIterStore {
888 bNodeTree *ngroup;
889 Scene *scene;
890 struct Material *mat;
891 Tex *tex;
892 struct Light *light;
893 struct World *world;
894 struct FreestyleLineStyle *linestyle;
895 struct Simulation *simulation;
896 };
897
898 void BKE_node_tree_iter_init(struct NodeTreeIterStore *ntreeiter, struct Main *bmain);
899 bool BKE_node_tree_iter_step(struct NodeTreeIterStore *ntreeiter,
900 struct bNodeTree **r_nodetree,
901 struct ID **r_id);
902
903 #define FOREACH_NODETREE_BEGIN(bmain, _nodetree, _id) \
904 { \
905 struct NodeTreeIterStore _nstore; \
906 bNodeTree *_nodetree; \
907 ID *_id; \
908 /* avoid compiler warning about unused variables */ \
909 BKE_node_tree_iter_init(&_nstore, bmain); \
910 while (BKE_node_tree_iter_step(&_nstore, &_nodetree, &_id) == true) { \
911 if (_nodetree) {
912
913 #define FOREACH_NODETREE_END \
914 } \
915 } \
916 } \
917 ((void)0)
918 /** \} */
919
920 /* -------------------------------------------------------------------- */
921 /** \name Node Tree
922 */
923
924 void BKE_nodetree_remove_layer_n(struct bNodeTree *ntree,
925 struct Scene *scene,
926 const int layer_index);
927
928 /* -------------------------------------------------------------------- */
929 /** \name Shader Nodes
930 * \{ */
931
932 /* note: types are needed to restore callbacks, don't change values */
933 /* range 1 - 100 is reserved for common nodes */
934 /* using toolbox, we add node groups by assuming the values below
935 * don't exceed NODE_GROUP_MENU for now. */
936
937 //#define SH_NODE_OUTPUT 1
938
939 //#define SH_NODE_MATERIAL 100
940 #define SH_NODE_RGB 101
941 #define SH_NODE_VALUE 102
942 #define SH_NODE_MIX_RGB 103
943 #define SH_NODE_VALTORGB 104
944 #define SH_NODE_RGBTOBW 105
945 #define SH_NODE_SHADERTORGB 106
946 //#define SH_NODE_TEXTURE 106
947 #define SH_NODE_NORMAL 107
948 //#define SH_NODE_GEOMETRY 108
949 #define SH_NODE_MAPPING 109
950 #define SH_NODE_CURVE_VEC 110
951 #define SH_NODE_CURVE_RGB 111
952 #define SH_NODE_CAMERA 114
953 #define SH_NODE_MATH 115
954 #define SH_NODE_VECTOR_MATH 116
955 #define SH_NODE_SQUEEZE 117
956 //#define SH_NODE_MATERIAL_EXT 118
957 #define SH_NODE_INVERT 119
958 #define SH_NODE_SEPRGB 120
959 #define SH_NODE_COMBRGB 121
960 #define SH_NODE_HUE_SAT 122
961 #define NODE_DYNAMIC 123
962
963 #define SH_NODE_OUTPUT_MATERIAL 124
964 #define SH_NODE_OUTPUT_WORLD 125
965 #define SH_NODE_OUTPUT_LIGHT 126
966 #define SH_NODE_FRESNEL 127
967 #define SH_NODE_MIX_SHADER 128
968 #define SH_NODE_ATTRIBUTE 129
969 #define SH_NODE_BACKGROUND 130
970 #define SH_NODE_BSDF_ANISOTROPIC 131
971 #define SH_NODE_BSDF_DIFFUSE 132
972 #define SH_NODE_BSDF_GLOSSY 133
973 #define SH_NODE_BSDF_GLASS 134
974 #define SH_NODE_BSDF_TRANSLUCENT 137
975 #define SH_NODE_BSDF_TRANSPARENT 138
976 #define SH_NODE_BSDF_VELVET 139
977 #define SH_NODE_EMISSION 140
978 #define SH_NODE_NEW_GEOMETRY 141
979 #define SH_NODE_LIGHT_PATH 142
980 #define SH_NODE_TEX_IMAGE 143
981 #define SH_NODE_TEX_SKY 145
982 #define SH_NODE_TEX_GRADIENT 146
983 #define SH_NODE_TEX_VORONOI 147
984 #define SH_NODE_TEX_MAGIC 148
985 #define SH_NODE_TEX_WAVE 149
986 #define SH_NODE_TEX_NOISE 150
987 #define SH_NODE_TEX_MUSGRAVE 152
988 #define SH_NODE_TEX_COORD 155
989 #define SH_NODE_ADD_SHADER 156
990 #define SH_NODE_TEX_ENVIRONMENT 157
991 // #define SH_NODE_OUTPUT_TEXTURE 158
992 #define SH_NODE_HOLDOUT 159
993 #define SH_NODE_LAYER_WEIGHT 160
994 #define SH_NODE_VOLUME_ABSORPTION 161
995 #define SH_NODE_VOLUME_SCATTER 162
996 #define SH_NODE_GAMMA 163
997 #define SH_NODE_TEX_CHECKER 164
998 #define SH_NODE_BRIGHTCONTRAST 165
999 #define SH_NODE_LIGHT_FALLOFF 166
1000 #define SH_NODE_OBJECT_INFO 167
1001 #define SH_NODE_PARTICLE_INFO 168
1002 #define SH_NODE_TEX_BRICK 169
1003 #define SH_NODE_BUMP 170
1004 #define SH_NODE_SCRIPT 171
1005 #define SH_NODE_AMBIENT_OCCLUSION 172
1006 #define SH_NODE_BSDF_REFRACTION 173
1007 #define SH_NODE_TANGENT 174
1008 #define SH_NODE_NORMAL_MAP 175
1009 #define SH_NODE_HAIR_INFO 176
1010 #define SH_NODE_SUBSURFACE_SCATTERING 177
1011 #define SH_NODE_WIREFRAME 178
1012 #define SH_NODE_BSDF_TOON 179
1013 #define SH_NODE_WAVELENGTH 180
1014 #define SH_NODE_BLACKBODY 181
1015 #define SH_NODE_VECT_TRANSFORM 182
1016 #define SH_NODE_SEPHSV 183
1017 #define SH_NODE_COMBHSV 184
1018 #define SH_NODE_BSDF_HAIR 185
1019 // #define SH_NODE_LAMP 186
1020 #define SH_NODE_UVMAP 187
1021 #define SH_NODE_SEPXYZ 188
1022 #define SH_NODE_COMBXYZ 189
1023 #define SH_NODE_OUTPUT_LINESTYLE 190
1024 #define SH_NODE_UVALONGSTROKE 191
1025 #define SH_NODE_TEX_POINTDENSITY 192
1026 #define SH_NODE_BSDF_PRINCIPLED 193
1027 #define SH_NODE_TEX_IES 194
1028 #define SH_NODE_EEVEE_SPECULAR 195
1029 #define SH_NODE_BEVEL 197
1030 #define SH_NODE_DISPLACEMENT 198
1031 #define SH_NODE_VECTOR_DISPLACEMENT 199
1032 #define SH_NODE_VOLUME_PRINCIPLED 200
1033 /* 201..700 occupied by other node types, continue from 701 */
1034 #define SH_NODE_BSDF_HAIR_PRINCIPLED 701
1035 #define SH_NODE_MAP_RANGE 702
1036 #define SH_NODE_CLAMP 703
1037 #define SH_NODE_TEX_WHITE_NOISE 704
1038 #define SH_NODE_VOLUME_INFO 705
1039 #define SH_NODE_VERTEX_COLOR 706
1040 #define SH_NODE_OUTPUT_AOV 707
1041 #define SH_NODE_VECTOR_ROTATE 708
1042
1043 /* custom defines options for Material node */
1044 // #define SH_NODE_MAT_DIFF 1
1045 // #define SH_NODE_MAT_SPEC 2
1046 // #define SH_NODE_MAT_NEG 4
1047
1048 /* API */
1049
1050 struct bNodeTreeExec *ntreeShaderBeginExecTree(struct bNodeTree *ntree);
1051 void ntreeShaderEndExecTree(struct bNodeTreeExec *exec);
1052 bool ntreeShaderExecTree(struct bNodeTree *ntree, int thread);
1053 struct bNode *ntreeShaderOutputNode(struct bNodeTree *ntree, int target);
1054
1055 void ntreeGPUMaterialNodes(struct bNodeTree *localtree,
1056 struct GPUMaterial *mat,
1057 bool *has_surface_output,
1058 bool *has_volume_output);
1059
1060 /** \} */
1061
1062 /* -------------------------------------------------------------------- */
1063 /** \name Composite Nodes
1064 * \{ */
1065
1066 /* output socket defines */
1067 #define RRES_OUT_IMAGE 0
1068 #define RRES_OUT_ALPHA 1
1069 // #define RRES_OUT_Z 2
1070 // #define RRES_OUT_NORMAL 3
1071 // #define RRES_OUT_UV 4
1072 // #define RRES_OUT_VEC 5
1073 // #define RRES_OUT_RGBA 6
1074 #define RRES_OUT_DIFF 7
1075 // #define RRES_OUT_SPEC 8
1076 // #define RRES_OUT_SHADOW 9
1077 // #define RRES_OUT_AO 10
1078 // #define RRES_OUT_REFLECT 11
1079 // #define RRES_OUT_REFRACT 12
1080 // #define RRES_OUT_INDIRECT 13
1081 // #define RRES_OUT_INDEXOB 14
1082 // #define RRES_OUT_INDEXMA 15
1083 // #define RRES_OUT_MIST 16
1084 // #define RRES_OUT_EMIT 17
1085 // #define RRES_OUT_ENV 18
1086 // #define RRES_OUT_DIFF_DIRECT 19
1087 // #define RRES_OUT_DIFF_INDIRECT 20
1088 // #define RRES_OUT_DIFF_COLOR 21
1089 // #define RRES_OUT_GLOSSY_DIRECT 22
1090 // #define RRES_OUT_GLOSSY_INDIRECT 23
1091 // #define RRES_OUT_GLOSSY_COLOR 24
1092 // #define RRES_OUT_TRANSM_DIRECT 25
1093 // #define RRES_OUT_TRANSM_INDIRECT 26
1094 // #define RRES_OUT_TRANSM_COLOR 27
1095 // #define RRES_OUT_SUBSURFACE_DIRECT 28
1096 // #define RRES_OUT_SUBSURFACE_INDIRECT 29
1097 // #define RRES_OUT_SUBSURFACE_COLOR 30
1098 // #define RRES_OUT_DEBUG 31
1099
1100 /* note: types are needed to restore callbacks, don't change values */
1101 #define CMP_NODE_VIEWER 201
1102 #define CMP_NODE_RGB 202
1103 #define CMP_NODE_VALUE 203
1104 #define CMP_NODE_MIX_RGB 204
1105 #define CMP_NODE_VALTORGB 205
1106 #define CMP_NODE_RGBTOBW 206
1107 #define CMP_NODE_NORMAL 207
1108 #define CMP_NODE_CURVE_VEC 208
1109 #define CMP_NODE_CURVE_RGB 209
1110 #define CMP_NODE_ALPHAOVER 210
1111 #define CMP_NODE_BLUR 211
1112 #define CMP_NODE_FILTER 212
1113 #define CMP_NODE_MAP_VALUE 213
1114 #define CMP_NODE_TIME 214
1115 #define CMP_NODE_VECBLUR 215
1116 #define CMP_NODE_SEPRGBA 216
1117 #define CMP_NODE_SEPHSVA 217
1118 #define CMP_NODE_SETALPHA 218
1119 #define CMP_NODE_HUE_SAT 219
1120 #define CMP_NODE_IMAGE 220
1121 #define CMP_NODE_R_LAYERS 221
1122 #define CMP_NODE_COMPOSITE 222
1123 #define CMP_NODE_OUTPUT_FILE 223
1124 #define CMP_NODE_TEXTURE 224
1125 #define CMP_NODE_TRANSLATE 225
1126 #define CMP_NODE_ZCOMBINE 226
1127 #define CMP_NODE_COMBRGBA 227
1128 #define CMP_NODE_DILATEERODE 228
1129 #define CMP_NODE_ROTATE 229
1130 #define CMP_NODE_SCALE 230
1131 #define CMP_NODE_SEPYCCA 231
1132 #define CMP_NODE_COMBYCCA 232
1133 #define CMP_NODE_SEPYUVA 233
1134 #define CMP_NODE_COMBYUVA 234
1135 #define CMP_NODE_DIFF_MATTE 235
1136 #define CMP_NODE_COLOR_SPILL 236
1137 #define CMP_NODE_CHROMA_MATTE 237
1138 #define CMP_NODE_CHANNEL_MATTE 238
1139 #define CMP_NODE_FLIP 239
1140 #define CMP_NODE_SPLITVIEWER 240
1141 // #define CMP_NODE_INDEX_MASK 241
1142 #define CMP_NODE_MAP_UV 242
1143 #define CMP_NODE_ID_MASK 243
1144 #define CMP_NODE_DEFOCUS 244
1145 #define CMP_NODE_DISPLACE 245
1146 #define CMP_NODE_COMBHSVA 246
1147 #define CMP_NODE_MATH 247
1148 #define CMP_NODE_LUMA_MATTE 248
1149 #define CMP_NODE_BRIGHTCONTRAST 249
1150 #define CMP_NODE_GAMMA 250
1151 #define CMP_NODE_INVERT 251
1152 #define CMP_NODE_NORMALIZE 252
1153 #define CMP_NODE_CROP 253
1154 #define CMP_NODE_DBLUR 254
1155 #define CMP_NODE_BILATERALBLUR 255
1156 #define CMP_NODE_PREMULKEY 256
1157 #define CMP_NODE_DIST_MATTE 257
1158 #define CMP_NODE_VIEW_LEVELS 258
1159 #define CMP_NODE_COLOR_MATTE 259
1160 #define CMP_NODE_COLORBALANCE 260
1161 #define CMP_NODE_HUECORRECT 261
1162 #define CMP_NODE_MOVIECLIP 262
1163 #define CMP_NODE_STABILIZE2D 263
1164 #define CMP_NODE_TRANSFORM 264
1165 #define CMP_NODE_MOVIEDISTORTION 265
1166 #define CMP_NODE_DOUBLEEDGEMASK 266
1167 #define CMP_NODE_OUTPUT_MULTI_FILE__DEPRECATED \
1168 267 /* DEPRECATED multi file node has been merged into regular CMP_NODE_OUTPUT_FILE */
1169 #define CMP_NODE_MASK 268
1170 #define CMP_NODE_KEYINGSCREEN 269
1171 #define CMP_NODE_KEYING 270
1172 #define CMP_NODE_TRACKPOS 271
1173 #define CMP_NODE_INPAINT 272
1174 #define CMP_NODE_DESPECKLE 273
1175
1176 #define CMP_NODE_GLARE 301
1177 #define CMP_NODE_TONEMAP 302
1178 #define CMP_NODE_LENSDIST 303
1179 #define CMP_NODE_SUNBEAMS 304
1180
1181 #define CMP_NODE_COLORCORRECTION 312
1182 #define CMP_NODE_MASK_BOX 313
1183 #define CMP_NODE_MASK_ELLIPSE 314
1184 #define CMP_NODE_BOKEHIMAGE 315
1185 #define CMP_NODE_BOKEHBLUR 316
1186 #define CMP_NODE_SWITCH 317
1187 #define CMP_NODE_PIXELATE 318
1188
1189 #define CMP_NODE_MAP_RANGE 319
1190 #define CMP_NODE_PLANETRACKDEFORM 320
1191 #define CMP_NODE_CORNERPIN 321
1192 #define CMP_NODE_SWITCH_VIEW 322
1193 #define CMP_NODE_CRYPTOMATTE 323
1194 #define CMP_NODE_DENOISE 324
1195
1196 /* channel toggles */
1197 #define CMP_CHAN_RGB 1
1198 #define CMP_CHAN_A 2
1199
1200 /* filter types */
1201 #define CMP_FILT_SOFT 0
1202 #define CMP_FILT_SHARP 1
1203 #define CMP_FILT_LAPLACE 2
1204 #define CMP_FILT_SOBEL 3
1205 #define CMP_FILT_PREWITT 4
1206 #define CMP_FILT_KIRSCH 5
1207 #define CMP_FILT_SHADOW 6
1208
1209 /* scale node type, in custom1 */
1210 #define CMP_SCALE_RELATIVE 0
1211 #define CMP_SCALE_ABSOLUTE 1
1212 #define CMP_SCALE_SCENEPERCENT 2
1213 #define CMP_SCALE_RENDERPERCENT 3
1214 /* custom2 */
1215 #define CMP_SCALE_RENDERSIZE_FRAME_ASPECT (1 << 0)
1216 #define CMP_SCALE_RENDERSIZE_FRAME_CROP (1 << 1)
1217
1218 /* track position node, in custom1 */
1219 #define CMP_TRACKPOS_ABSOLUTE 0
1220 #define CMP_TRACKPOS_RELATIVE_START 1
1221 #define CMP_TRACKPOS_RELATIVE_FRAME 2
1222 #define CMP_TRACKPOS_ABSOLUTE_FRAME 3
1223
1224 /* API */
1225 void ntreeCompositExecTree(struct Scene *scene,
1226 struct bNodeTree *ntree,
1227 struct RenderData *rd,
1228 int rendering,
1229 int do_previews,
1230 const struct ColorManagedViewSettings *view_settings,
1231 const struct ColorManagedDisplaySettings *display_settings,
1232 const char *view_name);
1233 void ntreeCompositTagRender(struct Scene *scene);
1234 void ntreeCompositUpdateRLayers(struct bNodeTree *ntree);
1235 void ntreeCompositRegisterPass(struct bNodeTree *ntree,
1236 struct Scene *scene,
1237 struct ViewLayer *view_layer,
1238 const char *name,
1239 eNodeSocketDatatype type);
1240 void ntreeCompositClearTags(struct bNodeTree *ntree);
1241
1242 struct bNodeSocket *ntreeCompositOutputFileAddSocket(struct bNodeTree *ntree,
1243 struct bNode *node,
1244 const char *name,
1245 struct ImageFormatData *im_format);
1246 int ntreeCompositOutputFileRemoveActiveSocket(struct bNodeTree *ntree, struct bNode *node);
1247 void ntreeCompositOutputFileSetPath(struct bNode *node,
1248 struct bNodeSocket *sock,
1249 const char *name);
1250 void ntreeCompositOutputFileSetLayer(struct bNode *node,
1251 struct bNodeSocket *sock,
1252 const char *name);
1253 /* needed in do_versions */
1254 void ntreeCompositOutputFileUniquePath(struct ListBase *list,
1255 struct bNodeSocket *sock,
1256 const char defname[],
1257 char delim);
1258 void ntreeCompositOutputFileUniqueLayer(struct ListBase *list,
1259 struct bNodeSocket *sock,
1260 const char defname[],
1261 char delim);
1262
1263 void ntreeCompositColorBalanceSyncFromLGG(bNodeTree *ntree, bNode *node);
1264 void ntreeCompositColorBalanceSyncFromCDL(bNodeTree *ntree, bNode *node);
1265
1266 void ntreeCompositCryptomatteSyncFromAdd(bNodeTree *ntree, bNode *node);
1267 void ntreeCompositCryptomatteSyncFromRemove(bNodeTree *ntree, bNode *node);
1268 struct bNodeSocket *ntreeCompositCryptomatteAddSocket(struct bNodeTree *ntree, struct bNode *node);
1269 int ntreeCompositCryptomatteRemoveSocket(struct bNodeTree *ntree, struct bNode *node);
1270
1271 /** \} */
1272
1273 /* -------------------------------------------------------------------- */
1274 /** \name Texture Nodes
1275 * \{ */
1276
1277 struct TexResult;
1278
1279 #define TEX_NODE_OUTPUT 401
1280 #define TEX_NODE_CHECKER 402
1281 #define TEX_NODE_TEXTURE 403
1282 #define TEX_NODE_BRICKS 404
1283 #define TEX_NODE_MATH 405
1284 #define TEX_NODE_MIX_RGB 406
1285 #define TEX_NODE_RGBTOBW 407
1286 #define TEX_NODE_VALTORGB 408
1287 #define TEX_NODE_IMAGE 409
1288 #define TEX_NODE_CURVE_RGB 410
1289 #define TEX_NODE_INVERT 411
1290 #define TEX_NODE_HUE_SAT 412
1291 #define TEX_NODE_CURVE_TIME 413
1292 #define TEX_NODE_ROTATE 414
1293 #define TEX_NODE_VIEWER 415
1294 #define TEX_NODE_TRANSLATE 416
1295 #define TEX_NODE_COORD 417
1296 #define TEX_NODE_DISTANCE 418
1297 #define TEX_NODE_COMPOSE 419
1298 #define TEX_NODE_DECOMPOSE 420
1299 #define TEX_NODE_VALTONOR 421
1300 #define TEX_NODE_SCALE 422
1301 #define TEX_NODE_AT 423
1302
1303 /* 501-599 reserved. Use like this: TEX_NODE_PROC + TEX_CLOUDS, etc */
1304 #define TEX_NODE_PROC 500
1305 #define TEX_NODE_PROC_MAX 600
1306
1307 /* API */
1308 void ntreeTexCheckCyclics(struct bNodeTree *ntree);
1309
1310 struct bNodeTreeExec *ntreeTexBeginExecTree(struct bNodeTree *ntree);
1311 void ntreeTexEndExecTree(struct bNodeTreeExec *exec);
1312 int ntreeTexExecTree(struct bNodeTree *ntree,
1313 struct TexResult *target,
1314 const float co[3],
1315 float dxt[3],
1316 float dyt[3],
1317 int osatex,
1318 const short thread,
1319 const struct Tex *tex,
1320 short which_output,
1321 int cfra,
1322 int preview,
1323 struct MTex *mtex);
1324 /** \} */
1325
1326 /* -------------------------------------------------------------------- */
1327 /** \name Function Nodes
1328 * \{ */
1329
1330 #define FN_NODE_BOOLEAN_MATH 1200
1331 #define FN_NODE_SWITCH 1201
1332 #define FN_NODE_FLOAT_COMPARE 1202
1333 #define FN_NODE_GROUP_INSTANCE_ID 1203
1334 #define FN_NODE_COMBINE_STRINGS 1204
1335 #define FN_NODE_OBJECT_TRANSFORMS 1205
1336 #define FN_NODE_RANDOM_FLOAT 1206
1337
1338 /** \} */
1339
1340 void init_nodesystem(void);
1341 void free_nodesystem(void);
1342
1343 /* -------------------------------------------------------------------- */
1344 /* evaluation support, */
1345
1346 struct Depsgraph;
1347
1348 void BKE_nodetree_shading_params_eval(struct Depsgraph *depsgraph,
1349 struct bNodeTree *ntree_dst,
1350 const struct bNodeTree *ntree_src);
1351
1352 extern struct bNodeType NodeTypeUndefined;
1353 extern struct bNodeSocketType NodeSocketTypeUndefined;
1354
1355 #ifdef __cplusplus
1356 }
1357 #endif
1358