Blender
V4.5
source
blender
nodes
composite
nodes
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
9
#include "
BLI_math_vector.hh
"
10
#include "
BLI_math_vector_types.hh
"
11
12
#include "
FN_multi_function_builder.hh
"
13
14
#include "
BKE_node_runtime.hh
"
15
16
#include "
NOD_multi_function.hh
"
17
18
#include "
GPU_material.hh
"
19
20
#include "
node_composite_util.hh
"
21
22
/* **************** NORMAL ******************** */
23
24
namespace
blender::nodes::node_composite_normal_cc
{
25
26
static
void
cmp_node_normal_declare
(
NodeDeclarationBuilder
&
b
)
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)
32
.
subtype
(
PROP_DIRECTION
)
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)
38
.
subtype
(
PROP_DIRECTION
);
39
b
.add_output<
decl::Float
>(
"Dot"
);
40
}
41
42
using namespace
blender::compositor
;
43
44
/* The vector value is stored in the default value of the output socket. */
45
static
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
52
static
int
node_gpu_material
(
GPUMaterial
*
material
,
53
bNode
*
node
,
54
bNodeExecData
*
/*execdata*/
,
55
GPUNodeStack
*
inputs
,
56
GPUNodeStack
*
outputs
)
57
{
58
return
GPU_stack_link
(
material
,
59
node
,
60
"node_composite_normal"
,
61
inputs
,
62
outputs
,
63
GPU_uniform
(
get_vector_value
(*
node
)));
64
}
65
66
static
void
node_build_multi_function
(
blender::nodes::NodeMultiFunctionBuilder
&builder)
67
{
68
const
float3
normalized_node_normal =
get_vector_value
(builder.
node
());
69
70
builder.
construct_and_set_matching_fn_cb
([=]() {
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
83
static
void
register_node_type_cmp_normal
()
84
{
85
namespace
file_ns =
blender::nodes::node_composite_normal_cc
;
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"
;
93
ntype.
nclass
=
NODE_CLASS_OP_VECTOR
;
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
98
blender::bke::node_register_type
(ntype);
99
}
100
NOD_REGISTER_NODE
(
register_node_type_cmp_normal
)
NODE_CLASS_OP_VECTOR
#define NODE_CLASS_OP_VECTOR
Definition
BKE_node.hh:436
CMP_NODE_NORMAL
#define CMP_NODE_NORMAL
Definition
BKE_node_legacy_types.hh:155
BKE_node_runtime.hh
BLI_math_vector.hh
BLI_math_vector_types.hh
FN_multi_function_builder.hh
GPU_material.hh
GPU_stack_link
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
Definition
gpu_node_graph.cc:825
GPU_uniform
GPUNodeLink * GPU_uniform(const float *num)
Definition
gpu_node_graph.cc:636
NOD_multi_function.hh
NOD_REGISTER_NODE
#define NOD_REGISTER_NODE(REGISTER_FUNC)
Definition
NOD_register.hh:34
PROP_DIRECTION
@ PROP_DIRECTION
Definition
RNA_types.hh:250
blender::nodes::NodeDeclarationBuilder
Definition
NOD_node_declaration.hh:629
blender::nodes::NodeMultiFunctionBuilder
Definition
NOD_multi_function.hh:18
blender::nodes::NodeMultiFunctionBuilder::construct_and_set_matching_fn_cb
void construct_and_set_matching_fn_cb(Fn &&create_multi_function)
Definition
NOD_multi_function.hh:117
blender::nodes::NodeMultiFunctionBuilder::node
const bNode & node()
Definition
NOD_multi_function.hh:84
blender::nodes::decl::Float
Definition
NOD_socket_declarations.hh:19
blender::nodes::decl::Vector
Definition
NOD_socket_declarations.hh:77
blender::nodes::decl::Vector::subtype
PropertySubType subtype
Definition
NOD_socket_declarations.hh:85
b
b
Definition
compositor_morphological_distance_info.hh:24
dot
dot(value.rgb, luminance_coefficients)") DEFINE_VALUE("REDUCE(lhs
node
OperationNode * node
Definition
deg_builder_cycle.cc:38
material
Material material
Definition
deg_eval_copy_on_write.cc:96
blender::bke::node_register_type
void node_register_type(bNodeType &ntype)
Definition
node.cc:2748
blender::compositor
Definition
BKE_node.hh:76
blender::math::dot
T dot(const QuaternionBase< T > &a, const QuaternionBase< T > &b)
Definition
BLI_math_quaternion.hh:197
blender::math::normalize
MatBase< T, NumCol, NumRow > normalize(const MatBase< T, NumCol, NumRow > &a)
Definition
BLI_math_matrix.hh:778
blender::nodes::node_composite_normal_cc
Definition
node_composite_normal.cc:24
blender::nodes::node_composite_normal_cc::node_gpu_material
static int node_gpu_material(GPUMaterial *material, bNode *node, bNodeExecData *, GPUNodeStack *inputs, GPUNodeStack *outputs)
Definition
node_composite_normal.cc:52
blender::nodes::node_composite_normal_cc::node_build_multi_function
static void node_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder)
Definition
node_composite_normal.cc:66
blender::nodes::node_composite_normal_cc::cmp_node_normal_declare
static void cmp_node_normal_declare(NodeDeclarationBuilder &b)
Definition
node_composite_normal.cc:26
blender::nodes::node_composite_normal_cc::get_vector_value
static float3 get_vector_value(const bNode &node)
Definition
node_composite_normal.cc:45
register_node_type_cmp_normal
static void register_node_type_cmp_normal()
Definition
node_composite_normal.cc:83
cmp_node_type_base
void cmp_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
Definition
node_composite_util.cc:33
node_composite_util.hh
outputs
static blender::bke::bNodeSocketTemplate outputs[]
Definition
node_texture_at.cc:16
inputs
static blender::bke::bNodeSocketTemplate inputs[]
Definition
node_texture_at.cc:11
min
#define min(a, b)
Definition
sort.cc:36
GPUMaterial
Definition
gpu/intern/gpu_material.cc:60
GPUNodeStack
Definition
GPU_material.hh:272
bNodeExecData
Definition
node_util.hh:19
bNodeSocketValueVector
Definition
DNA_node_types.h:990
bNodeSocket
Definition
DNA_node_types.h:120
bNode
Definition
DNA_node_types.h:415
blender::VecBase< float, 3 >
blender::bke::bNodeType
Defines a node type.
Definition
BKE_node.hh:226
blender::bke::bNodeType::ui_description
std::string ui_description
Definition
BKE_node.hh:232
blender::bke::bNodeType::ui_name
std::string ui_name
Definition
BKE_node.hh:231
blender::bke::bNodeType::gpu_fn
NodeGPUExecFunction gpu_fn
Definition
BKE_node.hh:330
blender::bke::bNodeType::build_multi_function
NodeMultiFunctionBuildFunction build_multi_function
Definition
BKE_node.hh:344
blender::bke::bNodeType::nclass
short nclass
Definition
BKE_node.hh:239
blender::bke::bNodeType::enum_name_legacy
const char * enum_name_legacy
Definition
BKE_node.hh:235
blender::bke::bNodeType::declare
NodeDeclareFunction declare
Definition
BKE_node.hh:355
value
T value
Definition
usd_reader_camera.cc:34
Generated on Fri Apr 3 2026 06:33:18 for Blender by
doxygen
1.11.0