Blender V5.3
node_shader_bsdf_ray_portal.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::Vector>("Position"_ustr).hide_value();
24 b.add_input<decl::Vector>("Direction"_ustr).hide_value();
25 b.add_input<decl::Float>("Weight"_ustr).available(is_gpu_internal);
26 b.add_output<decl::Shader>("BSDF"_ustr);
27}
28
30 bNode *node,
31 bNodeExecData * /*execdata*/,
34{
35 if (in[0].link || !is_zero_v3(std::get<float4>(in[0].value))) {
37 }
38 return GPU_stack_link(
39 mat, node, "node_bsdf_ray_portal", in, out, GPU_kernel_globals(), GPU_shading_data());
40}
41
43#ifdef WITH_MATERIALX
44{
45 switch (to_type_) {
46 case NodeItem::Type::BSDF: {
47 NodeItem color = get_input_value("Color", NodeItem::Type::Color3);
48 /* Returning diffuse node as BSDF component */
49 return create_node("oren_nayar_diffuse_bsdf", NodeItem::Type::BSDF, {{"color", color}});
50 }
51 case NodeItem::Type::SurfaceOpacity: {
52 NodeItem color = get_input_value("Color", NodeItem::Type::Color3);
53 /* Returning: 1 - <average of color components> */
54 return val(1.0f) - color.dotproduct(val(1.0f / 3.0f));
55 }
56 default:
57 break;
58 }
59 return empty();
60}
61#endif
63
64} // namespace nodes::node_shader_bsdf_ray_portal_cc
65
66/* node type definition */
68{
69 namespace file_ns = nodes::node_shader_bsdf_ray_portal_cc;
70
71 static bke::bNodeType ntype;
72
73 sh_node_type_base(&ntype, "ShaderNodeBsdfRayPortal"_ustr, SH_NODE_BSDF_RAY_PORTAL);
74 ntype.ui_name = "Ray Portal BSDF";
75 ntype.ui_description = "Continue tracing from an arbitrary new position and in a new direction";
76 ntype.enum_name_legacy = "BSDF_RAY_PORTAL";
79 ntype.declare = file_ns::node_declare;
81 ntype.gpu_fn = file_ns::node_shader_gpu_bsdf_ray_portal;
82 ntype.materialx_fn = file_ns::node_shader_materialx;
83
85}
86
87} // namespace blender
#define NODE_CLASS_SHADER
Definition BKE_node.hh:491
#define SH_NODE_BSDF_RAY_PORTAL
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
static int node_shader_gpu_bsdf_ray_portal(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_cycles_shader_nodes_poll(const bContext *C)
@ 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 GPU_material_flag_set(GPUMaterial *mat, eGPUMaterialFlag flag)
void register_node_type_sh_bsdf_ray_portal()
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