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