Blender V5.0
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>("Factor", "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*/,
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, "ShaderNodeMixShader", SH_NODE_MIX_SHADER);
69 ntype.ui_name = "Mix Shader";
70 ntype.ui_description = "Mix two shaders together. Typically used for material layering";
71 ntype.enum_name_legacy = "MIX_SHADER";
73 ntype.declare = file_ns::node_declare;
74 ntype.gpu_fn = file_ns::node_shader_gpu_mix_shader;
75 ntype.materialx_fn = file_ns::node_shader_materialx;
76
78}
#define NODE_CLASS_SHADER
Definition BKE_node.hh:460
#define SH_NODE_MIX_SHADER
#define ELEM(...)
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
@ PROP_FACTOR
Definition RNA_types.hh:251
#define in
#define out
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
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, std::string idname, const std::optional< int16_t > legacy_type)
Defines a node type.
Definition BKE_node.hh:238
NodeMaterialXFunction materialx_fn
Definition BKE_node.hh:344
std::string ui_description
Definition BKE_node.hh:244
NodeGPUExecFunction gpu_fn
Definition BKE_node.hh:342
const char * enum_name_legacy
Definition BKE_node.hh:247
NodeDeclareFunction declare
Definition BKE_node.hh:362