Blender V4.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
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{
25 node->custom1 = SHD_GLOSSY_BECKMANN;
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 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, SH_NODE_BSDF_REFRACTION, "Refraction BSDF", NODE_CLASS_SHADER);
76 ntype.declare = file_ns::node_declare;
79 ntype.initfunc = file_ns::node_shader_init_refraction;
80 ntype.gpu_fn = file_ns::node_shader_gpu_bsdf_refraction;
81 ntype.materialx_fn = file_ns::node_shader_materialx;
82
84}
#define NODE_CLASS_SHADER
Definition BKE_node.hh:417
@ 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: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_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, 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