Blender  V3.3
node_shader_common.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2006 Blender Foundation. All rights reserved. */
3 
8 #include "DNA_node_types.h"
9 
10 #include "BLI_utildefines.h"
11 
12 #include "BKE_node.h"
13 
14 #include "NOD_common.h"
15 #include "node_common.h"
16 #include "node_exec.h"
17 #include "node_shader_util.hh"
18 
19 #include "RNA_access.h"
20 
21 /**** GROUP ****/
22 
23 static void group_gpu_copy_inputs(bNode *gnode, GPUNodeStack *in, bNodeStack *gstack)
24 {
25  bNodeTree *ngroup = (bNodeTree *)gnode->id;
26 
27  LISTBASE_FOREACH (bNode *, node, &ngroup->nodes) {
28  if (node->type == NODE_GROUP_INPUT) {
29  int a;
30  LISTBASE_FOREACH_INDEX (bNodeSocket *, sock, &node->outputs, a) {
31  bNodeStack *ns = node_get_socket_stack(gstack, sock);
32  if (ns) {
33  /* convert the external gpu stack back to internal node stack data */
34  node_data_from_gpu_stack(ns, &in[a]);
35  }
36  }
37  }
38  }
39 }
40 
41 /* Copy internal results to the external outputs.
42  */
43 static void group_gpu_move_outputs(bNode *gnode, GPUNodeStack *out, bNodeStack *gstack)
44 {
45  bNodeTree *ngroup = (bNodeTree *)gnode->id;
46 
47  LISTBASE_FOREACH (bNode *, node, &ngroup->nodes) {
48  if (node->type == NODE_GROUP_OUTPUT && (node->flag & NODE_DO_OUTPUT)) {
49  int a;
50  LISTBASE_FOREACH_INDEX (bNodeSocket *, sock, &node->inputs, a) {
51  bNodeStack *ns = node_get_socket_stack(gstack, sock);
52  if (ns) {
53  /* convert the node stack data result back to gpu stack */
54  node_gpu_stack_from_data(&out[a], sock->type, ns);
55  }
56  }
57  break; /* only one active output node */
58  }
59  }
60 }
61 
62 static int gpu_group_execute(
64 {
65  bNodeTreeExec *exec = static_cast<bNodeTreeExec *>(execdata->data);
66 
67  if (!node->id) {
68  return 0;
69  }
70 
71  group_gpu_copy_inputs(node, in, exec->stack);
72  ntreeExecGPUNodes(exec, mat, nullptr);
74 
75  return 1;
76 }
77 
79 {
80  static bNodeType ntype;
81 
82  /* NOTE: cannot use #sh_node_type_base for node group, because it would map the node type
83  * to the shared #NODE_GROUP integer type id. */
84 
85  node_type_base_custom(&ntype, "ShaderNodeGroup", "Group", NODE_CLASS_GROUP);
86  ntype.type = NODE_GROUP;
87  ntype.poll = sh_node_poll_default;
90  ntype.rna_ext.srna = RNA_struct_find("ShaderNodeGroup");
91  BLI_assert(ntype.rna_ext.srna != nullptr);
93 
94  node_type_size(&ntype, 140, 60, 400);
98 
99  nodeRegisterType(&ntype);
100 }
101 
103 {
104  /* These methods can be overridden but need a default implementation otherwise. */
105  if (ntype->poll == nullptr) {
106  ntype->poll = sh_node_poll_default;
107  }
108  if (ntype->insert_link == nullptr) {
110  }
111 
113 }
void node_type_gpu(struct bNodeType *ntype, NodeGPUExecFunction gpu_fn)
Definition: node.cc:4465
void node_type_base_custom(struct bNodeType *ntype, const char *idname, const char *name, short nclass)
Definition: node.cc:4311
void node_type_size(struct bNodeType *ntype, int width, int minwidth, int maxwidth)
Definition: node.cc:4396
void node_type_group_update(struct bNodeType *ntype, void(*group_update_func)(struct bNodeTree *ntree, struct bNode *node))
Definition: node.cc:4449
#define NODE_CLASS_GROUP
Definition: BKE_node.h:350
#define NODE_GROUP_INPUT
Definition: BKE_node.h:987
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1357
#define BLI_assert(a)
Definition: BLI_assert.h:46
#define LISTBASE_FOREACH(type, var, list)
Definition: BLI_listbase.h:336
#define LISTBASE_FOREACH_INDEX(type, var, list, index_var)
Definition: BLI_listbase.h:344
#define NODE_DO_OUTPUT
NODE_GROUP_OUTPUT
NODE_GROUP
OperationNode * node
static unsigned a[3]
Definition: RandGen.cpp:78
static const pxr::TfToken out("out", pxr::TfToken::Immortal)
void node_group_update(struct bNodeTree *ntree, struct bNode *node)
Definition: node_common.cc:213
bool node_group_poll_instance(bNode *node, bNodeTree *nodetree, const char **disabled_hint)
Definition: node_common.cc:71
void node_group_label(const bNodeTree *UNUSED(ntree), const bNode *node, char *label, int maxlen)
Definition: node_common.cc:66
bNodeStack * node_get_socket_stack(bNodeStack *stack, bNodeSocket *sock)
Definition: node_exec.cc:28
static int gpu_group_execute(GPUMaterial *mat, bNode *node, bNodeExecData *execdata, GPUNodeStack *in, GPUNodeStack *out)
void register_node_type_sh_group()
static void group_gpu_copy_inputs(bNode *gnode, GPUNodeStack *in, bNodeStack *gstack)
static void group_gpu_move_outputs(bNode *gnode, GPUNodeStack *out, bNodeStack *gstack)
void register_node_type_sh_custom_group(bNodeType *ntype)
bool sh_node_poll_default(bNodeType *UNUSED(ntype), bNodeTree *ntree, const char **r_disabled_hint)
void node_data_from_gpu_stack(bNodeStack *ns, GPUNodeStack *gs)
void ntreeExecGPUNodes(bNodeTreeExec *exec, GPUMaterial *mat, bNode *output_node)
void node_gpu_stack_from_data(struct GPUNodeStack *gs, int type, bNodeStack *ns)
static void exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out)
void node_insert_link_default(bNodeTree *ntree, bNode *node, bNodeLink *link)
Definition: node_util.c:326
void RNA_struct_blender_type_set(StructRNA *srna, void *blender_type)
Definition: rna_access.c:902
StructRNA * RNA_struct_find(const char *identifier)
Definition: rna_access.c:581
StructRNA * srna
Definition: RNA_types.h:766
ListBase nodes
Defines a node type.
Definition: BKE_node.h:226
bool(* poll)(struct bNodeType *ntype, struct bNodeTree *nodetree, const char **r_disabled_hint)
Definition: BKE_node.h:292
ExtensionRNA rna_ext
Definition: BKE_node.h:341
int type
Definition: BKE_node.h:228
void(* insert_link)(struct bNodeTree *ntree, struct bNode *node, struct bNodeLink *link)
Definition: BKE_node.h:301
void(* labelfunc)(const struct bNodeTree *ntree, const struct bNode *node, char *label, int maxlen)
Definition: BKE_node.h:256
bool(* poll_instance)(struct bNode *node, struct bNodeTree *nodetree, const char **r_disabled_hint)
Definition: BKE_node.h:296
struct ID * id