Blender V4.5
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.add_input<decl::Vector>("Normal")
29 .default_value({0.0f, 0.0f, 1.0f})
30 .min(-1.0f)
31 .max(1.0f)
33 .compositor_domain_priority(0);
34 b.add_output<decl::Vector>("Normal")
35 .default_value({0.0f, 0.0f, 1.0f})
36 .min(-1.0f)
37 .max(1.0f)
39 b.add_output<decl::Float>("Dot");
40}
41
42using namespace blender::compositor;
43
44/* The vector value is stored in the default value of the output socket. */
45static float3 get_vector_value(const bNode &node)
46{
47 const bNodeSocket &normal_output = node.output_by_identifier("Normal");
48 const float3 node_normal = normal_output.default_value_typed<bNodeSocketValueVector>()->value;
49 return math::normalize(node_normal);
50}
51
52static int node_gpu_material(GPUMaterial *material,
53 bNode *node,
54 bNodeExecData * /*execdata*/,
57{
58 return GPU_stack_link(material,
59 node,
60 "node_composite_normal",
61 inputs,
62 outputs,
64}
65
67{
68 const float3 normalized_node_normal = get_vector_value(builder.node());
69
71 return mf::build::SI1_SO2<float3, float3, float>(
72 "Normal And Dot",
73 [=](const float3 &normal, float3 &output_normal, float &dot) -> void {
74 output_normal = normalized_node_normal;
75 dot = -math::dot(normal, normalized_node_normal);
76 },
77 mf::build::exec_presets::AllSpanOrSingle());
78 });
79}
80
81} // namespace blender::nodes::node_composite_normal_cc
82
84{
86
87 static blender::bke::bNodeType ntype;
88
89 cmp_node_type_base(&ntype, "CompositorNodeNormal", CMP_NODE_NORMAL);
90 ntype.ui_name = "Normal";
91 ntype.ui_description = "Generate a normal vector and a dot product";
92 ntype.enum_name_legacy = "NORMAL";
94 ntype.declare = file_ns::cmp_node_normal_declare;
95 ntype.gpu_fn = file_ns::node_gpu_material;
96 ntype.build_multi_function = file_ns::node_build_multi_function;
97
99}
#define NODE_CLASS_OP_VECTOR
Definition BKE_node.hh:436
#define CMP_NODE_NORMAL
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
GPUNodeLink * GPU_uniform(const float *num)
#define NOD_REGISTER_NODE(REGISTER_FUNC)
@ PROP_DIRECTION
Definition RNA_types.hh:250
void construct_and_set_matching_fn_cb(Fn &&create_multi_function)
dot(value.rgb, luminance_coefficients)") DEFINE_VALUE("REDUCE(lhs
void node_register_type(bNodeType &ntype)
Definition node.cc:2748
T dot(const QuaternionBase< T > &a, const QuaternionBase< T > &b)
MatBase< T, NumCol, NumRow > normalize(const MatBase< T, NumCol, NumRow > &a)
static int node_gpu_material(GPUMaterial *material, bNode *node, bNodeExecData *, GPUNodeStack *inputs, GPUNodeStack *outputs)
static void node_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder)
static void cmp_node_normal_declare(NodeDeclarationBuilder &b)
static float3 get_vector_value(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[]
static blender::bke::bNodeSocketTemplate inputs[]
#define min(a, b)
Definition sort.cc:36
Defines a node type.
Definition BKE_node.hh:226
std::string ui_description
Definition BKE_node.hh:232
NodeGPUExecFunction gpu_fn
Definition BKE_node.hh:330
NodeMultiFunctionBuildFunction build_multi_function
Definition BKE_node.hh:344
const char * enum_name_legacy
Definition BKE_node.hh:235
NodeDeclareFunction declare
Definition BKE_node.hh:355