Blender V5.0
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
8
9#include "BLI_math_vector.hh"
11
13
14#include "BKE_node_runtime.hh"
15
16#include "NOD_multi_function.hh"
17
18#include "GPU_material.hh"
19
21
22/* **************** NORMAL ******************** */
23
25
27{
28 b.is_function_node();
29 b.add_output<decl::Vector>("Normal")
30 .default_value({0.0f, 0.0f, 1.0f})
31 .min(-1.0f)
32 .max(1.0f)
34}
35
36using namespace blender::compositor;
37
38/* The vector value is stored in the default value of the output socket. */
39static float3 get_normal(const bNode &node)
40{
41 const bNodeSocket &normal_output = *node.output_by_identifier("Normal");
42 const float3 node_normal = normal_output.default_value_typed<bNodeSocketValueVector>()->value;
43 return math::normalize(node_normal);
44}
45
46static int node_gpu_material(GPUMaterial *material,
47 bNode *node,
48 bNodeExecData * /*execdata*/,
49 GPUNodeStack * /*inputs*/,
51{
52 const float3 normal = get_normal(*node);
53 return GPU_link(material, "set_vector", GPU_uniform(normal), &outputs->link);
54}
55
57{
58 const float3 normal = get_normal(builder.node());
59 builder.construct_and_set_matching_fn<mf::CustomMF_Constant<float3>>(normal);
60}
61
62} // namespace blender::nodes::node_composite_normal_cc
63
65{
67
68 static blender::bke::bNodeType ntype;
69
70 cmp_node_type_base(&ntype, "CompositorNodeNormal", CMP_NODE_NORMAL);
71 ntype.ui_name = "Normal";
72 ntype.ui_description = "Input normalized normal values to other nodes in the tree";
73 ntype.enum_name_legacy = "NORMAL";
75 ntype.declare = file_ns::cmp_node_normal_declare;
76 ntype.gpu_fn = file_ns::node_gpu_material;
77 ntype.build_multi_function = file_ns::node_build_multi_function;
78
80}
#define NODE_CLASS_INPUT
Definition BKE_node.hh:447
#define CMP_NODE_NORMAL
bool GPU_link(GPUMaterial *mat, const char *name,...)
GPUNodeLink * GPU_uniform(const float *num)
#define NOD_REGISTER_NODE(REGISTER_FUNC)
@ PROP_DIRECTION
Definition RNA_types.hh:262
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
MatBase< T, NumCol, NumRow > normalize(const MatBase< T, NumCol, NumRow > &a)
static void node_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder)
static void cmp_node_normal_declare(NodeDeclarationBuilder &b)
static int node_gpu_material(GPUMaterial *material, bNode *node, bNodeExecData *, GPUNodeStack *, GPUNodeStack *outputs)
static float3 get_normal(const bNode &node)
VecBase< float, 3 > float3
static void register_node_type_cmp_normal()
void cmp_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
static blender::bke::bNodeSocketTemplate outputs[]
#define min(a, b)
Definition sort.cc:36
Defines a node type.
Definition BKE_node.hh:238
std::string ui_description
Definition BKE_node.hh:244
NodeGPUExecFunction gpu_fn
Definition BKE_node.hh:342
NodeMultiFunctionBuildFunction build_multi_function
Definition BKE_node.hh:351
const char * enum_name_legacy
Definition BKE_node.hh:247
NodeDeclareFunction declare
Definition BKE_node.hh:362