Blender V5.0
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
5#include "node_shader_util.hh"
6
7#include "BLI_math_vector.h"
8
10
12{
13 b.add_input<decl::Color>("Color").default_value({1.0f, 1.0f, 1.0f, 1.0f});
14 b.add_input<decl::Float>("Weight").available(false);
15 b.add_output<decl::Shader>("BSDF");
16}
17
19 bNode *node,
20 bNodeExecData * /*execdata*/,
23{
24 if (in[0].link || !is_zero_v3(in[0].vec)) {
26 }
27 return GPU_stack_link(mat, node, "node_bsdf_transparent", in, out);
28}
29
31#ifdef WITH_MATERIALX
32{
33 switch (to_type_) {
34 case NodeItem::Type::BSDF: {
35 NodeItem color = get_input_value("Color", NodeItem::Type::Color3);
36 /* Returning diffuse node as BSDF component */
37 return create_node("oren_nayar_diffuse_bsdf", NodeItem::Type::BSDF, {{"color", color}});
38 }
39 case NodeItem::Type::SurfaceOpacity: {
40 NodeItem color = get_input_value("Color", NodeItem::Type::Color3);
41 /* Returning: 1 - <average of color components> */
42 return val(1.0f) - color.dotproduct(val(1.0f / 3.0f));
43 }
44 default:
45 break;
46 }
47 return empty();
48}
49#endif
51
52} // namespace blender::nodes::node_shader_bsdf_transparent_cc
53
54/* node type definition */
56{
58
59 static blender::bke::bNodeType ntype;
60
61 sh_node_type_base(&ntype, "ShaderNodeBsdfTransparent", SH_NODE_BSDF_TRANSPARENT);
62 ntype.ui_name = "Transparent BSDF";
63 ntype.ui_description =
64 "Transparency without refraction, passing straight through the surface as if there were no "
65 "geometry";
66 ntype.enum_name_legacy = "BSDF_TRANSPARENT";
69 ntype.declare = file_ns::node_declare;
70 ntype.gpu_fn = file_ns::node_shader_gpu_bsdf_transparent;
71 ntype.materialx_fn = file_ns::node_shader_materialx;
72
74}
#define NODE_CLASS_SHADER
Definition BKE_node.hh:460
#define SH_NODE_BSDF_TRANSPARENT
MINLINE bool is_zero_v3(const float v[3]) ATTR_WARN_UNUSED_RESULT
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
@ GPU_MATFLAG_TRANSPARENT
void GPU_material_flag_set(GPUMaterial *mat, eGPUMaterialFlag flag)
#define in
#define out
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
static int node_shader_gpu_bsdf_transparent(GPUMaterial *mat, bNode *node, bNodeExecData *, GPUNodeStack *in, GPUNodeStack *out)
#define NODE_SHADER_MATERIALX_BEGIN
#define NODE_SHADER_MATERIALX_END
void register_node_type_sh_bsdf_transparent()
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)
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
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