Blender V4.5
node_shader_bsdf_refraction.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.45f).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_refraction(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 return GPU_stack_link(mat, node, "node_bsdf_refraction", in, out);
41}
42
44#ifdef WITH_MATERIALX
45{
46 if (to_type_ != NodeItem::Type::BSDF) {
47 return empty();
48 }
49
50 NodeItem color = get_input_value("Color", NodeItem::Type::Color3);
51 NodeItem roughness = get_input_value("Roughness", NodeItem::Type::Vector2);
52 NodeItem ior = get_input_value("IOR", NodeItem::Type::Float);
53 NodeItem normal = get_input_link("Normal", NodeItem::Type::Vector3);
54
55 return create_node("dielectric_bsdf",
56 NodeItem::Type::BSDF,
57 {{"normal", normal},
58 {"tint", color},
59 {"roughness", roughness},
60 {"ior", ior},
61 {"scatter_mode", val(std::string("T"))}});
62}
63#endif
65
66} // namespace blender::nodes::node_shader_bsdf_refraction_cc
67
68/* node type definition */
70{
72
73 static blender::bke::bNodeType ntype;
74
75 sh_node_type_base(&ntype, "ShaderNodeBsdfRefraction", SH_NODE_BSDF_REFRACTION);
76 ntype.ui_name = "Refraction BSDF";
77 ntype.ui_description =
78 "Glossy refraction with sharp or microfacet distribution, typically used for materials that "
79 "transmit light";
80 ntype.enum_name_legacy = "BSDF_REFRACTION";
82 ntype.declare = file_ns::node_declare;
85 ntype.initfunc = file_ns::node_shader_init_refraction;
86 ntype.gpu_fn = file_ns::node_shader_gpu_bsdf_refraction;
87 ntype.materialx_fn = file_ns::node_shader_materialx;
88
90}
#define NODE_CLASS_SHADER
Definition BKE_node.hh:446
#define SH_NODE_BSDF_REFRACTION
@ SHD_GLOSSY_BECKMANN
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
@ 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_shader_init_refraction(bNodeTree *, bNode *node)
static int node_shader_gpu_bsdf_refraction(GPUMaterial *mat, bNode *node, bNodeExecData *, GPUNodeStack *in, GPUNodeStack *out)
static void node_declare(NodeDeclarationBuilder &b)
#define NODE_SHADER_MATERIALX_BEGIN
#define NODE_SHADER_MATERIALX_END
void register_node_type_sh_bsdf_refraction()
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