Blender V5.3
node_composite_normal.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2006 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "BLI_math_vector.hh"
7
9
10#include "BKE_node_runtime.hh"
11
12#include "NOD_multi_function.hh"
13
14#include "GPU_material.hh"
15
17
19
21{
22 b.is_function_node();
23 b.add_output<decl::Vector>("Normal"_ustr)
24 .default_value({0.0f, 0.0f, 1.0f})
25 .min(-1.0f)
26 .max(1.0f)
27 .subtype(PROP_DIRECTION);
28}
29
30using namespace blender::compositor;
31
32/* The vector value is stored in the default value of the output socket. */
34{
35 const bNodeSocket &normal_output = *node.output_by_identifier("Normal"_ustr);
36 const float3 node_normal = normal_output.default_value_typed<bNodeSocketValueVector>()->value;
37 return math::normalize(node_normal);
38}
39
40static int node_gpu_material(GPUMaterial *material,
41 bNode *node,
42 bNodeExecData * /*execdata*/,
43 GPUNodeStack * /*inputs*/,
44 GPUNodeStack *outputs)
45{
46 const float3 normal = get_normal(*node);
47 return GPU_link(material, "set_vector", GPU_uniform(normal), &outputs->link);
48}
49
51{
52 const float3 normal = get_normal(builder.node());
53 builder.construct_and_set_matching_fn<mf::CustomMF_Constant<float3>>(normal);
54}
55
56static void node_register()
57{
58 static bke::bNodeType ntype;
59
60 cmp_node_type_base(&ntype, "CompositorNodeNormal"_ustr, CMP_NODE_NORMAL);
61 ntype.ui_name = "Normal";
62 ntype.ui_description = "Input normalized normal values to other nodes in the tree";
63 ntype.enum_name_legacy = "NORMAL";
65 ntype.declare = node_declare;
68
70}
72
73} // namespace blender::nodes::node_composite_normal_cc
#define NODE_CLASS_INPUT
Definition BKE_node.hh:478
#define CMP_NODE_NORMAL
#define NOD_REGISTER_NODE(REGISTER_FUNC)
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
MatBase< T, NumCol, NumRow > normalize(const MatBase< T, NumCol, NumRow > &a)
static int node_gpu_material(GPUMaterial *material, bNode *node, bNodeExecData *, GPUNodeStack *, GPUNodeStack *outputs)
static void node_declare(NodeDeclarationBuilder &b)
static float3 get_normal(const bNode &node)
static void node_build_multi_function(nodes::NodeMultiFunctionBuilder &builder)
GPUNodeLink * GPU_uniform(const float *num)
bool GPU_link(GPUMaterial *mat, const char *name,...)
@ PROP_DIRECTION
Definition RNA_types.hh:319
void cmp_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
#define min(a, b)
Definition sort.cc:38
Defines a node type.
Definition BKE_node.hh:265
std::string ui_description
Definition BKE_node.hh:271
NodeGPUExecFunction gpu_fn
Definition BKE_node.hh:373
NodeMultiFunctionBuildFunction build_multi_function
Definition BKE_node.hh:382
const char * enum_name_legacy
Definition BKE_node.hh:274
NodeDeclareFunction declare
Definition BKE_node.hh:393