Blender V4.5
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
7#include "UI_interface.hh"
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 float use_multi_scatter = (node->custom1 == SHD_GLOSSY_MULTI_GGX) ? 1.0f : 0.0f;
55
56 return GPU_stack_link(mat, node, "node_bsdf_glossy", in, out, GPU_constant(&use_multi_scatter));
57}
58
60#ifdef WITH_MATERIALX
61{
62 if (to_type_ != NodeItem::Type::BSDF) {
63 return empty();
64 }
65
66 NodeItem color = get_input_value("Color", NodeItem::Type::Color3);
67 NodeItem roughness = get_input_value("Roughness", NodeItem::Type::Vector2);
68 NodeItem anisotropy = get_input_value("Anisotropy", NodeItem::Type::Color3);
69 NodeItem normal = get_input_link("Normal", NodeItem::Type::Vector3);
70 NodeItem tangent = get_input_link("Tangent", NodeItem::Type::Vector3);
71
72 NodeItem artistic_ior = create_node("artistic_ior",
73 NodeItem::Type::Multioutput,
74 {{"reflectivity", color}, {"edge_color", color}});
75 NodeItem ior_out = artistic_ior.add_output("ior", NodeItem::Type::Color3);
76 NodeItem extinction_out = artistic_ior.add_output("extinction", NodeItem::Type::Color3);
77
78 return create_node("conductor_bsdf",
79 NodeItem::Type::BSDF,
80 {{"normal", normal},
81 {"tangent", tangent},
82 {"ior", ior_out},
83 {"extinction", extinction_out},
84 {"roughness", roughness}});
85}
86#endif
88
89} // namespace blender::nodes::node_shader_bsdf_glossy_cc
90
91/* node type definition */
93{
95
96 static blender::bke::bNodeType ntype;
97
98 sh_node_type_base(&ntype, "ShaderNodeBsdfAnisotropic", SH_NODE_BSDF_GLOSSY);
99 ntype.ui_name = "Glossy BSDF";
100 ntype.ui_description =
101 "Reflection with microfacet distribution, used for materials such as metal or mirrors";
102 ntype.enum_name_legacy = "BSDF_GLOSSY";
104 ntype.declare = file_ns::node_declare;
106 ntype.draw_buttons = file_ns::node_shader_buts_glossy;
108 ntype.initfunc = file_ns::node_shader_init_glossy;
109 ntype.gpu_fn = file_ns::node_shader_gpu_bsdf_glossy;
110 ntype.materialx_fn = file_ns::node_shader_materialx;
111
113
114 /* Needed to preserve API compatibility with older versions which had separate
115 * Glossy and Anisotropic nodes. */
116 blender::bke::node_register_alias(ntype, "ShaderNodeBsdfGlossy");
117}
#define NODE_CLASS_SHADER
Definition BKE_node.hh:446
#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_GLOSSY
void GPU_material_flag_set(GPUMaterial *mat, eGPUMaterialFlag flag)
bool GPU_link(GPUMaterial *mat, const char *name,...)
@ PROP_FACTOR
Definition RNA_types.hh:239
@ UI_ITEM_R_SPLIT_EMPTY_NAME
#define in
#define out
void node_register_alias(bNodeType &nt, StringRef alias)
Definition node.cc:2784
void node_register_type(bNodeType &ntype)
Definition node.cc:2748
void node_type_size_preset(bNodeType &ntype, eNodeSizePreset size)
Definition node.cc:5585
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:226
NodeMaterialXFunction materialx_fn
Definition BKE_node.hh:332
std::string ui_description
Definition BKE_node.hh:232
bool(* add_ui_poll)(const bContext *C)
Definition BKE_node.hh:298
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:277
NodeGPUExecFunction gpu_fn
Definition BKE_node.hh:330
const char * enum_name_legacy
Definition BKE_node.hh:235
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:247
NodeDeclareFunction declare
Definition BKE_node.hh:355
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:4226