Blender V5.0
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
5#include "node_shader_util.hh"
6
8#include "UI_resources.hh"
9
11
13{
14 b.add_input<decl::Color>("Color").default_value({0.8f, 0.8f, 0.8f, 1.0f});
15 b.add_input<decl::Float>("Roughness")
16 .default_value(0.5f)
17 .min(0.0f)
18 .max(1.0f)
20 b.add_input<decl::Float>("Anisotropy").default_value(0.0f).min(-1.0f).max(1.0f);
21 b.add_input<decl::Float>("Rotation")
22 .default_value(0.0f)
23 .min(0.0f)
24 .max(1.0f)
26 b.add_input<decl::Vector>("Normal").hide_value();
27 b.add_input<decl::Vector>("Tangent").hide_value();
28 b.add_input<decl::Float>("Weight").available(false);
29 b.add_output<decl::Shader>("BSDF");
30}
31
33{
34 layout->prop(ptr, "distribution", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
35}
36
37static void node_shader_init_glossy(bNodeTree * /*ntree*/, bNode *node)
38{
40}
41
43 bNode *node,
44 bNodeExecData * /*execdata*/,
47{
48 if (!in[4].link) {
49 GPU_link(mat, "world_normals_get", &in[4].link);
50 }
51
53
54 if (in[0].might_be_tinted()) {
56 }
57
58 float use_multi_scatter = (node->custom1 == SHD_GLOSSY_MULTI_GGX) ? 1.0f : 0.0f;
59
60 return GPU_stack_link(mat, node, "node_bsdf_glossy", in, out, GPU_constant(&use_multi_scatter));
61}
62
64#ifdef WITH_MATERIALX
65{
66 if (to_type_ != NodeItem::Type::BSDF) {
67 return empty();
68 }
69
70 NodeItem color = get_input_value("Color", NodeItem::Type::Color3);
71 NodeItem roughness = get_input_value("Roughness", NodeItem::Type::Vector2);
72 NodeItem anisotropy = get_input_value("Anisotropy", NodeItem::Type::Color3);
73 NodeItem normal = get_input_link("Normal", NodeItem::Type::Vector3);
74 NodeItem tangent = get_input_link("Tangent", NodeItem::Type::Vector3);
75
76 NodeItem artistic_ior = create_node("artistic_ior",
77 NodeItem::Type::Multioutput,
78 {{"reflectivity", color}, {"edge_color", color}});
79 NodeItem ior_out = artistic_ior.add_output("ior", NodeItem::Type::Color3);
80 NodeItem extinction_out = artistic_ior.add_output("extinction", NodeItem::Type::Color3);
81
82 return create_node("conductor_bsdf",
83 NodeItem::Type::BSDF,
84 {{"normal", normal},
85 {"tangent", tangent},
86 {"ior", ior_out},
87 {"extinction", extinction_out},
88 {"roughness", roughness}});
89}
90#endif
92
93} // namespace blender::nodes::node_shader_bsdf_glossy_cc
94
95/* node type definition */
97{
99
100 static blender::bke::bNodeType ntype;
101
102 sh_node_type_base(&ntype, "ShaderNodeBsdfAnisotropic", SH_NODE_BSDF_GLOSSY);
103 ntype.ui_name = "Glossy BSDF";
104 ntype.ui_description =
105 "Reflection with microfacet distribution, used for materials such as metal or mirrors";
106 ntype.enum_name_legacy = "BSDF_GLOSSY";
108 ntype.declare = file_ns::node_declare;
110 ntype.draw_buttons = file_ns::node_shader_buts_glossy;
112 ntype.initfunc = file_ns::node_shader_init_glossy;
113 ntype.gpu_fn = file_ns::node_shader_gpu_bsdf_glossy;
114 ntype.materialx_fn = file_ns::node_shader_materialx;
115
117
118 /* Needed to preserve API compatibility with older versions which had separate
119 * Glossy and Anisotropic nodes. */
120 blender::bke::node_register_alias(ntype, "ShaderNodeBsdfGlossy");
121}
#define NODE_CLASS_SHADER
Definition BKE_node.hh:460
#define SH_NODE_BSDF_GLOSSY
@ SHD_GLOSSY_MULTI_GGX
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
GPUNodeLink * GPU_constant(const float *num)
@ GPU_MATFLAG_REFLECTION_MAYBE_COLORED
@ GPU_MATFLAG_GLOSSY
void GPU_material_flag_set(GPUMaterial *mat, eGPUMaterialFlag flag)
bool GPU_link(GPUMaterial *mat, const char *name,...)
@ PROP_FACTOR
Definition RNA_types.hh:251
@ UI_ITEM_R_SPLIT_EMPTY_NAME
#define in
#define out
void node_register_alias(bNodeType &nt, StringRef alias)
Definition node.cc:2452
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
void node_type_size_preset(bNodeType &ntype, eNodeSizePreset size)
Definition node.cc:5396
static void node_shader_init_glossy(bNodeTree *, bNode *node)
static void node_shader_buts_glossy(uiLayout *layout, bContext *, PointerRNA *ptr)
static int node_shader_gpu_bsdf_glossy(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_glossy()
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)
int16_t custom1
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
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:289
NodeGPUExecFunction gpu_fn
Definition BKE_node.hh:342
const char * enum_name_legacy
Definition BKE_node.hh:247
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:259
NodeDeclareFunction declare
Definition BKE_node.hh:362
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< blender::StringRef > name_opt, int icon, std::optional< blender::StringRef > placeholder=std::nullopt)
PointerRNA * ptr
Definition wm_files.cc:4238