Blender V4.3
node_shader_mix_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::Float>("Fac")
12 .default_value(0.5f)
13 .min(0.0f)
14 .max(1.0f)
16 .description(
17 "Blend weight to use for mixing two shaders. "
18 "At zero it uses the first shader entirely and at one the second shader");
19 b.add_input<decl::Shader>("Shader");
20 b.add_input<decl::Shader>("Shader", "Shader_001");
21 b.add_output<decl::Shader>("Shader");
22}
23
25 bNode *node,
26 bNodeExecData * /*execdata*/,
27 GPUNodeStack *in,
28 GPUNodeStack *out)
29{
30 return GPU_stack_link(mat, node, "node_mix_shader", in, out);
31}
32
34#ifdef WITH_MATERIALX
35{
36 if (!ELEM(to_type_, NodeItem::Type::BSDF, NodeItem::Type::EDF, NodeItem::Type::SurfaceOpacity)) {
37 return empty();
38 }
39
40 NodeItem shader1 = get_input_link(1, to_type_);
41 NodeItem shader2 = get_input_link(2, to_type_);
42 if (!shader1 && !shader2) {
43 return empty();
44 }
45
46 NodeItem fac = get_input_value(0, NodeItem::Type::Float);
47
48 if (shader1 && !shader2) {
49 return shader1 * (val(1.0f) - fac);
50 }
51 if (!shader1 && shader2) {
52 return shader2 * fac;
53 }
54 return fac.mix(shader1, shader2);
55}
56#endif
58
59} // namespace blender::nodes::node_shader_mix_shader_cc
60
61/* node type definition */
63{
65
66 static blender::bke::bNodeType ntype;
67
68 sh_node_type_base(&ntype, SH_NODE_MIX_SHADER, "Mix Shader", NODE_CLASS_SHADER);
69 ntype.declare = file_ns::node_declare;
70 ntype.gpu_fn = file_ns::node_shader_gpu_mix_shader;
71 ntype.materialx_fn = file_ns::node_shader_materialx;
72
74}
#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,...)
@ PROP_FACTOR
Definition RNA_types.hh:154
local_group_size(16, 16) .push_constant(Type b
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
static void node_declare(NodeDeclarationBuilder &b)
static int node_shader_gpu_mix_shader(GPUMaterial *mat, bNode *node, bNodeExecData *, GPUNodeStack *in, GPUNodeStack *out)
#define NODE_SHADER_MATERIALX_BEGIN
#define NODE_SHADER_MATERIALX_END
void register_node_type_sh_mix_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