Blender V4.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
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{
25 node->custom1 = SHD_GLOSSY_MULTI_GGX;
26}
27
29 bNode *node,
30 bNodeExecData * /*execdata*/,
31 GPUNodeStack *in,
32 GPUNodeStack *out)
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, SH_NODE_BSDF_GLASS, "Glass BSDF", NODE_CLASS_SHADER);
78 ntype.declare = file_ns::node_declare;
81 ntype.initfunc = file_ns::node_shader_init_glass;
82 ntype.gpu_fn = file_ns::node_shader_gpu_bsdf_glass;
83 ntype.materialx_fn = file_ns::node_shader_materialx;
84
86}
#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
@ 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:154
local_group_size(16, 16) .push_constant(Type b
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_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, 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
NodeDeclareFunction declare
Definition BKE_node.hh:347