Blender V5.0
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
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::Vector>("Position").hide_value();
15 b.add_input<decl::Vector>("Direction").hide_value();
16 b.add_input<decl::Float>("Weight").available(false);
17 b.add_output<decl::Shader>("BSDF");
18}
19
21 bNode *node,
22 bNodeExecData * /*execdata*/,
25{
26 if (in[0].link || !is_zero_v3(in[0].vec)) {
28 }
29 return GPU_stack_link(mat, node, "node_bsdf_ray_portal", in, out);
30}
31
33#ifdef WITH_MATERIALX
34{
35 switch (to_type_) {
36 case NodeItem::Type::BSDF: {
37 NodeItem color = get_input_value("Color", NodeItem::Type::Color3);
38 /* Returning diffuse node as BSDF component */
39 return create_node("oren_nayar_diffuse_bsdf", NodeItem::Type::BSDF, {{"color", color}});
40 }
41 case NodeItem::Type::SurfaceOpacity: {
42 NodeItem color = get_input_value("Color", NodeItem::Type::Color3);
43 /* Returning: 1 - <average of color components> */
44 return val(1.0f) - color.dotproduct(val(1.0f / 3.0f));
45 }
46 default:
47 break;
48 }
49 return empty();
50}
51#endif
53
54} // namespace blender::nodes::node_shader_bsdf_ray_portal_cc
55
56/* node type definition */
58{
60
61 static blender::bke::bNodeType ntype;
62
63 sh_node_type_base(&ntype, "ShaderNodeBsdfRayPortal", SH_NODE_BSDF_RAY_PORTAL);
64 ntype.ui_name = "Ray Portal BSDF";
65 ntype.ui_description = "Continue tracing from an arbitrary new position and in a new direction";
66 ntype.enum_name_legacy = "BSDF_RAY_PORTAL";
69 ntype.declare = file_ns::node_declare;
70 ntype.gpu_fn = file_ns::node_shader_gpu_bsdf_ray_portal;
71 ntype.materialx_fn = file_ns::node_shader_materialx;
72
74}
#define NODE_CLASS_SHADER
Definition BKE_node.hh:460
#define SH_NODE_BSDF_RAY_PORTAL
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_ray_portal(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_ray_portal()
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