Blender V5.3
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
8
9#include "node_shader_util.hh"
10
11namespace blender {
12
14
16{
17 const bNodeTree *ntree = b.tree_or_null();
18 const bool is_gpu_internal = ntree && (ntree->flag & NTREE_IS_GPU_SHADER_INTERNAL);
19
20 b.add_input<decl::Color>("Color"_ustr).default_value({0.8f, 0.8f, 0.8f, 1.0f});
21 b.add_input<decl::Float>("Roughness"_ustr)
22 .default_value(0.0f)
23 .min(0.0f)
24 .max(1.0f)
26 b.add_input<decl::Vector>("Normal"_ustr).hide_value();
27 b.add_input<decl::Float>("Weight"_ustr).available(is_gpu_internal);
28 b.add_output<decl::Shader>("BSDF"_ustr);
29}
30
32 bNode *node,
33 bNodeExecData * /*execdata*/,
36{
37 if (!in[2].link) {
38 GPU_link(mat, "world_normals_get", GPU_shading_data(), &in[2].link);
39 }
40
42
43 return GPU_stack_link(
44 mat, node, "node_bsdf_diffuse", in, out, GPU_kernel_globals(), GPU_shading_data());
45}
46
48#ifdef WITH_MATERIALX
49{
50 if (to_type_ != NodeItem::Type::BSDF) {
51 return empty();
52 }
53
54 NodeItem color = get_input_value("Color", NodeItem::Type::Color3);
55 NodeItem roughness = get_input_value("Roughness", NodeItem::Type::Float);
56 NodeItem normal = get_input_link("Normal", NodeItem::Type::Vector3);
57
58 return create_node("oren_nayar_diffuse_bsdf",
59 NodeItem::Type::BSDF,
60 {{"color", color}, {"roughness", roughness}, {"normal", normal}});
61}
62#endif
64
65} // namespace nodes::node_shader_bsdf_diffuse_cc
66
67/* node type definition */
69{
70 namespace file_ns = nodes::node_shader_bsdf_diffuse_cc;
71
72 static bke::bNodeType ntype;
73
74 sh_node_type_base(&ntype, "ShaderNodeBsdfDiffuse"_ustr, SH_NODE_BSDF_DIFFUSE);
75 ntype.ui_name = "Diffuse BSDF";
76 ntype.ui_description = "Lambertian and Oren-Nayar diffuse reflection";
77 ntype.enum_name_legacy = "BSDF_DIFFUSE";
79 ntype.declare = file_ns::node_declare;
83 ntype.gpu_fn = file_ns::node_shader_gpu_bsdf_diffuse;
84 ntype.materialx_fn = file_ns::node_shader_materialx;
85
87}
88
89} // namespace blender
#define NODE_CLASS_SHADER
Definition BKE_node.hh:491
#define SH_NODE_BSDF_DIFFUSE
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
static int node_shader_gpu_bsdf_diffuse(GPUMaterial *mat, bNode *node, bNodeExecData *, GPUNodeStack *in, GPUNodeStack *out)
static void node_declare(NodeDeclarationBuilder &b)
BMesh Iterators.
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
bool object_shader_nodes_poll(const bContext *C)
@ GPU_MATFLAG_DIFFUSE
void sh_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
bool GPU_link(GPUMaterial *mat, const char *name,...)
void search_link_ops_for_shader_bsdf_node(nodes::GatherLinkSearchOpParams &params)
void GPU_material_flag_set(GPUMaterial *mat, eGPUMaterialFlag flag)
void register_node_type_sh_bsdf_diffuse()
GPUNodeLink * GPU_shading_data()
@ NTREE_IS_GPU_SHADER_INTERNAL
GPUNodeLink * GPU_kernel_globals()
@ PROP_FACTOR
Definition RNA_types.hh:308
#define NODE_SHADER_MATERIALX_BEGIN
#define NODE_SHADER_MATERIALX_END
eNodeTree_Flag flag
static constexpr int _160
Definition BKE_node.hh:246
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
NodeGatherSocketLinkOperationsFunction gather_link_search_ops
Definition BKE_node.hh:409
NodeDeclareFunction declare
Definition BKE_node.hh:393
bool(*) add_ui_poll(const bContext *C)
Definition BKE_node.hh:341