Blender V5.0
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
6#include "UI_resources.hh"
7
8#include "node_shader_util.hh"
9
11
13{
14 b.use_custom_socket_order();
15
16 b.add_output<decl::Shader>("BSDF");
17
18 b.add_default_layout();
19
20 b.add_input<decl::Color>("Color").default_value({1.0f, 1.0f, 1.0f, 1.0f});
21 b.add_input<decl::Float>("Roughness")
22 .default_value(0.0f)
23 .min(0.0f)
24 .max(1.0f)
26 b.add_input<decl::Float>("IOR").default_value(1.5f).min(0.0f).max(1000.0f);
27 b.add_input<decl::Vector>("Normal").hide_value();
28 b.add_input<decl::Float>("Weight").available(false);
29
30 PanelDeclarationBuilder &film = b.add_panel("Thin Film").default_closed(true);
31 film.add_input<decl::Float>("Thin Film Thickness")
32 .default_value(0.0)
33 .min(0.0f)
34 .max(100000.0f)
36 .description("Thickness of the film in nanometers");
37 film.add_input<decl::Float>("Thin Film IOR")
38 .default_value(1.33f)
39 .min(1.0f)
40 .max(1000.0f)
41 .description("Index of refraction (IOR) of the thin film");
42}
43
44static void node_shader_buts_glass(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
45{
46 layout->prop(ptr, "distribution", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
47}
48
49static void node_shader_init_glass(bNodeTree * /*ntree*/, bNode *node)
50{
52}
53
55 bNode *node,
56 bNodeExecData * /*execdata*/,
59{
60 if (!in[3].link) {
61 GPU_link(mat, "world_normals_get", &in[3].link);
62 }
63
65
66 if (in[0].might_be_tinted()) {
69 }
70
71 float use_multi_scatter = (node->custom1 == SHD_GLOSSY_MULTI_GGX) ? 1.0f : 0.0f;
72
73 return GPU_stack_link(mat, node, "node_bsdf_glass", in, out, GPU_constant(&use_multi_scatter));
74}
75
77#ifdef WITH_MATERIALX
78{
79 if (to_type_ != NodeItem::Type::BSDF) {
80 return empty();
81 }
82
83 NodeItem color = get_input_value("Color", NodeItem::Type::Color3);
84 NodeItem roughness = get_input_value("Roughness", NodeItem::Type::Vector2);
85 NodeItem ior = get_input_value("IOR", NodeItem::Type::Float);
86 NodeItem normal = get_input_link("Normal", NodeItem::Type::Vector3);
87 NodeItem thin_film_thickness = get_input_value("Thin Film Thickness", NodeItem::Type::Float);
88 NodeItem thin_film_ior = get_input_value("Thin Film IOR", NodeItem::Type::Float);
89
90 return create_node("dielectric_bsdf",
91 NodeItem::Type::BSDF,
92 {{"normal", normal},
93 {"tint", color},
94 {"roughness", roughness},
95 {"ior", ior},
96 {"thinfilm_thickness", thin_film_thickness},
97 {"thinfilm_ior", thin_film_ior},
98 {"scatter_mode", val(std::string("RT"))}});
99}
100#endif
102
103} // namespace blender::nodes::node_shader_bsdf_glass_cc
104
105/* node type definition */
107{
109
110 static blender::bke::bNodeType ntype;
111
112 sh_node_type_base(&ntype, "ShaderNodeBsdfGlass", SH_NODE_BSDF_GLASS);
113 ntype.ui_name = "Glass BSDF";
114 ntype.ui_description = "Glass-like shader mixing refraction and reflection at grazing angles";
115 ntype.enum_name_legacy = "BSDF_GLASS";
117 ntype.declare = file_ns::node_declare;
120 ntype.draw_buttons = file_ns::node_shader_buts_glass;
121 ntype.initfunc = file_ns::node_shader_init_glass;
122 ntype.gpu_fn = file_ns::node_shader_gpu_bsdf_glass;
123 ntype.materialx_fn = file_ns::node_shader_materialx;
124
126}
#define NODE_CLASS_SHADER
Definition BKE_node.hh:460
#define SH_NODE_BSDF_GLASS
@ 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_REFRACTION_MAYBE_COLORED
@ GPU_MATFLAG_REFLECTION_MAYBE_COLORED
@ GPU_MATFLAG_GLOSSY
@ GPU_MATFLAG_REFRACT
void GPU_material_flag_set(GPUMaterial *mat, eGPUMaterialFlag flag)
bool GPU_link(GPUMaterial *mat, const char *name,...)
@ PROP_FACTOR
Definition RNA_types.hh:251
@ PROP_WAVELENGTH
Definition RNA_types.hh:287
@ UI_ITEM_R_SPLIT_EMPTY_NAME
DeclType::Builder & add_input(StringRef name, StringRef identifier="")
#define in
#define out
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_declare(NodeDeclarationBuilder &b)
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)
static void node_shader_buts_glass(uiLayout *layout, bContext *, PointerRNA *ptr)
#define NODE_SHADER_MATERIALX_BEGIN
#define NODE_SHADER_MATERIALX_END
void register_node_type_sh_bsdf_glass()
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