Blender V4.3
node_shader_bsdf_metallic.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 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>("Base Color")
15 .default_value({0.617f, 0.577f, 0.540f, 1.0f})
16 .description("Color of the material");
17 b.add_input<decl::Color>("Edge Tint")
18 .default_value({0.695f, 0.726f, 0.770f, 1.0f})
19 .description(
20 "Tint reflection at near-grazing incidence to simulate complex index of refraction");
21 b.add_input<decl::Vector>("IOR")
22 .default_value({2.757f, 2.513f, 2.231f})
23 .min(0.0f)
24 .max(100.0f)
25 .description("Real part of the conductor's refractive index, often called n");
26 b.add_input<decl::Vector>("Extinction")
27 .default_value({3.867f, 3.404f, 3.009f})
28 .min(0.0f)
29 .max(100.0f)
30 .description("Imaginary part of the conductor's refractive index, often called k");
31 b.add_input<decl::Float>("Roughness")
32 .default_value(0.5f)
33 .min(0.0f)
34 .max(1.0f)
36 .description(
37 "Microfacet roughness of the surface (0.0 is a perfect mirror reflection, 1.0 is "
38 "completely rough)");
39 ;
40 b.add_input<decl::Float>("Anisotropy")
41 .default_value(0.0f)
42 .min(0.0f)
43 .max(1.0f)
45 .description(
46 "Amount of anisotropy for reflection. Higher values give elongated highlights along the "
47 "tangent direction");
48 b.add_input<decl::Float>("Rotation")
49 .default_value(0.0f)
50 .min(0.0f)
51 .max(1.0f)
53 .description("Rotates the direction of anisotropy, with 1.0 going full circle");
54 b.add_input<decl::Vector>("Normal").hide_value();
55 b.add_input<decl::Vector>("Tangent").hide_value();
56 b.add_input<decl::Float>("Weight").available(false);
57 b.add_output<decl::Shader>("BSDF");
58}
59
61{
62 uiItemR(layout, ptr, "distribution", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
63 uiItemR(layout, ptr, "fresnel_type", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
64}
65
66static void node_shader_init_metallic(bNodeTree * /*ntree*/, bNode *node)
67{
70}
71
73 bNode *node,
74 bNodeExecData * /*execdata*/,
75 GPUNodeStack *in,
76 GPUNodeStack *out)
77{
78 if (!in[7].link) {
79 GPU_link(mat, "world_normals_get", &in[7].link);
80 }
81
83
84 float use_multi_scatter = (node->custom1 == SHD_GLOSSY_MULTI_GGX) ? 1.0f : 0.0f;
85 float use_complex_ior = (node->custom2 == SHD_PHYSICAL_CONDUCTOR) ? 1.0f : 0.0f;
86
87 return GPU_stack_link(mat,
88 node,
89 "node_bsdf_metallic",
90 in,
91 out,
92 GPU_constant(&use_multi_scatter),
93 GPU_constant(&use_complex_ior));
94}
95
97{
98 const bool is_physical = (node->custom2 == SHD_PHYSICAL_CONDUCTOR);
99
101 ntree, bke::node_find_socket(node, SOCK_IN, "Base Color"), !is_physical);
103 ntree, bke::node_find_socket(node, SOCK_IN, "Edge Tint"), !is_physical);
105 ntree, bke::node_find_socket(node, SOCK_IN, "IOR"), is_physical);
107 ntree, bke::node_find_socket(node, SOCK_IN, "Extinction"), is_physical);
108}
109
111#ifdef WITH_MATERIALX
112{
113 if (to_type_ != NodeItem::Type::BSDF) {
114 return empty();
115 }
116
117 NodeItem color = get_input_value("Base Color", NodeItem::Type::Color3);
118 NodeItem edge_tint = get_input_value("Edge Tint", NodeItem::Type::Color3);
119 NodeItem roughness = get_input_value("Roughness", NodeItem::Type::Vector2);
120 NodeItem anisotropy = get_input_value("Anisotropy", NodeItem::Type::Color3);
121 NodeItem normal = get_input_link("Normal", NodeItem::Type::Vector3);
122 NodeItem tangent = get_input_link("Tangent", NodeItem::Type::Vector3);
123
124 NodeItem ior_out, extinction_out;
125 if (node_->custom2 == SHD_PHYSICAL_CONDUCTOR) {
126 ior_out = get_input_value("IOR", NodeItem::Type::Color3);
127 extinction_out = get_input_value("Extinction", NodeItem::Type::Color3);
128 }
129 else {
130 NodeItem artistic_ior = create_node("artistic_ior",
131 NodeItem::Type::Multioutput,
132 {{"reflectivity", color}, {"edge_color", edge_tint}});
133 ior_out = artistic_ior.add_output("ior", NodeItem::Type::Color3);
134 extinction_out = artistic_ior.add_output("extinction", NodeItem::Type::Color3);
135 }
136
137 return create_node("conductor_bsdf",
138 NodeItem::Type::BSDF,
139 {{"normal", normal},
140 {"tangent", tangent},
141 {"ior", ior_out},
142 {"extinction", extinction_out},
143 {"roughness", roughness}});
144}
145#endif
147
148} // namespace blender::nodes::node_shader_bsdf_metallic_cc
149
150/* node type definition */
152{
154
155 static blender::bke::bNodeType ntype;
156
158 ntype.declare = file_ns::node_declare;
160 ntype.draw_buttons = file_ns::node_shader_buts_metallic;
162 ntype.initfunc = file_ns::node_shader_init_metallic;
163 ntype.gpu_fn = file_ns::node_shader_gpu_bsdf_metallic;
164 ntype.updatefunc = file_ns::node_shader_update_metallic;
165 ntype.materialx_fn = file_ns::node_shader_materialx;
166
168}
#define SH_NODE_BSDF_METALLIC
Definition BKE_node.hh:999
#define NODE_CLASS_SHADER
Definition BKE_node.hh:417
@ SHD_CONDUCTOR_F82
@ SHD_PHYSICAL_CONDUCTOR
@ SOCK_IN
@ 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,...)
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Brightness Control the brightness and contrast of the input color Vector Map input vector components with curves Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp a value between a minimum and a maximum Vector Perform vector math operation Invert Invert a color
@ 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_type_size_preset(bNodeType *ntype, eNodeSizePreset size)
Definition node.cc:4614
void node_set_socket_availability(bNodeTree *ntree, bNodeSocket *sock, bool is_available)
Definition node.cc:3911
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
bNodeSocket * node_find_socket(bNode *node, eNodeSocketInOut in_out, StringRef identifier)
Definition node.cc:1829
void normal(const bNode &, void *r_value)
static void node_shader_update_metallic(bNodeTree *ntree, bNode *node)
static void node_shader_init_metallic(bNodeTree *, bNode *node)
static void node_declare(NodeDeclarationBuilder &b)
static int node_shader_gpu_bsdf_metallic(GPUMaterial *mat, bNode *node, bNodeExecData *, GPUNodeStack *in, GPUNodeStack *out)
static void node_shader_buts_metallic(uiLayout *layout, bContext *, PointerRNA *ptr)
#define NODE_SHADER_MATERIALX_BEGIN
#define NODE_SHADER_MATERIALX_END
void register_node_type_sh_bsdf_metallic()
void sh_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
bool object_shader_nodes_poll(const bContext *C)
#define min(a, b)
Definition sort.c:32
int16_t custom1
int16_t custom2
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
void(* updatefunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:257
PointerRNA * ptr
Definition wm_files.cc:4126