Blender V5.3
node_shader_bsdf_glass.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
10#include "UI_resources.hh"
11
12#include "node_shader_util.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.use_custom_socket_order();
24
25 b.add_output<decl::Shader>("BSDF"_ustr);
26
27 b.add_default_layout();
28
29 b.add_input<decl::Color>("Color"_ustr).default_value({1.0f, 1.0f, 1.0f, 1.0f});
30 b.add_input<decl::Float>("Roughness"_ustr)
31 .default_value(0.0f)
32 .min(0.0f)
33 .max(1.0f)
35 b.add_input<decl::Float>("Anisotropy"_ustr)
36 .default_value(0.0f)
37 .min(-1.0f)
38 .max(1.0f)
40 .short_label("Anisotropy"_ustr)
41 .description(
42 "Amount of anisotropy for specular reflection. "
43 "Higher absolute values give elongated highlights along the tangent direction");
44 b.add_input<decl::Float>("Rotation"_ustr)
45 .default_value(0.0f)
46 .min(0.0f)
47 .max(1.0f)
49 .description("Rotates the direction of anisotropy, with 1.0 going full circle");
50 b.add_input<decl::Float>("IOR"_ustr).default_value(1.5f).min(0.0f).max(1000.0f);
51 b.add_input<decl::Vector>("Normal"_ustr).hide_value();
52 b.add_input<decl::Vector>("Tangent"_ustr).hide_value();
53 b.add_input<decl::Float>("Weight"_ustr).available(is_gpu_internal);
54
55 PanelDeclarationBuilder &film = b.add_panel("Thin Film"_ustr).default_closed(true);
56 film.add_input<decl::Float>("Thin Film Thickness"_ustr)
57 .default_value(0.0)
58 .min(0.0f)
59 .max(100000.0f)
61 .description("Thickness of the film in nanometers");
62 film.add_input<decl::Float>("Thin Film IOR"_ustr)
63 .default_value(1.33f)
64 .min(1.0f)
65 .max(1000.0f)
66 .description("Index of refraction (IOR) of the thin film");
67}
68
69static void node_shader_buts_glass(ui::Layout &layout, bContext * /*C*/, PointerRNA *ptr)
70{
71 layout.prop(ptr, "distribution", ui::ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
72}
73
74static void node_shader_init_glass(bNodeTree * /*ntree*/, bNode *node)
75{
76 node->custom1 = SHD_GLOSSY_MULTI_GGX;
77}
78
80 bNode *node,
81 bNodeExecData * /*execdata*/,
84{
85 if (!in[5].link) {
86 GPU_link(mat, "world_normals_get", GPU_shading_data(), &in[5].link);
87 }
88
90
91 if (in[0].might_be_tinted()) {
94 }
95
96 float use_multi_scatter = (node->custom1 == SHD_GLOSSY_MULTI_GGX) ? 1.0f : 0.0f;
97
98 return GPU_stack_link(mat,
99 node,
100 "node_bsdf_glass",
101 in,
102 out,
103 GPU_constant(&use_multi_scatter),
106}
107
109#ifdef WITH_MATERIALX
110{
111 if (to_type_ != NodeItem::Type::BSDF) {
112 return empty();
113 }
114
115 NodeItem color = get_input_value("Color", NodeItem::Type::Color3);
116 NodeItem roughness = get_input_value("Roughness", NodeItem::Type::Vector2);
117 NodeItem ior = get_input_value("IOR", NodeItem::Type::Float);
118 NodeItem normal = get_input_link("Normal", NodeItem::Type::Vector3);
119 NodeItem thin_film_thickness = get_input_value("Thin Film Thickness", NodeItem::Type::Float);
120 NodeItem thin_film_ior = get_input_value("Thin Film IOR", NodeItem::Type::Float);
121
122 return create_node("dielectric_bsdf",
123 NodeItem::Type::BSDF,
124 {{"normal", normal},
125 {"tint", color},
126 {"roughness", roughness},
127 {"ior", ior},
128 {"thinfilm_thickness", thin_film_thickness},
129 {"thinfilm_ior", thin_film_ior},
130 {"scatter_mode", val(std::string("RT"))}});
131}
132#endif
134
135} // namespace nodes::node_shader_bsdf_glass_cc
136
137/* node type definition */
139{
140 namespace file_ns = nodes::node_shader_bsdf_glass_cc;
141
142 static bke::bNodeType ntype;
143
144 sh_node_type_base(&ntype, "ShaderNodeBsdfGlass"_ustr, SH_NODE_BSDF_GLASS);
145 ntype.ui_name = "Glass BSDF";
146 ntype.ui_description = "Glass-like shader mixing refraction and reflection at grazing angles";
147 ntype.enum_name_legacy = "BSDF_GLASS";
149 ntype.declare = file_ns::node_declare;
153 ntype.draw_buttons = file_ns::node_shader_buts_glass;
154 ntype.initfunc = file_ns::node_shader_init_glass;
155 ntype.gpu_fn = file_ns::node_shader_gpu_bsdf_glass;
156 ntype.materialx_fn = file_ns::node_shader_materialx;
157
159}
160
161} // namespace blender
#define NODE_CLASS_SHADER
Definition BKE_node.hh:491
#define SH_NODE_BSDF_GLASS
DeclType::Builder & add_input(UString name, UString identifier=""_ustr)
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
static void node_declare(NodeDeclarationBuilder &b)
static void node_shader_buts_glass(ui::Layout &layout, bContext *, PointerRNA *ptr)
static void node_shader_init_glass(bNodeTree *, bNode *node)
static int node_shader_gpu_bsdf_glass(GPUMaterial *mat, bNode *node, bNodeExecData *, GPUNodeStack *in, GPUNodeStack *out)
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_REFRACT
@ GPU_MATFLAG_REFLECTION_MAYBE_COLORED
@ GPU_MATFLAG_REFRACTION_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)
void register_node_type_sh_bsdf_glass()
GPUNodeLink * GPU_shading_data()
@ NTREE_IS_GPU_SHADER_INTERNAL
GPUNodeLink * GPU_kernel_globals()
@ PROP_FACTOR
Definition RNA_types.hh:308
@ PROP_WAVELENGTH
Definition RNA_types.hh:344
@ 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)