Blender V5.3
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
8
9#include "node_shader_util.hh"
10
11namespace blender {
12
14
16{
17 const bNodeTree *ntree = b.tree_or_null();
18 const bool is_gpu_internal = ntree && (ntree->flag & NTREE_IS_GPU_SHADER_INTERNAL);
19
20 b.add_input<decl::Color>("Color"_ustr).default_value({1.0f, 1.0f, 1.0f, 1.0f});
21 b.add_input<decl::Float>("Roughness"_ustr)
22 .default_value(0.0f)
23 .min(0.0f)
24 .max(1.0f)
26 b.add_input<decl::Float>("IOR"_ustr).default_value(1.45f).min(0.0f).max(1000.0f);
27 b.add_input<decl::Vector>("Normal"_ustr).hide_value();
28 b.add_input<decl::Float>("Weight"_ustr).available(is_gpu_internal);
29 b.add_output<decl::Shader>("BSDF"_ustr);
30}
31
33{
34 node->custom1 = SHD_GLOSSY_BECKMANN;
35}
36
38 bNode *node,
39 bNodeExecData * /*execdata*/,
42{
43 if (!in[3].link) {
44 GPU_link(mat, "world_normals_get", GPU_shading_data(), &in[3].link);
45 }
46
48 if (in[0].might_be_tinted()) {
50 }
51
52 return GPU_stack_link(
53 mat, node, "node_bsdf_refraction", in, out, GPU_kernel_globals(), GPU_shading_data());
54}
55
57#ifdef WITH_MATERIALX
58{
59 if (to_type_ != NodeItem::Type::BSDF) {
60 return empty();
61 }
62
63 NodeItem color = get_input_value("Color", NodeItem::Type::Color3);
64 NodeItem roughness = get_input_value("Roughness", NodeItem::Type::Vector2);
65 NodeItem ior = get_input_value("IOR", NodeItem::Type::Float);
66 NodeItem normal = get_input_link("Normal", NodeItem::Type::Vector3);
67
68 return create_node("dielectric_bsdf",
69 NodeItem::Type::BSDF,
70 {{"normal", normal},
71 {"tint", color},
72 {"roughness", roughness},
73 {"ior", ior},
74 {"scatter_mode", val(std::string("T"))}});
75}
76#endif
78
79} // namespace nodes::node_shader_bsdf_refraction_cc
80
81/* node type definition */
83{
84 namespace file_ns = nodes::node_shader_bsdf_refraction_cc;
85
86 static bke::bNodeType ntype;
87
88 sh_node_type_base(&ntype, "ShaderNodeBsdfRefraction"_ustr, SH_NODE_BSDF_REFRACTION);
89 ntype.ui_name = "Refraction BSDF";
90 ntype.ui_description =
91 "Glossy refraction with sharp or microfacet distribution, typically used for materials that "
92 "transmit light";
93 ntype.enum_name_legacy = "BSDF_REFRACTION";
95 ntype.declare = file_ns::node_declare;
99 ntype.initfunc = file_ns::node_shader_init_refraction;
100 ntype.gpu_fn = file_ns::node_shader_gpu_bsdf_refraction;
101 ntype.materialx_fn = file_ns::node_shader_materialx;
102
104}
105
106} // namespace blender
#define NODE_CLASS_SHADER
Definition BKE_node.hh:491
#define SH_NODE_BSDF_REFRACTION
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
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)
BMesh Iterators.
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
bool object_shader_nodes_poll(const bContext *C)
@ GPU_MATFLAG_REFRACT
@ GPU_MATFLAG_REFRACTION_MAYBE_COLORED
void sh_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
void register_node_type_sh_bsdf_refraction()
bool GPU_link(GPUMaterial *mat, const char *name,...)
void search_link_ops_for_shader_bsdf_node(nodes::GatherLinkSearchOpParams &params)
void GPU_material_flag_set(GPUMaterial *mat, eGPUMaterialFlag flag)
GPUNodeLink * GPU_shading_data()
@ NTREE_IS_GPU_SHADER_INTERNAL
GPUNodeLink * GPU_kernel_globals()
@ PROP_FACTOR
Definition RNA_types.hh:308
@ SHD_GLOSSY_BECKMANN
#define NODE_SHADER_MATERIALX_BEGIN
#define NODE_SHADER_MATERIALX_END
eNodeTree_Flag flag
static constexpr int _160
Definition BKE_node.hh:246
Defines a node type.
Definition BKE_node.hh:265
NodeMaterialXFunction materialx_fn
Definition BKE_node.hh:375
std::string ui_description
Definition BKE_node.hh:271
NodeGPUExecFunction gpu_fn
Definition BKE_node.hh:373
void(*) initfunc(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:320
const char * enum_name_legacy
Definition BKE_node.hh:274
NodeGatherSocketLinkOperationsFunction gather_link_search_ops
Definition BKE_node.hh:409
NodeDeclareFunction declare
Definition BKE_node.hh:393
bool(*) add_ui_poll(const bContext *C)
Definition BKE_node.hh:341