Blender V5.0
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 if (in[0].might_be_tinted()) {
41 }
42
43 return GPU_stack_link(mat, node, "node_bsdf_refraction", in, out);
44}
45
47#ifdef WITH_MATERIALX
48{
49 if (to_type_ != NodeItem::Type::BSDF) {
50 return empty();
51 }
52
53 NodeItem color = get_input_value("Color", NodeItem::Type::Color3);
54 NodeItem roughness = get_input_value("Roughness", NodeItem::Type::Vector2);
55 NodeItem ior = get_input_value("IOR", NodeItem::Type::Float);
56 NodeItem normal = get_input_link("Normal", NodeItem::Type::Vector3);
57
58 return create_node("dielectric_bsdf",
59 NodeItem::Type::BSDF,
60 {{"normal", normal},
61 {"tint", color},
62 {"roughness", roughness},
63 {"ior", ior},
64 {"scatter_mode", val(std::string("T"))}});
65}
66#endif
68
69} // namespace blender::nodes::node_shader_bsdf_refraction_cc
70
71/* node type definition */
73{
75
76 static blender::bke::bNodeType ntype;
77
78 sh_node_type_base(&ntype, "ShaderNodeBsdfRefraction", SH_NODE_BSDF_REFRACTION);
79 ntype.ui_name = "Refraction BSDF";
80 ntype.ui_description =
81 "Glossy refraction with sharp or microfacet distribution, typically used for materials that "
82 "transmit light";
83 ntype.enum_name_legacy = "BSDF_REFRACTION";
85 ntype.declare = file_ns::node_declare;
88 ntype.initfunc = file_ns::node_shader_init_refraction;
89 ntype.gpu_fn = file_ns::node_shader_gpu_bsdf_refraction;
90 ntype.materialx_fn = file_ns::node_shader_materialx;
91
93}
#define NODE_CLASS_SHADER
Definition BKE_node.hh:460
#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_REFRACTION_MAYBE_COLORED
@ 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
#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_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: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
NodeDeclareFunction declare
Definition BKE_node.hh:362