Blender V5.3
node_shader_bsdf_glossy.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
12#include "UI_resources.hh"
13
14namespace blender {
15
17
19{
20 const bNodeTree *ntree = b.tree_or_null();
21 const bool is_gpu_internal = ntree && (ntree->flag & NTREE_IS_GPU_SHADER_INTERNAL);
22
23 b.add_input<decl::Color>("Color"_ustr).default_value({0.8f, 0.8f, 0.8f, 1.0f});
24 b.add_input<decl::Float>("Roughness"_ustr)
25 .default_value(0.5f)
26 .min(0.0f)
27 .max(1.0f)
29 b.add_input<decl::Float>("Anisotropy"_ustr).default_value(0.0f).min(-1.0f).max(1.0f);
30 b.add_input<decl::Float>("Rotation"_ustr)
31 .default_value(0.0f)
32 .min(0.0f)
33 .max(1.0f)
35 b.add_input<decl::Vector>("Normal"_ustr).hide_value();
36 b.add_input<decl::Vector>("Tangent"_ustr).hide_value();
37 b.add_input<decl::Float>("Weight"_ustr).available(is_gpu_internal);
38 b.add_output<decl::Shader>("BSDF"_ustr);
39}
40
41static void node_shader_buts_glossy(ui::Layout &layout, bContext * /*C*/, PointerRNA *ptr)
42{
43 layout.prop(ptr, "distribution", ui::ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
44}
45
46static void node_shader_init_glossy(bNodeTree * /*ntree*/, bNode *node)
47{
48 node->custom1 = SHD_GLOSSY_MULTI_GGX;
49}
50
52 bNode *node,
53 bNodeExecData * /*execdata*/,
56{
57 if (!in[4].link) {
58 GPU_link(mat, "world_normals_get", GPU_shading_data(), &in[4].link);
59 }
60
62
63 if (in[0].might_be_tinted()) {
65 }
66
67 float use_multi_scatter = (node->custom1 == SHD_GLOSSY_MULTI_GGX) ? 1.0f : 0.0f;
68
69 return GPU_stack_link(mat,
70 node,
71 "node_bsdf_glossy",
72 in,
73 out,
74 GPU_constant(&use_multi_scatter),
77}
78
80#ifdef WITH_MATERIALX
81{
82 if (to_type_ != NodeItem::Type::BSDF) {
83 return empty();
84 }
85
86 NodeItem color = get_input_value("Color", NodeItem::Type::Color3);
87 NodeItem roughness = get_input_value("Roughness", NodeItem::Type::Vector2);
88 NodeItem anisotropy = get_input_value("Anisotropy", NodeItem::Type::Color3);
89 NodeItem normal = get_input_link("Normal", NodeItem::Type::Vector3);
90 NodeItem tangent = get_input_link("Tangent", NodeItem::Type::Vector3);
91
92 NodeItem artistic_ior = create_node("artistic_ior",
93 NodeItem::Type::Multioutput,
94 {{"reflectivity", color}, {"edge_color", color}});
95 NodeItem ior_out = artistic_ior.add_output("ior", NodeItem::Type::Color3);
96 NodeItem extinction_out = artistic_ior.add_output("extinction", NodeItem::Type::Color3);
97
98 return create_node("conductor_bsdf",
99 NodeItem::Type::BSDF,
100 {{"normal", normal},
101 {"tangent", tangent},
102 {"ior", ior_out},
103 {"extinction", extinction_out},
104 {"roughness", roughness}});
105}
106#endif
108
109} // namespace nodes::node_shader_bsdf_glossy_cc
110
111/* node type definition */
113{
114 namespace file_ns = nodes::node_shader_bsdf_glossy_cc;
115
116 static bke::bNodeType ntype;
117
118 sh_node_type_base(&ntype, "ShaderNodeBsdfAnisotropic"_ustr, SH_NODE_BSDF_GLOSSY);
119 ntype.ui_name = "Glossy BSDF";
120 ntype.ui_description =
121 "Reflection with microfacet distribution, used for materials such as metal or mirrors";
122 ntype.enum_name_legacy = "BSDF_GLOSSY";
124 ntype.declare = file_ns::node_declare;
127 ntype.draw_buttons = file_ns::node_shader_buts_glossy;
129 ntype.initfunc = file_ns::node_shader_init_glossy;
130 ntype.gpu_fn = file_ns::node_shader_gpu_bsdf_glossy;
131 ntype.materialx_fn = file_ns::node_shader_materialx;
132
134
135 /* Needed to preserve API compatibility with older versions which had separate
136 * Glossy and Anisotropic nodes. */
137 bke::node_register_alias(ntype, "ShaderNodeBsdfGlossy"_ustr);
138}
139
140} // namespace blender
#define NODE_CLASS_SHADER
Definition BKE_node.hh:491
#define SH_NODE_BSDF_GLOSSY
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
void node_register_alias(bNodeType &nt, UString alias)
Definition node.cc:2956
static void node_shader_buts_glossy(ui::Layout &layout, bContext *, PointerRNA *ptr)
static void node_shader_init_glossy(bNodeTree *, bNode *node)
static int node_shader_gpu_bsdf_glossy(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_GLOSSY
@ GPU_MATFLAG_REFLECTION_MAYBE_COLORED
void sh_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
GPUNodeLink * GPU_constant(const float *num)
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)
GPUNodeLink * GPU_shading_data()
@ NTREE_IS_GPU_SHADER_INTERNAL
GPUNodeLink * GPU_kernel_globals()
void register_node_type_sh_bsdf_glossy()
@ PROP_FACTOR
Definition RNA_types.hh:308
@ SHD_GLOSSY_MULTI_GGX
#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
void(*) draw_buttons(ui::Layout &, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:290
std::string ui_description
Definition BKE_node.hh:271
NodeGPUExecFunction gpu_fn
Definition BKE_node.hh:373
void(*) initfunc(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:320
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
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< StringRef > name_opt, int icon, std::optional< StringRef > placeholder=std::nullopt)