Blender V4.5
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
5#include "node_shader_util.hh"
6
8
10{
11 b.add_input<decl::Color>("Color").default_value({1.0f, 1.0f, 1.0f, 1.0f});
12 b.add_input<decl::Float>("Roughness")
13 .default_value(0.0f)
14 .min(0.0f)
15 .max(1.0f)
17 b.add_input<decl::Float>("IOR").default_value(1.5f).min(0.0f).max(1000.0f);
18 b.add_input<decl::Vector>("Normal").hide_value();
19 b.add_input<decl::Float>("Weight").available(false);
20 b.add_output<decl::Shader>("BSDF");
21}
22
23static void node_shader_init_glass(bNodeTree * /*ntree*/, bNode *node)
24{
26}
27
29 bNode *node,
30 bNodeExecData * /*execdata*/,
33{
34 if (!in[3].link) {
35 GPU_link(mat, "world_normals_get", &in[3].link);
36 }
37
39
40 float use_multi_scatter = (node->custom1 == SHD_GLOSSY_MULTI_GGX) ? 1.0f : 0.0f;
41
42 return GPU_stack_link(mat, node, "node_bsdf_glass", in, out, GPU_constant(&use_multi_scatter));
43}
44
46#ifdef WITH_MATERIALX
47{
48 if (to_type_ != NodeItem::Type::BSDF) {
49 return empty();
50 }
51
52 NodeItem color = get_input_value("Color", NodeItem::Type::Color3);
53 NodeItem roughness = get_input_value("Roughness", NodeItem::Type::Vector2);
54 NodeItem ior = get_input_value("IOR", NodeItem::Type::Float);
55 NodeItem normal = get_input_link("Normal", NodeItem::Type::Vector3);
56
57 return create_node("dielectric_bsdf",
58 NodeItem::Type::BSDF,
59 {{"normal", normal},
60 {"tint", color},
61 {"roughness", roughness},
62 {"ior", ior},
63 {"scatter_mode", val(std::string("RT"))}});
64}
65#endif
67
68} // namespace blender::nodes::node_shader_bsdf_glass_cc
69
70/* node type definition */
72{
74
75 static blender::bke::bNodeType ntype;
76
77 sh_node_type_base(&ntype, "ShaderNodeBsdfGlass", SH_NODE_BSDF_GLASS);
78 ntype.ui_name = "Glass BSDF";
79 ntype.ui_description = "Glass-like shader mixing refraction and reflection at grazing angles";
80 ntype.enum_name_legacy = "BSDF_GLASS";
82 ntype.declare = file_ns::node_declare;
85 ntype.initfunc = file_ns::node_shader_init_glass;
86 ntype.gpu_fn = file_ns::node_shader_gpu_bsdf_glass;
87 ntype.materialx_fn = file_ns::node_shader_materialx;
88
90}
#define NODE_CLASS_SHADER
Definition BKE_node.hh:446
#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_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:239
#define in
#define out
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_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)
#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: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
NodeDeclareFunction declare
Definition BKE_node.hh:355