Blender
V5.0
source
blender
nodes
composite
nodes
node_composite_brightness.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 <limits>
10
11
#include "
BLI_math_color.h
"
12
#include "
BLI_math_vector_types.hh
"
13
14
#include "
FN_multi_function_builder.hh
"
15
16
#include "
NOD_multi_function.hh
"
17
18
#include "
UI_resources.hh
"
19
20
#include "
GPU_material.hh
"
21
22
#include "
node_composite_util.hh
"
23
24
/* **************** Brightness and Contrast ******************** */
25
26
namespace
blender::nodes::node_composite_brightness_cc
{
27
28
static
void
cmp_node_brightcontrast_declare
(
NodeDeclarationBuilder
&
b
)
29
{
30
b
.use_custom_socket_order();
31
b
.allow_any_socket_order();
32
b
.is_function_node();
33
b
.add_input<
decl::Color
>(
"Image"
).default_value({1.0f, 1.0f, 1.0f, 1.0f}).hide_value();
34
b
.add_output<
decl::Color
>(
"Image"
).align_with_previous();
35
36
b
.add_input<
decl::Float
>(
"Brightness"
,
"Bright"
).
min
(-100.0f).max(100.0f);
37
b
.add_input<
decl::Float
>(
"Contrast"
).
min
(-100.0f).max(100.0f);
38
}
39
40
using namespace
blender::compositor
;
41
42
static
int
node_gpu_material
(
GPUMaterial
*material,
43
bNode
*node,
44
bNodeExecData
*
/*execdata*/
,
45
GPUNodeStack
*
inputs
,
46
GPUNodeStack
*
outputs
)
47
{
48
return
GPU_stack_link
(material, node,
"node_composite_bright_contrast"
,
inputs
,
outputs
);
49
}
50
51
/* The algorithm is by Werner D. Streidt, extracted of OpenCV `demhist.c`:
52
* http://visca.com/ffactory/archives/5-99/msg00021.html */
53
static
float4
brightness_and_contrast
(
const
float4
&
color
,
54
const
float
brightness,
55
const
float
contrast)
56
{
57
float
scaled_brightness = brightness / 100.0f;
58
float
delta = contrast / 200.0f;
59
60
float
multiplier, offset;
61
if
(contrast > 0.0f) {
62
multiplier = 1.0f - delta * 2.0f;
63
multiplier = 1.0f /
math::max
(multiplier, std::numeric_limits<float>::epsilon());
64
offset = multiplier * (scaled_brightness - delta);
65
}
66
else
{
67
delta *= -1.0f;
68
multiplier =
math::max
(1.0f - delta * 2.0f, 0.0f);
69
offset = multiplier * scaled_brightness + delta;
70
}
71
72
return
float4
(
color
.xyz() * multiplier + offset,
color
.w);
73
}
74
75
static
void
node_build_multi_function
(
blender::nodes::NodeMultiFunctionBuilder
&builder)
76
{
77
static
auto
function = mf::build::SI3_SO<float4, float, float, float4>(
78
"Brightness And Contrast"
,
79
[](
const
float4
&
color
,
const
float
brightness,
const
float
contrast) ->
float4
{
80
return
brightness_and_contrast
(
color
, brightness, contrast);
81
},
82
mf::build::exec_presets::SomeSpanOrSingle<0>());
83
builder.
set_matching_fn
(function);
84
}
85
86
}
// namespace blender::nodes::node_composite_brightness_cc
87
88
static
void
register_node_type_cmp_brightcontrast
()
89
{
90
namespace
file_ns =
blender::nodes::node_composite_brightness_cc
;
91
92
static
blender::bke::bNodeType
ntype;
93
94
cmp_node_type_base
(&ntype,
"CompositorNodeBrightContrast"
,
CMP_NODE_BRIGHTCONTRAST
);
95
ntype.
ui_name
=
"Brightness/Contrast"
;
96
ntype.
ui_description
=
"Adjust brightness and contrast"
;
97
ntype.
enum_name_legacy
=
"BRIGHTCONTRAST"
;
98
ntype.
nclass
=
NODE_CLASS_OP_COLOR
;
99
ntype.
declare
= file_ns::cmp_node_brightcontrast_declare;
100
ntype.
gpu_fn
= file_ns::node_gpu_material;
101
ntype.
build_multi_function
= file_ns::node_build_multi_function;
102
103
blender::bke::node_register_type
(ntype);
104
}
105
NOD_REGISTER_NODE
(
register_node_type_cmp_brightcontrast
)
NODE_CLASS_OP_COLOR
#define NODE_CLASS_OP_COLOR
Definition
BKE_node.hh:449
CMP_NODE_BRIGHTCONTRAST
#define CMP_NODE_BRIGHTCONTRAST
Definition
BKE_node_legacy_types.hh:198
BLI_math_color.h
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:851
NOD_multi_function.hh
NOD_REGISTER_NODE
#define NOD_REGISTER_NODE(REGISTER_FUNC)
Definition
NOD_register.hh:34
UI_resources.hh
blender::nodes::NodeDeclarationBuilder
Definition
NOD_node_declaration.hh:664
blender::nodes::NodeMultiFunctionBuilder
Definition
NOD_multi_function.hh:18
blender::nodes::NodeMultiFunctionBuilder::set_matching_fn
void set_matching_fn(const mf::MultiFunction *fn)
Definition
NOD_multi_function.hh:99
blender::nodes::decl::Color
Definition
NOD_socket_declarations.hh:139
blender::nodes::decl::Float
Definition
NOD_socket_declarations.hh:25
b
b
Definition
compositor_morphological_distance_infos.hh:24
blender::bke::node_register_type
void node_register_type(bNodeType &ntype)
Definition
node.cc:2416
blender::color
Definition
BLI_color.hh:32
blender::compositor
Definition
BKE_node.hh:77
blender::math::max
T max(const T &a, const T &b)
Definition
BLI_math_base.hh:49
blender::nodes::node_composite_brightness_cc
Definition
node_composite_brightness.cc:26
blender::nodes::node_composite_brightness_cc::node_build_multi_function
static void node_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder)
Definition
node_composite_brightness.cc:75
blender::nodes::node_composite_brightness_cc::cmp_node_brightcontrast_declare
static void cmp_node_brightcontrast_declare(NodeDeclarationBuilder &b)
Definition
node_composite_brightness.cc:28
blender::nodes::node_composite_brightness_cc::node_gpu_material
static int node_gpu_material(GPUMaterial *material, bNode *node, bNodeExecData *, GPUNodeStack *inputs, GPUNodeStack *outputs)
Definition
node_composite_brightness.cc:42
blender::nodes::node_composite_brightness_cc::brightness_and_contrast
static float4 brightness_and_contrast(const float4 &color, const float brightness, const float contrast)
Definition
node_composite_brightness.cc:53
blender::float4
VecBase< float, 4 > float4
Definition
BLI_math_vector_types.hh:620
register_node_type_cmp_brightcontrast
static void register_node_type_cmp_brightcontrast()
Definition
node_composite_brightness.cc:88
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:63
GPUNodeStack
Definition
GPU_material.hh:295
bNodeExecData
Definition
node_util.hh:22
bNode
Definition
DNA_node_types.h:422
blender::bke::bNodeType
Defines a node type.
Definition
BKE_node.hh:238
blender::bke::bNodeType::ui_description
std::string ui_description
Definition
BKE_node.hh:244
blender::bke::bNodeType::ui_name
std::string ui_name
Definition
BKE_node.hh:243
blender::bke::bNodeType::gpu_fn
NodeGPUExecFunction gpu_fn
Definition
BKE_node.hh:342
blender::bke::bNodeType::build_multi_function
NodeMultiFunctionBuildFunction build_multi_function
Definition
BKE_node.hh:351
blender::bke::bNodeType::nclass
short nclass
Definition
BKE_node.hh:251
blender::bke::bNodeType::enum_name_legacy
const char * enum_name_legacy
Definition
BKE_node.hh:247
blender::bke::bNodeType::declare
NodeDeclareFunction declare
Definition
BKE_node.hh:362
Generated on
for Blender by
doxygen
1.16.1