Blender V5.0
node_shader_bsdf_diffuse.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::Color>("Color").default_value({0.8f, 0.8f, 0.8f, 1.0f});
12 b.add_input<decl::Float>("Roughness")
13 .default_value(0.0f)
14 .min(0.0f)
15 .max(1.0f)
17 b.add_input<decl::Vector>("Normal").hide_value();
18 b.add_input<decl::Float>("Weight").available(false);
19 b.add_output<decl::Shader>("BSDF");
20}
21
23 bNode *node,
24 bNodeExecData * /*execdata*/,
27{
28 if (!in[2].link) {
29 GPU_link(mat, "world_normals_get", &in[2].link);
30 }
31
33
34 return GPU_stack_link(mat, node, "node_bsdf_diffuse", in, out);
35}
36
38#ifdef WITH_MATERIALX
39{
40 if (to_type_ != NodeItem::Type::BSDF) {
41 return empty();
42 }
43
44 NodeItem color = get_input_value("Color", NodeItem::Type::Color3);
45 NodeItem roughness = get_input_value("Roughness", NodeItem::Type::Float);
46 NodeItem normal = get_input_link("Normal", NodeItem::Type::Vector3);
47
48 return create_node("oren_nayar_diffuse_bsdf",
49 NodeItem::Type::BSDF,
50 {{"color", color}, {"roughness", roughness}, {"normal", normal}});
51}
52#endif
54
55} // namespace blender::nodes::node_shader_bsdf_diffuse_cc
56
57/* node type definition */
59{
61
62 static blender::bke::bNodeType ntype;
63
64 sh_node_type_base(&ntype, "ShaderNodeBsdfDiffuse", SH_NODE_BSDF_DIFFUSE);
65 ntype.ui_name = "Diffuse BSDF";
66 ntype.ui_description = "Lambertian and Oren-Nayar diffuse reflection";
67 ntype.enum_name_legacy = "BSDF_DIFFUSE";
69 ntype.declare = file_ns::node_declare;
72 ntype.gpu_fn = file_ns::node_shader_gpu_bsdf_diffuse;
73 ntype.materialx_fn = file_ns::node_shader_materialx;
74
76}
#define NODE_CLASS_SHADER
Definition BKE_node.hh:460
#define SH_NODE_BSDF_DIFFUSE
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
@ GPU_MATFLAG_DIFFUSE
void GPU_material_flag_set(GPUMaterial *mat, eGPUMaterialFlag flag)
bool GPU_link(GPUMaterial *mat, const char *name,...)
@ PROP_FACTOR
Definition RNA_types.hh:251
#define in
#define out
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
void node_type_size_preset(bNodeType &ntype, eNodeSizePreset size)
Definition node.cc:5396
static int node_shader_gpu_bsdf_diffuse(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_bsdf_diffuse()
void sh_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
bool object_shader_nodes_poll(const bContext *C)
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
bool(* add_ui_poll)(const bContext *C)
Definition BKE_node.hh:310
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