Blender V5.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
8
9#include "node_shader_util.hh"
10
11namespace blender {
12
14
16{
17 b.add_input<decl::Float>("Factor"_ustr, "Fac"_ustr)
18 .default_value(0.5f)
19 .min(0.0f)
20 .max(1.0f)
22 .description(
23 "Blend weight to use for mixing two shaders. "
24 "At zero it uses the first shader entirely and at one the second shader");
25 b.add_input<decl::Shader>("Shader"_ustr);
26 b.add_input<decl::Shader>("Shader"_ustr, "Shader_001"_ustr);
27 b.add_output<decl::Shader>("Shader"_ustr);
28}
29
31 bNode *node,
32 bNodeExecData * /*execdata*/,
35{
36 return GPU_stack_link(mat, node, "node_mix_shader", in, out);
37}
38
40#ifdef WITH_MATERIALX
41{
42 if (!ELEM(to_type_, NodeItem::Type::BSDF, NodeItem::Type::EDF, NodeItem::Type::SurfaceOpacity)) {
43 return empty();
44 }
45
46 NodeItem shader1 = get_input_link(1, to_type_);
47 NodeItem shader2 = get_input_link(2, to_type_);
48 if (!shader1 && !shader2) {
49 return empty();
50 }
51
52 /* Cycles and EEVEE clamp the factor, match that here. */
53 NodeItem fac = get_input_value(0, NodeItem::Type::Float).clamp();
54
55 if (shader1 && !shader2) {
56 return shader1 * (val(1.0f) - fac);
57 }
58 if (!shader1 && shader2) {
59 return shader2 * fac;
60 }
61 return fac.mix(shader1, shader2);
62}
63#endif
65
66} // namespace nodes::node_shader_mix_shader_cc
67
68/* node type definition */
70{
71 namespace file_ns = nodes::node_shader_mix_shader_cc;
72
73 static bke::bNodeType ntype;
74
75 sh_node_type_base(&ntype, "ShaderNodeMixShader"_ustr, SH_NODE_MIX_SHADER);
76 ntype.ui_name = "Mix Shader";
77 ntype.ui_description = "Mix two shaders together. Typically used for material layering";
78 ntype.enum_name_legacy = "MIX_SHADER";
80 ntype.declare = file_ns::node_declare;
81 ntype.gpu_fn = file_ns::node_shader_gpu_mix_shader;
82 ntype.materialx_fn = file_ns::node_shader_materialx;
83
85}
86
87} // namespace blender
#define NODE_CLASS_SHADER
Definition BKE_node.hh:491
#define SH_NODE_MIX_SHADER
#define ELEM(...)
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
static void node_declare(NodeDeclarationBuilder &b)
static int node_shader_gpu_mix_shader(GPUMaterial *mat, bNode *node, bNodeExecData *, GPUNodeStack *in, GPUNodeStack *out)
BMesh Iterators.
void register_node_type_sh_mix_shader()
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
void sh_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
@ PROP_FACTOR
Definition RNA_types.hh:308
#define NODE_SHADER_MATERIALX_BEGIN
#define NODE_SHADER_MATERIALX_END
Defines a node type.
Definition BKE_node.hh:265
NodeMaterialXFunction materialx_fn
Definition BKE_node.hh:375
std::string ui_description
Definition BKE_node.hh:271
NodeGPUExecFunction gpu_fn
Definition BKE_node.hh:373
const char * enum_name_legacy
Definition BKE_node.hh:274
NodeDeclareFunction declare
Definition BKE_node.hh:393