Blender V5.0
node_shader_normal.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
12
14{
15 b.add_input<decl::Vector>("Normal")
16 .default_value({0.0f, 0.0f, 1.0f})
17 .min(-1.0f)
18 .max(1.0f)
20 .description(
21 "Normal direction vector.\n"
22 "\u2022 LMB click and drag on the sphere to set the direction of the normal.\n"
23 "\u2022 Holding Ctrl while dragging snaps to 45 degree rotation increments");
24 b.add_output<decl::Vector>("Normal")
25 .default_value({0.0f, 0.0f, 1.0f})
26 .min(-1.0f)
27 .max(1.0f)
29 b.add_output<decl::Float>("Dot");
30}
31
33 bNode *node,
34 bNodeExecData * /*execdata*/,
37{
38 GPUNodeLink *vec = GPU_uniform(out[0].vec);
39 return GPU_stack_link(mat, node, "normal_new_shading", in, out, vec);
40}
41
43#ifdef WITH_MATERIALX
44{
45 NodeItem res = get_output_default("Normal", NodeItem::Type::Vector3);
46
47 if (STREQ(socket_out_->identifier, "Dot")) {
48 return res.dotproduct(get_input_value("Normal", NodeItem::Type::Vector3));
49 }
50
51 return res;
52}
53#endif
55
56} // namespace blender::nodes::node_shader_normal_cc
57
59{
60 namespace file_ns = blender::nodes::node_shader_normal_cc;
61
62 static blender::bke::bNodeType ntype;
63
64 sh_node_type_base(&ntype, "ShaderNodeNormal", SH_NODE_NORMAL);
65 ntype.ui_name = "Normal";
66 ntype.ui_description = "Generate a normal vector and a dot product";
67 ntype.enum_name_legacy = "NORMAL";
69 ntype.declare = file_ns::node_declare;
70 ntype.gpu_fn = file_ns::gpu_shader_normal;
71 ntype.materialx_fn = file_ns::node_shader_materialx;
72
74}
#define NODE_CLASS_OP_VECTOR
Definition BKE_node.hh:450
#define SH_NODE_NORMAL
#define STREQ(a, b)
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
GPUNodeLink * GPU_uniform(const float *num)
@ PROP_DIRECTION
Definition RNA_types.hh:262
#define in
#define out
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
static void node_declare(NodeDeclarationBuilder &b)
static int gpu_shader_normal(GPUMaterial *mat, bNode *node, bNodeExecData *, GPUNodeStack *in, GPUNodeStack *out)
#define NODE_SHADER_MATERIALX_BEGIN
#define NODE_SHADER_MATERIALX_END
void register_node_type_sh_normal()
void sh_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
#define min(a, b)
Definition sort.cc:36
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
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