Blender V4.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
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 uiItemR(layout, ptr, "distribution", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
35}
36
37static void node_shader_init_glossy(bNodeTree * /*ntree*/, bNode *node)
38{
39 node->custom1 = SHD_GLOSSY_MULTI_GGX;
40}
41
43 bNode *node,
44 bNodeExecData * /*execdata*/,
45 GPUNodeStack *in,
46 GPUNodeStack *out)
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, SH_NODE_BSDF_GLOSSY, "Glossy BSDF", NODE_CLASS_SHADER);
99 ntype.declare = file_ns::node_declare;
101 ntype.draw_buttons = file_ns::node_shader_buts_glossy;
103 ntype.initfunc = file_ns::node_shader_init_glossy;
104 ntype.gpu_fn = file_ns::node_shader_gpu_bsdf_glossy;
105 ntype.materialx_fn = file_ns::node_shader_materialx;
106
108
109 /* Needed to preserve API compatibility with older versions which had separate
110 * Glossy and Anisotropic nodes. */
111 blender::bke::node_register_alias(&ntype, "ShaderNodeBsdfGlossy");
112}
#define NODE_CLASS_SHADER
Definition BKE_node.hh:417
@ 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:154
void uiItemR(uiLayout *layout, PointerRNA *ptr, const char *propname, eUI_Item_Flag flag, const char *name, int icon)
@ UI_ITEM_R_SPLIT_EMPTY_NAME
local_group_size(16, 16) .push_constant(Type b
void node_register_alias(bNodeType *nt, const char *alias)
Definition node.cc:1731
void node_type_size_preset(bNodeType *ntype, eNodeSizePreset size)
Definition node.cc:4614
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
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, int type, const char *name, short nclass)
bool object_shader_nodes_poll(const bContext *C)
Defines a node type.
Definition BKE_node.hh:218
NodeMaterialXFunction materialx_fn
Definition BKE_node.hh:320
bool(* add_ui_poll)(const bContext *C)
Definition BKE_node.hh:288
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:267
NodeGPUExecFunction gpu_fn
Definition BKE_node.hh:318
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:238
NodeDeclareFunction declare
Definition BKE_node.hh:347
PointerRNA * ptr
Definition wm_files.cc:4126