Blender V5.3
node_shader_tree.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2007 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cstring>
10
11#include "DNA_light_types.h"
12#include "DNA_linestyle_types.h"
13#include "DNA_material_types.h"
14#include "DNA_node_types.h"
15#include "DNA_scene_types.h"
16#include "DNA_space_types.h"
17#include "DNA_world_types.h"
18
19#include "BLI_array.hh"
20#include "BLI_linklist.hh"
21#include "BLI_listbase.hh"
22#include "BLI_map.hh"
23#include "BLI_math_vector_c.hh"
24#include "BLI_set.hh"
25#include "BLI_stack.hh"
26#include "BLI_threads.hh"
27#include "BLI_utildefines.hh"
28#include "BLI_vector.hh"
29
30#include "BKE_context.hh"
31#include "BKE_global.hh"
32#include "BKE_layer.hh"
33#include "BKE_lib_id.hh"
34#include "BKE_linestyle.h"
35#include "BKE_material.hh"
36#include "BKE_node.hh"
38#include "BKE_node_runtime.hh"
40#include "BKE_scene.hh"
41
42#include "RNA_prototypes.hh"
43
44#include "UI_resources.hh"
45
46#include "NOD_shader.h"
47
48#include "node_common.h"
49#include "node_exec.hh"
50#include "node_shader_util.hh"
51#include "node_util.hh"
52
53namespace blender {
54
55static bool shader_tree_poll(const bContext *C, bke::bNodeTreeType * /*treetype*/)
56{
57 Scene *scene = CTX_data_scene(C);
58 const char *engine_id = scene->r.engine;
59
60 /* Allow empty engine string too,
61 * this is from older versions that didn't have registerable engines yet. */
62 return (engine_id[0] == '\0' || STREQ(engine_id, RE_engine_id_CYCLES) ||
64}
65
67 bke::bNodeTreeType * /*treetype*/,
68 bNodeTree **r_ntree,
69 ID **r_id,
70 ID **r_from)
71{
73 const Main *bmain = CTX_data_main(C);
74 Scene *scene = CTX_data_scene(C);
75 ViewLayer *view_layer = CTX_data_view_layer(C);
76 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
78
79 if (snode->shaderfrom == SNODE_SHADER_OBJECT) {
80 if (ob) {
81 *r_from = &ob->id;
82 if (ob->type == OB_LAMP) {
83 *r_id = ob->data;
84 *r_ntree = (id_cast<Light *>(ob->data))->nodetree;
85 }
86 else {
88 if (ma) {
89 *r_id = &ma->id;
90 *r_ntree = ma->nodetree;
91 }
92 }
93 }
94 }
95#ifdef WITH_FREESTYLE
96 else if (snode->shaderfrom == SNODE_SHADER_LINESTYLE) {
98 if (linestyle) {
99 *r_from = nullptr;
100 *r_id = &linestyle->id;
101 *r_ntree = linestyle->nodetree;
102 }
103 }
104#endif
105 else { /* SNODE_SHADER_WORLD */
106 if (scene->world) {
107 *r_from = nullptr;
108 *r_id = &scene->world->id;
109 *r_ntree = scene->world->nodetree;
110 }
111 }
112}
113
114static void foreach_nodeclass(void *calldata, bke::bNodeClassCallback func)
115{
116 func(calldata, NODE_CLASS_INPUT, N_("Input"));
117 func(calldata, NODE_CLASS_OUTPUT, N_("Output"));
118 func(calldata, NODE_CLASS_SHADER, N_("Shader"));
119 func(calldata, NODE_CLASS_TEXTURE, N_("Texture"));
120 func(calldata, NODE_CLASS_OP_COLOR, N_("Color"));
121 func(calldata, NODE_CLASS_OP_VECTOR, N_("Vector"));
122 func(calldata, NODE_CLASS_CONVERTER, N_("Converter"));
123 func(calldata, NODE_CLASS_SCRIPT, N_("Script"));
124 func(calldata, NODE_CLASS_GROUP, N_("Group"));
125 func(calldata, NODE_CLASS_INTERFACE, N_("Interface"));
126 func(calldata, NODE_CLASS_LAYOUT, N_("Layout"));
127}
128
129static void localize(bNodeTree *localtree, bNodeTree * /*ntree*/)
130{
131 /* replace muted nodes and reroute nodes by internal links */
132 for (bNode &node : localtree->nodes.items_mutable()) {
133 if (node.is_muted() || node.is_reroute()) {
134 if (node.is_group() && node.id) {
135 /* Free the group like in #ntree_shader_groups_flatten. */
136 bNodeTree *group = reinterpret_cast<bNodeTree *>(node.id);
138 MEM_delete(group);
139 node.id = nullptr;
140 }
141
142 bke::node_internal_relink(*localtree, node);
144 }
145 }
146}
147
148static void update(bNodeTree *ntree)
149{
151
153}
154
156{
157 /* Can't connect shader into other socket types, other way around is fine
158 * since it will be interpreted as emission. */
159 if (from == SOCK_SHADER) {
160 return to == SOCK_SHADER;
161 }
164 {
165 return from == to;
166 }
167 return true;
168}
169
171 bke::bNodeSocketType *socket_type)
172{
173 return bke::node_is_static_socket_type(*socket_type) && ELEM(socket_type->type,
175 SOCK_INT,
178 SOCK_RGBA,
182 SOCK_MENU,
184}
185
187
189{
190 bke::bNodeTreeType *tt = ntreeType_Shader = MEM_new<bke::bNodeTreeType>(__func__);
191
192 tt->type = NTREE_SHADER;
193 tt->idname = "ShaderNodeTree"_ustr;
194 tt->group_idname = "ShaderNodeGroup"_ustr;
195 tt->ui_name = N_("Shader Editor");
196 tt->ui_icon = ICON_NODE_MATERIAL;
197 tt->ui_description = N_("Edit materials, lights, and world shading using nodes");
198 tt->asset_catalog_path_prefix = "Shading";
199
201 tt->localize = localize;
202 tt->update = update;
207
208 tt->rna_ext.srna = RNA_ShaderNodeTree;
209
211}
212
213/* GPU material from shader nodes */
214
216{
217 /* Make sure we only have single node tagged as output. */
219
220 /* Find output node that matches type and target. If there are
221 * multiple, we prefer exact target match and active nodes. */
222 bNode *output_node = nullptr;
223
224 for (bNode &node : ntree->nodes) {
225 if (!ELEM(
227 {
228 continue;
229 }
230
231 if (node.custom1 == SHD_OUTPUT_ALL) {
232 if (output_node == nullptr) {
233 output_node = &node;
234 }
235 else if (output_node->custom1 == SHD_OUTPUT_ALL) {
236 if ((node.flag & NODE_DO_OUTPUT) && !(output_node->flag & NODE_DO_OUTPUT)) {
237 output_node = &node;
238 }
239 }
240 }
241 else if (node.custom1 == target) {
242 if (output_node == nullptr) {
243 output_node = &node;
244 }
245 else if (output_node->custom1 == SHD_OUTPUT_ALL) {
246 output_node = &node;
247 }
248 else if ((node.flag & NODE_DO_OUTPUT) && !(output_node->flag & NODE_DO_OUTPUT)) {
249 output_node = &node;
250 }
251 }
252 }
253
254 return output_node;
255}
256
257/* Find socket with a specified identifier. */
258static bNodeSocket *ntree_shader_node_find_socket(ListBaseT<bNodeSocket> *sockets,
259 const char *identifier)
260{
261 for (bNodeSocket &sock : *sockets) {
262 if (STREQ(sock.identifier, identifier)) {
263 return &sock;
264 }
265 }
266 return nullptr;
267}
268
269/* Find input socket with a specified identifier. */
270static bNodeSocket *ntree_shader_node_find_input(bNode *node, const char *identifier)
271{
272 return ntree_shader_node_find_socket(&node->inputs, identifier);
273}
274
275/* Find output socket with a specified identifier. */
276static bNodeSocket *ntree_shader_node_find_output(bNode *node, const char *identifier)
277{
278 return ntree_shader_node_find_socket(&node->outputs, identifier);
279}
280
281/* Find input socket at a specific position. */
283{
284 return reinterpret_cast<bNodeSocket *>(BLI_findlink(&node->inputs, n));
285}
286
287/* Find output socket at a specific position. */
289{
290 return reinterpret_cast<bNodeSocket *>(BLI_findlink(&node->outputs, n));
291}
292
293/* TODO: should be migrated to shader_nodes_inline.c See !153704. */
295{
296 /* To avoid more trouble in the node tree processing (especially inside
297 * `ntree_shader_weight_tree_invert()`) we disconnect the script node since they are not
298 * supported in EEVEE (see #101702). */
299 for (bNodeLink &link : ntree->links.items_mutable()) {
300 if ((link.tonode->type_legacy == SH_NODE_SCRIPT) ||
301 (link.fromnode->type_legacy == SH_NODE_SCRIPT))
302 {
303 bke::node_remove_link(ntree, link);
304 }
305 }
306}
307
309 bool (*node_filter)(const bNode *node);
311};
312
313static bool ntree_branch_count_and_tag_nodes(bNode *fromnode, bNode *tonode, void *userdata)
314{
315 branchIterData *iter = static_cast<branchIterData *>(userdata);
316 if (fromnode->runtime->tmp_flag == -1 &&
317 (iter->node_filter == nullptr || iter->node_filter(fromnode)))
318 {
319 fromnode->runtime->tmp_flag = iter->node_count;
320 iter->node_count++;
321 }
322 if (tonode->runtime->tmp_flag == -1 &&
323 (iter->node_filter == nullptr || iter->node_filter(tonode)))
324 {
325 tonode->runtime->tmp_flag = iter->node_count;
326 iter->node_count++;
327 }
328 return true;
329}
330
331/* Create a copy of a branch starting from a given node. */
333 bNode *start_node,
334 bool (*node_filter)(const bNode *node))
335{
336 auto gather_branch_nodes = [](bNode *fromnode, bNode * /*tonode*/, void *userdata) {
337 Set<bNode *> *set = static_cast<Set<bNode *> *>(userdata);
338 set->add(fromnode);
339 return true;
340 };
341 Set<bNode *> branch_nodes = {start_node};
342 bke::node_chain_iterator_backwards(ntree, start_node, gather_branch_nodes, &branch_nodes, 0);
343
344 /* Initialize `runtime->tmp_flag`. */
345 for (bNode &node : ntree->nodes) {
346 node.runtime->tmp_flag = -1;
347 }
348 /* Count and tag all nodes inside the displacement branch of the tree. */
349 branchIterData iter_data;
350 iter_data.node_filter = node_filter;
351 iter_data.node_count = 0;
353 ntree, start_node, ntree_branch_count_and_tag_nodes, &iter_data, 1);
354 /* Copies of the non-filtered nodes on the branch. */
355 Array<bNode *> nodes_copy(iter_data.node_count);
356
357 for (bNode &node : ntree->nodes) {
358 if (node.runtime->tmp_flag >= 0) {
359 int id = node.runtime->tmp_flag;
360 /* Avoid creating unique names in the new tree, since it is very slow.
361 * The names on the new nodes will be invalid. */
363 nodes_copy[id] = bke::node_copy_with_mapping(ntree,
364 node,
367 std::nullopt,
368 std::nullopt,
369 socket_map,
370 true);
371
372 bNode *copy = nodes_copy[id];
373 copy->runtime->tmp_flag = -2; /* Copy */
374 copy->runtime->original = node.runtime->original;
375 /* Make sure to clear all sockets links as they are invalid. */
376 for (bNodeSocket &sock : copy->inputs) {
377 sock.link = nullptr;
378 }
379 for (bNodeSocket &sock : copy->outputs) {
380 sock.link = nullptr;
381 }
382 }
383 }
384
385 /* Unlink the original nodes from this branch and link the copies. */
386 for (bNodeLink &link : ntree->links.items_mutable()) {
387 bool from_copy = link.fromnode->runtime->tmp_flag >= 0;
388 bool to_copy = link.tonode->runtime->tmp_flag >= 0;
389 if (from_copy && to_copy) {
390 bNode *from_node = nodes_copy[link.fromnode->runtime->tmp_flag];
391 bNode *to_node = nodes_copy[link.tonode->runtime->tmp_flag];
392 bke::node_add_link(*ntree,
393 *from_node,
394 *ntree_shader_node_find_output(from_node, link.fromsock->identifier),
395 *to_node,
396 *ntree_shader_node_find_input(to_node, link.tosock->identifier));
397 }
398 else if (to_copy) {
399 bNode *to_node = nodes_copy[link.tonode->runtime->tmp_flag];
400 bke::node_add_link(*ntree,
401 *link.fromnode,
402 *link.fromsock,
403 *to_node,
404 *ntree_shader_node_find_input(to_node, link.tosock->identifier));
405 }
406 else if (from_copy && branch_nodes.contains(link.tonode)) {
407 bNode *from_node = nodes_copy[link.fromnode->runtime->tmp_flag];
408 bke::node_add_link(*ntree,
409 *from_node,
410 *ntree_shader_node_find_output(from_node, link.fromsock->identifier),
411 *link.tonode,
412 *link.tosock);
413 bke::node_remove_link(ntree, link);
414 }
415 }
416}
417
418/* Generate emission node to convert regular data to closure sockets.
419 * Returns validity of the tree.
420 */
422{
423 bool modified = false;
424 for (bNodeLink &link : ntree->links.items_mutable()) {
425 if ((link.fromsock->type != SOCK_SHADER) && (link.tosock->type == SOCK_SHADER)) {
426 bNode *emission_node = bke::node_add_static_node(nullptr, *ntree, SH_NODE_EMISSION);
427 bNodeSocket *in_sock = ntree_shader_node_find_input(emission_node, "Color");
428 bNodeSocket *out_sock = ntree_shader_node_find_output(emission_node, "Emission");
429 bke::node_add_link(*ntree, *link.fromnode, *link.fromsock, *emission_node, *in_sock);
430 bke::node_add_link(*ntree, *emission_node, *out_sock, *link.tonode, *link.tosock);
431 bke::node_remove_link(ntree, link);
432 modified = true;
433 }
434 else if ((link.fromsock->type == SOCK_SHADER) && (link.tosock->type != SOCK_SHADER)) {
435 bke::node_remove_link(ntree, link);
437 modified = true;
438 }
439 }
440 if (modified) {
442 }
443 return true;
444}
445
446/* Socket already has a link to it. Add weights together. */
448 bNode * /*fromnode*/,
449 bNodeSocket *fromsock,
450 bNode **tonode,
451 bNodeSocket **tosock)
452{
453 bNode *addnode = bke::node_add_static_node(nullptr, *ntree, SH_NODE_MATH);
454 addnode->custom1 = NODE_MATH_ADD;
455 addnode->runtime->tmp_flag = -2; /* Copy */
456 bNodeSocket *addsock_out = ntree_shader_node_output_get(addnode, 0);
457 bNodeSocket *addsock_in0 = ntree_shader_node_input_get(addnode, 0);
458 bNodeSocket *addsock_in1 = ntree_shader_node_input_get(addnode, 1);
459 bNodeLink *oldlink = fromsock->link;
460 bke::node_add_link(*ntree, *oldlink->fromnode, *oldlink->fromsock, *addnode, *addsock_in0);
461 bke::node_add_link(*ntree, **tonode, **tosock, *addnode, *addsock_in1);
462 bke::node_remove_link(ntree, *oldlink);
463 *tonode = addnode;
464 *tosock = addsock_out;
465}
466
467static bool ntree_weight_tree_tag_nodes(bNode *fromnode, bNode *tonode, void *userdata)
468{
469 int *node_count = static_cast<int *>(userdata);
470 bool to_node_from_weight_tree = ELEM(tonode->type_legacy,
476 if (tonode->runtime->tmp_flag == -1 && to_node_from_weight_tree) {
477 tonode->runtime->tmp_flag = *node_count;
478 *node_count += (tonode->type_legacy == SH_NODE_MIX_SHADER) ? 4 : 1;
479 }
480 if (fromnode->runtime->tmp_flag == -1 &&
482 {
483 fromnode->runtime->tmp_flag = *node_count;
484 *node_count += (fromnode->type_legacy == SH_NODE_MIX_SHADER) ? 4 : 1;
485 }
486 /* Note: We do not continue recursing after a shader-to-rgb node as they get processed
487 * independently/ */
488 return to_node_from_weight_tree && fromnode->type_legacy != SH_NODE_SHADERTORGB;
489}
490
491/* Invert evaluation order of the weight tree (add & mix closure nodes) to feed the closure nodes
492 * with their respective weights. */
493static void ntree_shader_weight_tree_invert(bNodeTree *ntree, bNode *output_node)
494{
495 bNodeLink *displace_link = nullptr;
496 bNodeSocket *displace_output = ntree_shader_node_find_input(output_node, "Displacement");
497 if (displace_output && displace_output->link) {
498 /* Remove any displacement link to avoid tagging it later on. */
499 displace_link = displace_output->link;
500 displace_output->link = nullptr;
501 }
502 bNodeLink *thickness_link = nullptr;
503 bNodeSocket *thickness_output = ntree_shader_node_find_input(output_node, "Thickness");
504 if (thickness_output && thickness_output->link) {
505 /* Remove any thickness link to avoid tagging it later on. */
506 thickness_link = thickness_output->link;
507 thickness_output->link = nullptr;
508 }
509 /* Init tmp flag. */
510 for (bNode &node : ntree->nodes) {
511 node.runtime->tmp_flag = -1;
512 }
513 /* Tag nodes from the weight tree. Only tag output node and mix/add shader nodes. */
514 output_node->runtime->tmp_flag = 0;
515 int node_count = 1;
517 ntree, output_node, ntree_weight_tree_tag_nodes, &node_count, 0);
518 /* Make a mirror copy of the weight tree. */
519 Array<bNode *> nodes_copy(node_count);
520 for (bNode &node : ntree->nodes) {
521 if (node.runtime->tmp_flag >= 0) {
522 int id = node.runtime->tmp_flag;
523
524 switch (node.type_legacy) {
529 /* Start the tree with full weight. */
530 nodes_copy[id] = bke::node_add_static_node(nullptr, *ntree, SH_NODE_VALUE);
531 nodes_copy[id]->runtime->tmp_flag = -2; /* Copy */
532 ((bNodeSocketValueFloat *)ntree_shader_node_output_get(nodes_copy[id], 0)->default_value)
533 ->value = 1.0f;
534 break;
535 }
536 case SH_NODE_ADD_SHADER: {
537 /* Simple passthrough node. Each original inputs will get the same weight. */
538 /* TODO(fclem): Better use some kind of reroute node? */
539 nodes_copy[id] = bke::node_add_static_node(nullptr, *ntree, SH_NODE_MATH);
540 nodes_copy[id]->custom1 = NODE_MATH_ADD;
541 nodes_copy[id]->runtime->tmp_flag = -2; /* Copy */
542 ((bNodeSocketValueFloat *)ntree_shader_node_input_get(nodes_copy[id], 0)->default_value)
543 ->value = 0.0f;
544 break;
545 }
546 case SH_NODE_MIX_SHADER: {
547 /* We need multiple nodes to emulate the mix node in reverse. */
548 bNode *fromnode, *tonode;
549 bNodeSocket *fromsock, *tosock;
550 int id_start = id;
551 /* output = (factor * input_weight) */
552 nodes_copy[id] = bke::node_add_static_node(nullptr, *ntree, SH_NODE_MATH);
553 nodes_copy[id]->custom1 = NODE_MATH_MULTIPLY;
554 nodes_copy[id]->runtime->tmp_flag = -2; /* Copy */
555 id++;
556 /* output = ((1.0 - factor) * input_weight) <=> (input_weight - factor * input_weight) */
557 nodes_copy[id] = bke::node_add_static_node(nullptr, *ntree, SH_NODE_MATH);
558 nodes_copy[id]->custom1 = NODE_MATH_SUBTRACT;
559 nodes_copy[id]->runtime->tmp_flag = -2; /* Copy */
560 id++;
561 /* Node sanitizes the input mix factor by clamping it. */
562 nodes_copy[id] = bke::node_add_static_node(nullptr, *ntree, SH_NODE_MATH);
563 nodes_copy[id]->custom1 = NODE_MATH_ADD;
564 nodes_copy[id]->custom2 = SHD_MATH_CLAMP;
565 nodes_copy[id]->runtime->tmp_flag = -2; /* Copy */
566 ((bNodeSocketValueFloat *)ntree_shader_node_input_get(nodes_copy[id], 0)->default_value)
567 ->value = 0.0f;
568 /* Copy default value if no link present. */
569 bNodeSocket *fac_sock = ntree_shader_node_find_input(&node, "Fac");
570 if (!fac_sock->link) {
571 float default_value = ((bNodeSocketValueFloat *)fac_sock->default_value)->value;
572 bNodeSocket *dst_sock = ntree_shader_node_input_get(nodes_copy[id], 1);
573 ((bNodeSocketValueFloat *)dst_sock->default_value)->value = default_value;
574 }
575 id++;
576 /* Reroute the weight input to the 3 processing nodes. Simplify linking later-on. */
577 /* TODO(fclem): Better use some kind of reroute node? */
578 nodes_copy[id] = bke::node_add_static_node(nullptr, *ntree, SH_NODE_MATH);
579 nodes_copy[id]->custom1 = NODE_MATH_ADD;
580 nodes_copy[id]->runtime->tmp_flag = -2; /* Copy */
581 ((bNodeSocketValueFloat *)ntree_shader_node_input_get(nodes_copy[id], 0)->default_value)
582 ->value = 0.0f;
583 id++;
584 /* Link between nodes for the subtraction. */
585 fromnode = nodes_copy[id_start];
586 tonode = nodes_copy[id_start + 1];
587 fromsock = ntree_shader_node_output_get(fromnode, 0);
588 tosock = ntree_shader_node_input_get(tonode, 1);
589 bke::node_add_link(*ntree, *fromnode, *fromsock, *tonode, *tosock);
590 /* Link mix input to first node. */
591 fromnode = nodes_copy[id_start + 2];
592 tonode = nodes_copy[id_start];
593 fromsock = ntree_shader_node_output_get(fromnode, 0);
594 tosock = ntree_shader_node_input_get(tonode, 1);
595 bke::node_add_link(*ntree, *fromnode, *fromsock, *tonode, *tosock);
596 /* Link weight input to both multiply nodes. */
597 fromnode = nodes_copy[id_start + 3];
598 fromsock = ntree_shader_node_output_get(fromnode, 0);
599 tonode = nodes_copy[id_start];
600 tosock = ntree_shader_node_input_get(tonode, 0);
601 bke::node_add_link(*ntree, *fromnode, *fromsock, *tonode, *tosock);
602 tonode = nodes_copy[id_start + 1];
603 tosock = ntree_shader_node_input_get(tonode, 0);
604 bke::node_add_link(*ntree, *fromnode, *fromsock, *tonode, *tosock);
605 break;
606 }
607 default:
608 BLI_assert(0);
609 break;
610 }
611 }
612 }
613 /* Recreate links between copied nodes. */
614 for (bNode &node : ntree->nodes) {
615 if (node.runtime->tmp_flag >= 0) {
616 /* Naming can be confusing here. We use original node-link name for from/to prefix.
617 * The final link is in reversed order. */
618
619 for (const auto [socket_index, sock] : node.inputs.enumerate()) {
620 bNodeSocket *tosock;
621 bNode *tonode;
622
623 switch (node.type_legacy) {
628 case SH_NODE_ADD_SHADER: {
629 tonode = nodes_copy[node.runtime->tmp_flag];
630 tosock = ntree_shader_node_output_get(tonode, 0);
631 break;
632 }
633 case SH_NODE_MIX_SHADER: {
634 if (socket_index == 0) {
635 /* Mix Factor. */
636 tonode = nodes_copy[node.runtime->tmp_flag + 2];
637 tosock = ntree_shader_node_input_get(tonode, 1);
638 }
639 else if (socket_index == 1) {
640 /* Shader 1. */
641 tonode = nodes_copy[node.runtime->tmp_flag + 1];
642 tosock = ntree_shader_node_output_get(tonode, 0);
643 }
644 else {
645 /* Shader 2. */
646 tonode = nodes_copy[node.runtime->tmp_flag];
647 tosock = ntree_shader_node_output_get(tonode, 0);
648 }
649 break;
650 }
651 default:
652 BLI_assert(0);
653 break;
654 }
655
656 if (sock.link) {
657 bNodeSocket *fromsock;
658 bNode *fromnode = sock.link->fromnode;
659
660 switch (fromnode->type_legacy) {
661 case SH_NODE_ADD_SHADER: {
662 fromnode = nodes_copy[fromnode->runtime->tmp_flag];
663 fromsock = ntree_shader_node_input_get(fromnode, 1);
664 if (fromsock->link) {
665 ntree_weight_tree_merge_weight(ntree, fromnode, fromsock, &tonode, &tosock);
666 }
667 break;
668 }
669 case SH_NODE_MIX_SHADER: {
670 fromnode = nodes_copy[fromnode->runtime->tmp_flag + 3];
671 fromsock = ntree_shader_node_input_get(fromnode, 1);
672 if (fromsock->link) {
673 ntree_weight_tree_merge_weight(ntree, fromnode, fromsock, &tonode, &tosock);
674 }
675 break;
676 }
692 case SH_NODE_EMISSION:
693 case SH_NODE_HOLDOUT:
700 fromsock = ntree_shader_node_find_input(fromnode, "Weight");
701 if (fromsock->link) {
702 ntree_weight_tree_merge_weight(ntree, fromnode, fromsock, &tonode, &tosock);
703 }
704 break;
705 default:
706 fromsock = sock.link->fromsock;
707 break;
708 }
709
710 /* Manually add the link to the socket to avoid calling:
711 * `BKE_ntree_update(G.main, oop)`. */
712 fromsock->link = &bke::node_add_link(*ntree, *fromnode, *fromsock, *tonode, *tosock);
713 }
714 }
715 }
716 }
717 /* Restore displacement & thickness link. */
718 if (displace_link) {
719 bke::node_add_link(*ntree,
720 *displace_link->fromnode,
721 *displace_link->fromsock,
722 *output_node,
723 *displace_output);
724 }
725 if (thickness_link) {
726 bke::node_add_link(*ntree,
727 *thickness_link->fromnode,
728 *thickness_link->fromsock,
729 *output_node,
730 *thickness_output);
731 }
733}
734
735static bool closure_node_filter(const bNode *node)
736{
737 switch (node->type_legacy) {
755 case SH_NODE_EMISSION:
756 case SH_NODE_HOLDOUT:
762 return true;
763 default:
764 return false;
765 }
766}
767
768/* Shader to rgba needs their associated closure duplicated and the weight tree generated for. */
770{
771 Vector<bNode *> shader_to_rgba_nodes;
772 for (bNode &node : ntree->nodes) {
773 if (node.type_legacy == SH_NODE_SHADERTORGB) {
774 shader_to_rgba_nodes.append(&node);
775 }
776 }
777
778 for (bNode *shader_to_rgba : shader_to_rgba_nodes) {
779 bNodeSocket *closure_input = ntree_shader_node_input_get(shader_to_rgba, 0);
780 if (closure_input->link == nullptr) {
781 continue;
782 }
783 ntree_shader_copy_branch(ntree, shader_to_rgba, closure_node_filter);
785
786 ntree_shader_weight_tree_invert(ntree, shader_to_rgba);
787 }
788}
789
791 bNode *node_start,
792 int16_t &max_depth)
793{
794 struct StackNode {
795 bNode *node;
796 int16_t depth;
797 };
798
799 Stack<StackNode> stack;
800 Stack<StackNode> zone_stack;
801 stack.push({node_start, 0});
802
803 while (!stack.is_empty() || !zone_stack.is_empty()) {
804 StackNode s_node = !stack.is_empty() ? stack.pop() : zone_stack.pop();
805
806 bNode *node = s_node.node;
807 int16_t depth_level = s_node.depth;
808
809 if (node->runtime->tmp_flag >= depth_level) {
810 /* We already iterated this branch at this or a greater depth. */
811 continue;
812 }
813
814 if (node->type_legacy == SH_NODE_SHADERTORGB) {
815 depth_level++;
816 max_depth = std::max(max_depth, depth_level);
817 }
818
819 node->runtime->tmp_flag = std::max(node->runtime->tmp_flag, depth_level);
820
821 for (bNodeSocket &sock : node->inputs) {
822 bNodeLink *link = sock.link;
823 if (link == nullptr) {
824 continue;
825 }
826 if ((link->flag & NODE_LINK_VALID) == 0) {
827 /* Skip links marked as cyclic. */
828 continue;
829 }
830 stack.push({link->fromnode, depth_level});
831 }
832
833 /* Zone input nodes are linked to their corresponding zone output nodes, even if there is no
834 * bNodeLink between them. */
835 if (const bke::bNodeZoneType *zone_type = bke::zone_type_by_node_type(node->type_legacy)) {
836 if (zone_type->output_type == node->type_legacy) {
837 if (bNode *zone_input_node = zone_type->get_corresponding_input(*ntree, *node)) {
838 zone_stack.push({zone_input_node, depth_level});
839 }
840 }
841 }
842 }
843}
844
846{
848 if (link) {
849 bke::node_remove_link(ntree, *link);
850 }
851}
852
854 bNode *node,
855 int factor_socket_index,
856 int a_socket_index,
857 int b_socket_index,
858 bool clamp_factor)
859{
860 bNodeSocket *factor_socket = ntree_shader_node_input_get(node, factor_socket_index);
861 if (factor_socket->link == nullptr) {
862 float factor = 0.5;
863
864 if (factor_socket->type == SOCK_FLOAT) {
865 factor = factor_socket->default_value_typed<bNodeSocketValueFloat>()->value;
866 if (clamp_factor) {
867 factor = clamp_f(factor, 0.0f, 1.0f);
868 }
869 }
870 else if (factor_socket->type == SOCK_VECTOR) {
871 const float *vfactor = factor_socket->default_value_typed<bNodeSocketValueVector>()->value;
872 float vfactor_copy[3];
873 for (int i = 0; i < 3; i++) {
874 if (clamp_factor) {
875 vfactor_copy[i] = clamp_f(vfactor[i], 0.0f, 1.0f);
876 }
877 else {
878 vfactor_copy[i] = vfactor[i];
879 }
880 }
881 if (vfactor_copy[0] == vfactor_copy[1] && vfactor_copy[0] == vfactor_copy[2]) {
882 factor = vfactor_copy[0];
883 }
884 }
885
886 if (factor == 1.0f && a_socket_index >= 0) {
887 shader_node_disconnect_input(ntree, node, a_socket_index);
888 }
889 else if (factor == 0.0f && b_socket_index >= 0) {
890 shader_node_disconnect_input(ntree, node, b_socket_index);
891 }
892 }
893}
894
896{
897 for (bNode &node : ntree->nodes) {
898 if (node.typeinfo->type_legacy == SH_NODE_MIX_SHADER) {
899 shader_node_disconnect_inactive_mix_branch(ntree, &node, 0, 1, 2, true);
900 }
901 else if (node.typeinfo->type_legacy == SH_NODE_MIX) {
902 const NodeShaderMix *storage = static_cast<NodeShaderMix *>(node.storage);
903 if (storage->data_type == SOCK_FLOAT) {
904 shader_node_disconnect_inactive_mix_branch(ntree, &node, 0, 2, 3, storage->clamp_factor);
905 /* Disconnect links from data_type-specific sockets that are not currently in use */
906 for (int i : {1, 4, 5, 6, 7}) {
908 }
909 }
910 else if (storage->data_type == SOCK_VECTOR) {
911 int factor_socket = storage->factor_mode == NODE_MIX_MODE_UNIFORM ? 0 : 1;
913 ntree, &node, factor_socket, 4, 5, storage->clamp_factor);
914 /* Disconnect links from data_type-specific sockets that are not currently in use */
915 int unused_factor_socket = factor_socket == 0 ? 1 : 0;
916 for (int i : {unused_factor_socket, 2, 3, 6, 7}) {
918 }
919 }
920 else if (storage->data_type == SOCK_RGBA) {
921 /* Branch A can't be optimized-out, since its alpha is always used regardless of factor */
922 shader_node_disconnect_inactive_mix_branch(ntree, &node, 0, -1, 7, storage->clamp_factor);
923 /* Disconnect links from data_type-specific sockets that are not currently in use */
924 for (int i : {1, 2, 3, 4, 5}) {
926 }
927 }
928 }
929 }
930}
931
932static bool ntree_branch_node_tag(bNode *fromnode, bNode *tonode, void * /*userdata*/)
933{
934 fromnode->runtime->tmp_flag = 1;
935 tonode->runtime->tmp_flag = 1;
936 return true;
937}
938
939/* Avoid adding more node execution when multiple outputs are present. */
940/* NOTE(@fclem): This is also a workaround for the old EEVEE SSS implementation where only the
941 * first executed SSS node gets a SSS profile. */
942static void ntree_shader_pruned_unused(bNodeTree *ntree, bNode *output_node)
943{
945
946 bool changed = false;
947
948 for (bNode &node : ntree->nodes) {
949 node.runtime->tmp_flag = 0;
950 }
951
952 /* Avoid deleting the output node if it is the only node in the tree. */
953 if (output_node) {
954 output_node->runtime->tmp_flag = 1;
955 bke::node_chain_iterator_backwards(ntree, output_node, ntree_branch_node_tag, nullptr, 0);
956 }
957
958 for (bNode &node : ntree->nodes) {
959 if (node.type_legacy == SH_NODE_OUTPUT_AOV) {
960 node.runtime->tmp_flag = 1;
962 }
963 }
964
965 for (bNode &node : ntree->nodes.items_mutable()) {
966 if (node.runtime->tmp_flag == 0) {
969 changed = true;
970 }
971 }
972
973 if (changed) {
975 }
976}
977
979{
980 /* Safeguard to not emit a LIGHT_ITER_INTERNAL_INPUT without a LIGHT_ITER_INTERNAL_OUTPUT raising
981 * an assert in the shader dead code optimization. */
982 bool has_light_accumulation = false;
983 for (bNode &node : ntree->nodes) {
984 if (node.type_legacy == SH_NODE_LIGHT_ACCUMULATION) {
985 has_light_accumulation = true;
986 break;
987 }
988 }
989
990 if (!has_light_accumulation) {
991 return;
992 }
993
994 bNode *zone_input = nullptr;
995 bNode *zone_output = nullptr;
996
997 auto ensure_nodes = [&]() {
998 if (!zone_input) {
1000 zone_output = bke::node_add_static_node(nullptr, *ntree, SH_NODE_LIGHT_ITER_INTERNAL_OUTPUT);
1001 zone_input->custom3 = *reinterpret_cast<float *>(&zone_output->identifier);
1002 }
1003 };
1004
1005 Map<bNodeSocket *, bNodeSocket *> accumulation_out_to_zone_out;
1006
1007 for (bNode &node : ntree->nodes) {
1008 if (ELEM(node.type_legacy,
1013 (node.type_legacy == SH_NODE_ATTRIBUTE &&
1014 static_cast<NodeShaderAttribute *>(node.storage)->type == SHD_ATTRIBUTE_LIGHT) ||
1015 (node.type_legacy == SH_NODE_VECT_TRANSFORM &&
1017 static_cast<NodeShaderVectTransform *>(node.storage)->convert_from,
1018 static_cast<NodeShaderVectTransform *>(node.storage)->convert_to)))
1019 {
1020 ensure_nodes();
1021 /* Connect LightIndex socket */
1022 bke::node_add_link(*ntree,
1023 *zone_input,
1024 *ntree_shader_node_output_get(zone_input, 0),
1025 node,
1027
1028 if (node.type_legacy == SH_NODE_LIGHT_ACCUMULATION) {
1029 /* Connect accumulation result to the zone output node.
1030 * Create one zone IO for each Light Accumulation node. */
1032 *ntree, *zone_input, SOCK_IN, SOCK_SHADER, PROP_NONE, "ShaderZoneIO", "ShaderZoneIO");
1034 *ntree, *zone_input, SOCK_OUT, SOCK_SHADER, PROP_NONE, "ShaderZoneIO", "ShaderZoneIO");
1036 *ntree, *zone_output, SOCK_IN, SOCK_SHADER, PROP_NONE, "ShaderZoneIO", "ShaderZoneIO");
1037 bNodeSocket *socket_out = bke::node_add_static_socket(*ntree,
1038 *zone_output,
1039 SOCK_OUT,
1041 PROP_NONE,
1042 "ShaderZoneIO",
1043 "ShaderZoneIO");
1044
1045 bNodeSocket &accumulation_out = *ntree_shader_node_output_get(&node, 0);
1046 bke::node_add_link(*ntree, node, accumulation_out, *zone_output, *socket_in);
1047 accumulation_out_to_zone_out.add(&accumulation_out, socket_out);
1048 }
1049 }
1050 }
1051
1052 Vector<bNodeLink *> links_to_remove;
1053 for (bNodeLink &link : ntree->links) {
1056 {
1057 bke::node_add_link(*ntree,
1058 *zone_output,
1059 *accumulation_out_to_zone_out.lookup(link.fromsock),
1060 *link.tonode,
1061 *link.tosock);
1062 links_to_remove.append(&link);
1063 }
1064 }
1065
1066 for (bNodeLink *link : links_to_remove) {
1067 bke::node_remove_link(ntree, *link);
1068 }
1069}
1070
1072{
1073 bNodeTreeExec *exec;
1074
1077
1078 /* Tree is valid if it contains no undefined implicit socket type cast. */
1079 bool valid_tree = ntree_shader_implicit_closure_cast(localtree);
1080
1081 if (valid_tree) {
1083 if (output != nullptr) {
1087 }
1088 }
1089
1090 exec = ntreeShaderBeginExecTree(localtree);
1091 /* Execute nodes ordered by the number of ShaderToRGB nodes found in their path,
1092 * so all closures can be properly evaluated. */
1093 int16_t max_depth = 0;
1094 for (bNode &node : localtree->nodes) {
1095 node.runtime->tmp_flag = -1;
1096 }
1097 if (output != nullptr) {
1098 iter_shader_to_rgba_depth_count(localtree, output, max_depth);
1099 }
1100 for (bNode &node : localtree->nodes) {
1101 if (node.type_legacy == SH_NODE_OUTPUT_AOV) {
1102 iter_shader_to_rgba_depth_count(localtree, &node, max_depth);
1103 }
1104 }
1105 for (int depth = max_depth; depth >= 0; depth--) {
1106 ntreeExecGPUNodes(exec, mat, output, &depth);
1107 for (bNode &node : localtree->nodes) {
1108 if (node.type_legacy == SH_NODE_OUTPUT_AOV) {
1109 ntreeExecGPUNodes(exec, mat, &node, &depth);
1110 }
1111 }
1112 }
1114}
1115
1117 bNodeTree *ntree,
1118 bNodeInstanceKey parent_key)
1119{
1120 /* ensures only a single output node is enabled */
1122
1123 /* common base initialization */
1124 bNodeTreeExec *exec = ntree_exec_begin(context, ntree, parent_key);
1125
1126 /* allocate the thread stack listbase array */
1128 "thread stack array");
1129
1130 for (bNode &node : exec->nodetree->nodes) {
1131 node.runtime->need_exec = 1;
1132 }
1133
1134 return exec;
1135}
1136
1138{
1139 bNodeExecContext context;
1140 bNodeTreeExec *exec;
1141
1142 /* XXX hack: prevent exec data from being generated twice.
1143 * this should be handled by the renderer!
1144 */
1145 if (ntree->runtime->execdata) {
1146 return ntree->runtime->execdata;
1147 }
1148
1150
1151 /* XXX: this should not be necessary, but is still used for compositor/shader/texture nodes,
1152 * which only store the `ntree` pointer. Should be fixed at some point!
1153 */
1154 ntree->runtime->execdata = exec;
1155
1156 return exec;
1157}
1158
1160{
1161 if (exec->threadstack) {
1162 for (int a = 0; a < BLENDER_MAX_THREADS; a++) {
1163 for (bNodeThreadStack &nts : exec->threadstack[a]) {
1164 if (nts.stack) {
1165 MEM_delete(nts.stack);
1166 }
1167 }
1168 BLI_freelistN(&exec->threadstack[a]);
1169 }
1170
1171 MEM_delete(exec->threadstack);
1172 exec->threadstack = nullptr;
1173 }
1174
1175 ntree_exec_end(exec);
1176}
1177
1179{
1180 if (exec) {
1181 /* exec may get freed, so assign ntree */
1182 bNodeTree *ntree = exec->nodetree;
1184
1185 /* XXX: clear node-tree back-pointer to exec data,
1186 * same problem as noted in #ntreeBeginExecTree. */
1187 ntree->runtime->execdata = nullptr;
1188 }
1189}
1190
1191} // namespace blender
Blender kernel freestyle line style functionality.
General operations, lookup, etc. for materials.
#define NODE_CLASS_OUTPUT
Definition BKE_node.hh:479
#define NODE_CLASS_INTERFACE
Definition BKE_node.hh:490
#define NODE_CLASS_CONVERTER
Definition BKE_node.hh:484
#define NODE_CLASS_OP_VECTOR
Definition BKE_node.hh:481
#define NODE_CLASS_LAYOUT
Definition BKE_node.hh:494
#define NODE_CLASS_OP_COLOR
Definition BKE_node.hh:480
#define NODE_CLASS_INPUT
Definition BKE_node.hh:478
#define NODE_CLASS_GROUP
Definition BKE_node.hh:483
#define NODE_CLASS_TEXTURE
Definition BKE_node.hh:488
#define NODE_CLASS_SHADER
Definition BKE_node.hh:491
#define NODE_CLASS_SCRIPT
Definition BKE_node.hh:489
#define SH_NODE_LIGHT_ITER_INTERNAL_OUTPUT
#define SH_NODE_MIX_SHADER
#define SH_NODE_LIGHT_ACCUMULATION
#define SH_NODE_BSDF_METALLIC
#define SH_NODE_HOLDOUT
#define SH_NODE_LIGHT_EVALUATION
#define SH_NODE_VOLUME_COEFFICIENTS
#define SH_NODE_OUTPUT_WORLD
#define SH_NODE_SHADOW_RAYCAST
#define SH_NODE_BSDF_PRINCIPLED
#define SH_NODE_EMISSION
#define SH_NODE_BSDF_SHEEN
#define SH_NODE_ADD_SHADER
#define SH_NODE_SUBSURFACE_SCATTERING
#define SH_NODE_VOLUME_ABSORPTION
#define SH_NODE_LIGHT_INFO
#define SH_NODE_VALUE
#define SH_NODE_MATH
#define SH_NODE_BSDF_TOON
#define SH_NODE_BSDF_TRANSPARENT
#define SH_NODE_BSDF_DIFFUSE
#define SH_NODE_VECT_TRANSFORM
#define SH_NODE_SHADERTORGB
#define SH_NODE_OUTPUT_MATERIAL
#define SH_NODE_BSDF_TRANSLUCENT
#define SH_NODE_BSDF_HAIR_PRINCIPLED
#define SH_NODE_BSDF_HAIR
#define SH_NODE_BACKGROUND
#define SH_NODE_BSDF_RAY_PORTAL
#define SH_NODE_BSDF_GLOSSY
#define SH_NODE_MIX
#define SH_NODE_EEVEE_SPECULAR
#define SH_NODE_BSDF_GLASS
#define SH_NODE_LIGHT_ITER_INTERNAL_INPUT
#define SH_NODE_VOLUME_PRINCIPLED
#define SH_NODE_BSDF_REFRACTION
#define SH_NODE_OUTPUT_LIGHT
#define SH_NODE_VOLUME_SCATTER
#define SH_NODE_OUTPUT_AOV
#define SH_NODE_SCRIPT
#define SH_NODE_ATTRIBUTE
#define BLENDER_MAX_THREADS
#define C
Definition RandGen.cpp:29
#define ELEM(...)
#define STREQ(a, b)
#define output
bool add(const Key &key, const Value &value)
Definition BLI_map.hh:295
const Value & lookup(const Key &key) const
Definition BLI_map.hh:545
bool contains(const Key &key) const
Definition BLI_set.hh:310
bool add(const Key &key)
Definition BLI_set.hh:248
bool is_empty() const
Definition BLI_stack.hh:310
void push(const T &value)
Definition BLI_stack.hh:215
void append(const T &value)
#define storage(slot, qualifiers)
void node_chain_iterator_backwards(const bNodeTree *ntree, bNode *node_start, bool(*callback)(bNode *, bNode *, void *), void *userdata, int recursion_lvl)
Definition node.cc:4206
void node_tree_free_local_node(bNodeTree &ntree, bNode &node)
Definition node.cc:5141
void node_tree_set_output(bNodeTree &ntree)
Definition node.cc:5238
const bNodeZoneType * zone_type_by_node_type(const int node_type)
void node_unlink_node(bNodeTree &ntree, bNode &node)
Definition node.cc:5026
void node_tree_free_tree(bNodeTree &ntree)
Definition node.cc:5224
void node_remove_link(bNodeTree *ntree, bNodeLink &link)
Definition node.cc:4676
void node_tree_type_add(bNodeTreeType &nt)
Definition node.cc:2844
void node_internal_relink(bNodeTree &ntree, bNode &node)
Definition node.cc:4812
const bNodeInstanceKey NODE_INSTANCE_KEY_BASE
Definition node.cc:5600
void node_free_node(bNodeTree *tree, bNode &node)
Definition node.cc:5073
void(*)(void *calldata, int nclass, StringRefNull name) bNodeClassCallback
Definition BKE_node.hh:523
bNode * node_add_static_node(const bContext *C, bNodeTree &ntree, int type)
Definition node.cc:4283
bNodeLink & node_add_link(bNodeTree &ntree, bNode &fromnode, bNodeSocket &fromsock, bNode &tonode, bNodeSocket &tosock)
Definition node.cc:4638
bNodeSocket * node_add_static_socket(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out, int type, int subtype, StringRefNull identifier, StringRefNull name)
Definition node.cc:3980
bNode * node_copy_with_mapping(bNodeTree *dst_tree, const bNode &node_src, int flag, std::optional< StringRefNull > dst_unique_name, std::optional< int > dst_unique_identifier, Map< const bNodeSocket *, bNodeSocket * > &new_socket_map, bool allow_duplicate_names=false)
Definition node.cc:4327
bool node_is_static_socket_type(const bNodeSocketType &stype)
Definition node.cc:3483
BMesh Iterators.
static bNodeSocket * ntree_shader_node_output_get(bNode *node, int n)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
static void ntree_weight_tree_merge_weight(bNodeTree *ntree, bNode *, bNodeSocket *fromsock, bNode **tonode, bNodeSocket **tosock)
struct bNode * ntreeShaderOutputNode(struct bNodeTree *ntree, int target)
@ SNODE_SHADER_LINESTYLE
Object * BKE_view_layer_active_object_get(const ViewLayer *view_layer)
static bool ntree_weight_tree_tag_nodes(bNode *fromnode, bNode *tonode, void *userdata)
static void shader_node_disconnect_input(bNodeTree *ntree, bNode *node, int index)
Material * BKE_object_material_get(Object *ob, short act)
static void localize(bNodeTree *localtree, bNodeTree *)
@ SHD_ATTRIBUTE_LIGHT
static bool shader_node_tree_socket_type_valid(bke::bNodeTreeType *, bke::bNodeSocketType *socket_type)
static bool ntree_shader_implicit_closure_cast(bNodeTree *ntree)
static void ntree_shader_weight_tree_invert(bNodeTree *ntree, bNode *output_node)
const char * RE_engine_id_CYCLES
Definition scene.cc:1720
void ntreeGPUMaterialNodes(struct bNodeTree *localtree, struct GPUMaterial *mat)
static bool shader_tree_poll(const bContext *C, bke::bNodeTreeType *)
bool BKE_scene_use_shading_nodes_custom(Scene *scene)
Definition scene.cc:3065
@ LIB_ID_CREATE_NO_USER_REFCOUNT
@ LIB_ID_CREATE_NO_MAIN
ViewLayer * CTX_data_view_layer(const bContext *C)
static bool ntree_branch_count_and_tag_nodes(bNode *fromnode, bNode *tonode, void *userdata)
void ntree_exec_end(bNodeTreeExec *exec)
Definition node_exec.cc:285
static void ntree_shader_disconnect_inactive_mix_branches(bNodeTree *ntree)
void * BLI_findlink(const ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:541
void void BLI_freelistN(ListBase *listbase) ATTR_NONNULL(1)
Definition listbase.cc:504
static void ntree_shader_shader_to_rgba_branches(bNodeTree *ntree)
static void ntree_shader_setup_custom_lighting_zone(bNodeTree *ntree)
static void shader_node_disconnect_inactive_mix_branch(bNodeTree *ntree, bNode *node, int factor_socket_index, int a_socket_index, int b_socket_index, bool clamp_factor)
struct bNodeTreeExec * ntreeShaderBeginExecTree(struct bNodeTree *ntree)
bool BKE_view_layer_synced_ensure(const Main &bmain, const Scene *scene, ViewLayer *view_layer)
SpaceNode * CTX_wm_space_node(const bContext *C)
static void iter_shader_to_rgba_depth_count(bNodeTree *ntree, bNode *node_start, int16_t &max_depth)
static void ntree_shader_pruned_unused(bNodeTree *ntree, bNode *output_node)
bNodeTreeExec * ntree_exec_begin(bNodeExecContext *context, bNodeTree *ntree, bNodeInstanceKey parent_key)
Definition node_exec.cc:192
void ntreeShaderEndExecTree_internal(bNodeTreeExec *exec)
bNodeTreeExec * ntreeShaderBeginExecTree_internal(bNodeExecContext *context, bNodeTree *ntree, bNodeInstanceKey parent_key)
static void shader_get_from_context(const bContext *C, bke::bNodeTreeType *, bNodeTree **r_ntree, ID **r_id, ID **r_from)
void BKE_ntree_update_without_main(bNodeTree &tree)
static bool ntree_branch_node_tag(bNode *fromnode, bNode *tonode, void *)
static void update(bNodeTree *ntree)
@ SHD_VECT_TRANSFORM_SPACE_LIGHT
struct bke::bNodeTreeType * ntreeType_Shader
static void ntree_shader_unlink_script_nodes(bNodeTree *ntree)
static bNodeSocket * ntree_shader_node_find_input(bNode *node, const char *identifier)
static bool shader_validate_link(eNodeSocketDatatype from, eNodeSocketDatatype to)
Main * CTX_data_main(const bContext *C)
static bNodeSocket * ntree_shader_node_input_get(bNode *node, int n)
@ NODE_MIX_MODE_UNIFORM
void ntree_update_reroute_nodes(bNodeTree *ntree)
static void ntree_shader_copy_branch(bNodeTree *ntree, bNode *start_node, bool(*node_filter)(const bNode *node))
void register_node_tree_type_sh()
FreestyleLineStyle * BKE_linestyle_active_from_view_layer(struct ViewLayer *view_layer)
Definition linestyle.cc:773
static bNodeSocket * ntree_shader_node_find_socket(ListBaseT< bNodeSocket > *sockets, const char *identifier)
Scene * CTX_data_scene(const bContext *C)
void ntreeShaderEndExecTree(struct bNodeTreeExec *exec)
static bool closure_node_filter(const bNode *node)
static void foreach_nodeclass(void *calldata, bke::bNodeClassCallback func)
void ntreeExecGPUNodes(bNodeTreeExec *exec, GPUMaterial *mat, bNode *output_node, const int *depth_level)
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
signed short int16_t
Definition BKE_text.h:77
MINLINE float clamp_f(float value, float min, float max)
static bNodeSocket * ntree_shader_node_find_output(bNode *node, const char *identifier)
struct World * world
struct RenderData r
eSpaceNode_ShaderFrom shaderfrom
bke::motionpath::Runtime * runtime
eNodeSocketDatatype type
struct bNodeLink * link
ListBaseT< bNodeThreadStack > * threadstack
Definition node_exec.hh:44
ListBaseT< bNodeLink > links
bke::bNodeTreeRuntime * runtime
ListBaseT< bNode > nodes
bke::bNodeRuntime * runtime
Defines a socket type.
Definition BKE_node.hh:163
eNodeSocketDatatype type
Definition BKE_node.hh:198
bool(*) valid_socket_type(bNodeTreeType *ntreetype, bNodeSocketType *socket_type)
Definition BKE_node.hh:569
void(*) get_from_context(const bContext *C, bNodeTreeType *ntreetype, bNodeTree **r_ntree, ID **r_id, ID **r_from)
Definition BKE_node.hh:554
void(*) update(bNodeTree *ntree)
Definition BKE_node.hh:564
void(*) foreach_nodeclass(void *calldata, bNodeClassCallback func)
Definition BKE_node.hh:550
void(*) localize(bNodeTree *localtree, bNodeTree *ntree)
Definition BKE_node.hh:561
std::optional< std::string > asset_catalog_path_prefix
Definition BKE_node.hh:546
bool(*) validate_link(eNodeSocketDatatype from, eNodeSocketDatatype to)
Definition BKE_node.hh:566
bool(*) poll(const bContext *C, bNodeTreeType *ntreetype)
Definition BKE_node.hh:552
bool(*) node_filter(const bNode *node)
#define N_(msgid)