Blender
V4.5
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_interface.hh
"
19
#include "
UI_resources.hh
"
20
21
#include "
GPU_material.hh
"
22
23
#include "
node_composite_util.hh
"
24
25
/* **************** Brightness and Contrast ******************** */
26
27
namespace
blender::nodes::node_composite_brightness_cc
{
28
29
static
void
cmp_node_brightcontrast_declare
(
NodeDeclarationBuilder
&
b
)
30
{
31
b
.add_input<
decl::Color
>(
"Image"
).default_value({1.0f, 1.0f, 1.0f, 1.0f});
32
b
.add_input<
decl::Float
>(
"Bright"
).
min
(-100.0f).max(100.0f);
33
b
.add_input<
decl::Float
>(
"Contrast"
).
min
(-100.0f).max(100.0f);
34
b
.add_output<
decl::Color
>(
"Image"
);
35
}
36
37
using namespace
blender::compositor
;
38
39
static
int
node_gpu_material
(
GPUMaterial
*material,
40
bNode
*node,
41
bNodeExecData
*
/*execdata*/
,
42
GPUNodeStack
*
inputs
,
43
GPUNodeStack
*
outputs
)
44
{
45
return
GPU_stack_link
(material, node,
"node_composite_bright_contrast"
,
inputs
,
outputs
);
46
}
47
48
/* The algorithm is by Werner D. Streidt, extracted of OpenCV `demhist.c`:
49
* http://visca.com/ffactory/archives/5-99/msg00021.html */
50
static
float4
brightness_and_contrast
(
const
float4
&
color
,
51
const
float
brightness,
52
const
float
contrast)
53
{
54
float
scaled_brightness = brightness / 100.0f;
55
float
delta = contrast / 200.0f;
56
57
float
multiplier, offset;
58
if
(contrast > 0.0f) {
59
multiplier = 1.0f - delta * 2.0f;
60
multiplier = 1.0f /
math::max
(multiplier, std::numeric_limits<float>::epsilon());
61
offset = multiplier * (scaled_brightness - delta);
62
}
63
else
{
64
delta *= -1.0f;
65
multiplier =
math::max
(1.0f - delta * 2.0f, 0.0f);
66
offset = multiplier * scaled_brightness + delta;
67
}
68
69
return
float4
(
color
.xyz() * multiplier + offset,
color
.w);
70
}
71
72
static
void
node_build_multi_function
(
blender::nodes::NodeMultiFunctionBuilder
&builder)
73
{
74
static
auto
function = mf::build::SI3_SO<float4, float, float, float4>(
75
"Bright And Contrast"
,
76
[](
const
float4
&
color
,
const
float
brightness,
const
float
contrast) ->
float4
{
77
return
brightness_and_contrast
(
color
, brightness, contrast);
78
},
79
mf::build::exec_presets::SomeSpanOrSingle<0>());
80
builder.
set_matching_fn
(function);
81
}
82
83
}
// namespace blender::nodes::node_composite_brightness_cc
84
85
static
void
register_node_type_cmp_brightcontrast
()
86
{
87
namespace
file_ns =
blender::nodes::node_composite_brightness_cc
;
88
89
static
blender::bke::bNodeType
ntype;
90
91
cmp_node_type_base
(&ntype,
"CompositorNodeBrightContrast"
,
CMP_NODE_BRIGHTCONTRAST
);
92
ntype.
ui_name
=
"Brightness/Contrast"
;
93
ntype.
ui_description
=
"Adjust brightness and contrast"
;
94
ntype.
enum_name_legacy
=
"BRIGHTCONTRAST"
;
95
ntype.
nclass
=
NODE_CLASS_OP_COLOR
;
96
ntype.
declare
= file_ns::cmp_node_brightcontrast_declare;
97
ntype.
gpu_fn
= file_ns::node_gpu_material;
98
ntype.
build_multi_function
= file_ns::node_build_multi_function;
99
100
blender::bke::node_register_type
(ntype);
101
}
102
NOD_REGISTER_NODE
(
register_node_type_cmp_brightcontrast
)
NODE_CLASS_OP_COLOR
#define NODE_CLASS_OP_COLOR
Definition
BKE_node.hh:435
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:825
NOD_multi_function.hh
NOD_REGISTER_NODE
#define NOD_REGISTER_NODE(REGISTER_FUNC)
Definition
NOD_register.hh:34
UI_interface.hh
UI_resources.hh
blender::nodes::NodeDeclarationBuilder
Definition
NOD_node_declaration.hh:629
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:133
blender::nodes::decl::Float
Definition
NOD_socket_declarations.hh:19
b
b
Definition
compositor_morphological_distance_info.hh:24
blender::bke::node_register_type
void node_register_type(bNodeType &ntype)
Definition
node.cc:2748
blender::color
Definition
BLI_color_mix.hh:21
blender::compositor
Definition
BKE_node.hh:76
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:27
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:72
blender::nodes::node_composite_brightness_cc::cmp_node_brightcontrast_declare
static void cmp_node_brightcontrast_declare(NodeDeclarationBuilder &b)
Definition
node_composite_brightness.cc:29
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:39
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:50
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:85
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
bNode
Definition
DNA_node_types.h:415
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
Generated on
for Blender by
doxygen
1.15.0