Blender V5.3
node_shader_bsdf_transparent.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
11#include "BLI_math_vector_c.hh"
12
13namespace blender {
14
16
18{
19 const bNodeTree *ntree = b.tree_or_null();
20 const bool is_gpu_internal = ntree && (ntree->flag & NTREE_IS_GPU_SHADER_INTERNAL);
21
22 b.add_input<decl::Color>("Color"_ustr).default_value({1.0f, 1.0f, 1.0f, 1.0f});
23 b.add_input<decl::Float>("Weight"_ustr).available(is_gpu_internal);
24 b.add_output<decl::Shader>("BSDF"_ustr);
25}
26
28 bNode *node,
29 bNodeExecData * /*execdata*/,
32{
33 if (in[0].link || !is_zero_v3(std::get<float4>(in[0].value))) {
35
36 if (in[0].might_be_tinted()) {
38 }
39 }
40 return GPU_stack_link(
41 mat, node, "node_bsdf_transparent", in, out, GPU_kernel_globals(), GPU_shading_data());
42}
43
45#ifdef WITH_MATERIALX
46{
47 switch (to_type_) {
48 case NodeItem::Type::BSDF: {
49 NodeItem color = get_input_value("Color", NodeItem::Type::Color3);
50 /* Returning diffuse node as BSDF component */
51 return create_node("oren_nayar_diffuse_bsdf", NodeItem::Type::BSDF, {{"color", color}});
52 }
53 case NodeItem::Type::SurfaceOpacity: {
54 NodeItem color = get_input_value("Color", NodeItem::Type::Color3);
55 /* Returning: 1 - <average of color components> */
56 return val(1.0f) - color.dotproduct(val(1.0f / 3.0f));
57 }
58 default:
59 break;
60 }
61 return empty();
62}
63#endif
65
66} // namespace nodes::node_shader_bsdf_transparent_cc
67
68/* node type definition */
70{
72
73 static bke::bNodeType ntype;
74
75 sh_node_type_base(&ntype, "ShaderNodeBsdfTransparent"_ustr, SH_NODE_BSDF_TRANSPARENT);
76 ntype.ui_name = "Transparent BSDF";
77 ntype.ui_description =
78 "Transparency without refraction, passing straight through the surface as if there were no "
79 "geometry";
80 ntype.enum_name_legacy = "BSDF_TRANSPARENT";
83 ntype.declare = file_ns::node_declare;
85 ntype.gpu_fn = file_ns::node_shader_gpu_bsdf_transparent;
86 ntype.materialx_fn = file_ns::node_shader_materialx;
87
89}
90
91} // namespace blender
#define NODE_CLASS_SHADER
Definition BKE_node.hh:491
#define SH_NODE_BSDF_TRANSPARENT
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
static int node_shader_gpu_bsdf_transparent(GPUMaterial *mat, bNode *node, bNodeExecData *, GPUNodeStack *in, GPUNodeStack *out)
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_TRANSPARENT_MAYBE_COLORED
@ GPU_MATFLAG_TRANSPARENT
void sh_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
void search_link_ops_for_shader_bsdf_node(nodes::GatherLinkSearchOpParams &params)
void register_node_type_sh_bsdf_transparent()
void GPU_material_flag_set(GPUMaterial *mat, eGPUMaterialFlag flag)
GPUNodeLink * GPU_shading_data()
@ NTREE_IS_GPU_SHADER_INTERNAL
GPUNodeLink * GPU_kernel_globals()
MINLINE bool is_zero_v3(const float v[3]) ATTR_WARN_UNUSED_RESULT
#define NODE_SHADER_MATERIALX_BEGIN
#define NODE_SHADER_MATERIALX_END
eNodeTree_Flag flag
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
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