Blender V4.3
node_shader_add_shader.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2005 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "node_shader_util.hh"
6
8
10{
11 b.add_input<decl::Shader>("Shader");
12 b.add_input<decl::Shader>("Shader", "Shader_001");
13 b.add_output<decl::Shader>("Shader");
14}
15
17 bNode *node,
18 bNodeExecData * /*execdata*/,
19 GPUNodeStack *in,
20 GPUNodeStack *out)
21{
22 return GPU_stack_link(mat, node, "node_add_shader", in, out);
23}
24
26#ifdef WITH_MATERIALX
27{
28 if (!ELEM(to_type_, NodeItem::Type::BSDF, NodeItem::Type::EDF, NodeItem::Type::SurfaceOpacity)) {
29 return empty();
30 }
31
32 NodeItem shader1 = get_input_link(0, to_type_);
33 NodeItem shader2 = get_input_link(1, to_type_);
34 if (!shader1 && !shader2) {
35 return empty();
36 }
37
38 if (shader1 && !shader2) {
39 return shader1;
40 }
41 if (!shader1 && shader2) {
42 return shader2;
43 }
44 if (to_type_ == NodeItem::Type::SurfaceOpacity) {
45 return (shader1 + shader2) * val(0.5f);
46 }
47 return shader1 + shader2;
48}
49#endif
51
52} // namespace blender::nodes::node_shader_add_shader_cc
53
54/* node type definition */
56{
58
59 static blender::bke::bNodeType ntype;
60
61 sh_node_type_base(&ntype, SH_NODE_ADD_SHADER, "Add Shader", NODE_CLASS_SHADER);
62 ntype.declare = file_ns::node_declare;
63 ntype.gpu_fn = file_ns::node_shader_gpu_add_shader;
64 ntype.materialx_fn = file_ns::node_shader_materialx;
65
67}
#define NODE_CLASS_SHADER
Definition BKE_node.hh:417
#define ELEM(...)
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
local_group_size(16, 16) .push_constant(Type b
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
static int node_shader_gpu_add_shader(GPUMaterial *mat, bNode *node, bNodeExecData *, GPUNodeStack *in, GPUNodeStack *out)
static void node_declare(NodeDeclarationBuilder &b)
#define NODE_SHADER_MATERIALX_BEGIN
#define NODE_SHADER_MATERIALX_END
void register_node_type_sh_add_shader()
void sh_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
Defines a node type.
Definition BKE_node.hh:218
NodeMaterialXFunction materialx_fn
Definition BKE_node.hh:320
NodeGPUExecFunction gpu_fn
Definition BKE_node.hh:318
NodeDeclareFunction declare
Definition BKE_node.hh:347