Blender
V5.0
source
blender
compositor
COM_domain.hh
Go to the documentation of this file.
1
/* SPDX-FileCopyrightText: 2023 Blender Authors
2
*
3
* SPDX-License-Identifier: GPL-2.0-or-later */
4
5
#pragma once
6
7
#include <cstdint>
8
9
#include "
BLI_math_interp.hh
"
10
#include "
BLI_math_matrix_types.hh
"
11
#include "
BLI_math_vector_types.hh
"
12
13
#include "
GPU_texture.hh
"
14
15
namespace
blender::compositor
{
16
17
/* Possible interpolations to use when realizing an input result of some domain on another domain.
18
* See the RealizationOptions struct for more information. */
19
enum class
Interpolation
: uint8_t {
20
Nearest
,
21
Bilinear
,
22
Bicubic
,
23
Anisotropic
,
24
};
25
26
/* Possible extension modes when computing samples in the domain's exterior. */
27
enum class
ExtensionMode
: uint8_t {
28
/* Areas outside of the image are filled with zero. */
29
Clip
,
30
/* Areas outside of the image are filled with the closest boundary pixel in the image. */
31
Extend
,
32
/* Areas outside of the image are filled with repetitions of the image. */
33
Repeat
,
34
};
35
36
/* ------------------------------------------------------------------------------------------------
37
* Realization Options
38
*
39
* The options that describe how an input result prefer to be realized on some other domain. This
40
* is used by the Realize On Domain and Transform algorithms to identify the appropriate method of
41
* realization. See the Domain class for more information. */
42
struct
RealizationOptions
{
43
/* The interpolation method that should be used when performing realization. Since realizing a
44
* result involves projecting it on a different domain, which in turn, involves sampling the
45
* result at arbitrary locations, the interpolation identifies the method used for computing the
46
* value at those arbitrary locations. */
47
Interpolation
interpolation
=
Interpolation::Bilinear
;
48
/* The extend mode for the x-axis. Defaults to Zero padding. */
49
ExtensionMode
extension_x
=
ExtensionMode::Clip
;
50
/* The extend mode for the y-axis. Defaults to Zero padding. */
51
ExtensionMode
extension_y
=
ExtensionMode::Clip
;
52
};
53
54
/* ------------------------------------------------------------------------------------------------
55
* Domain
56
*
57
* The compositor is designed in such a way as to allow compositing in an infinite virtual
58
* compositing space. Consequently, any result of an operation is not only represented by its image
59
* output, but also by its transformation in that virtual space. The transformation of the result
60
* together with the dimension of its image is stored and represented by a Domain. In the figure
61
* below, two results of different domains are illustrated on the virtual compositing space. One of
62
* the results is centered in space with an image dimension of 800px x 600px, and the other result
63
* is scaled down and translated such that it lies in the upper right quadrant of the space with an
64
* image dimension of 800px × 400px. The position of the domain is in pixel space, and the domain
65
* is considered centered if it has an identity transformation. Note that both results have the
66
* same resolution, but occupy different areas of the virtual compositing space.
67
*
68
* y
69
* ^
70
* 800px x 600px |
71
* .---------------------|---------------------.
72
* | | 800px x 600px |
73
* | | .-------------. |
74
* | | | | |
75
* | | '-------------' |
76
* ------|---------------------|---------------------|------> x
77
* | | |
78
* | | |
79
* | | |
80
* | | |
81
* '---------------------|---------------------'
82
* |
83
*
84
* By default, results have domains of identity transformations, that is, they are centered in
85
* space, but a transformation operation like the rotate, translate, or transform operations will
86
* adjust the transformation to make the result reside somewhere different in space. The domain of
87
* a single value result is irrelevant and always set to an identity domain.
88
*
89
* An operation is typically only concerned about a subset of the virtual compositing space, this
90
* subset is represented by a domain which is called the Operation Domain. It follows that before
91
* the operation itself is executed, inputs will typically be realized on the operation domain to
92
* be in the same domain and have the same dimension as that of the operation domain. This process
93
* is called Domain Realization and is implemented using an operation called the Realize On Domain
94
* Operation. Realization involves projecting the result onto the target domain, copying the area
95
* of the result that intersects the target domain, and filling the rest with zeros or repetitions
96
* of the result depending on the realization options that can be set by the user. Consequently,
97
* operations can generally expect their inputs to have the same dimension and can operate on them
98
* directly and transparently. For instance, if an operation takes both results illustrated in
99
* the figure above, and the operation has an operation domain that matches the bigger domain, the
100
* result with the bigger domain will not need to be realized because it already has a domain that
101
* matches that of the operation domain, but the result with the smaller domain will have to be
102
* realized into a new result that has the same domain as the domain of the bigger result. Assuming
103
* no repetition, the output of the realization will be an all zeros image with dimension 800px ×
104
* 600px with a small scaled version of the smaller result copied into the upper right quadrant of
105
* the image. The following figure illustrates the realization process on a different set of
106
* results
107
*
108
* Realized Result
109
* +-------------+ +-------------+
110
* | Operation | | |
111
* | Domain | | Zeros |
112
* | | ----> | |
113
* +-----|-----+ | |-----+ |
114
* | | C | | | C | |
115
* | +-----|-------+ +-----'-------+
116
* | Domain Of |
117
* | Input |
118
* +-----------+
119
*
120
* An operation can operate in an arbitrary operation domain, but in most cases, the operation
121
* domain is inferred from the inputs of the operation. In particular, one of the inputs is said to
122
* be the Domain Input of the operation and the operation domain is inferred from its domain. It
123
* follows that this particular input will not need realization, because it already has the correct
124
* domain. The domain input selection mechanism is as follows. Each of the inputs are assigned a
125
* value by the developer called the Domain Priority, the domain input is then chosen as the
126
* non-single value input with the highest domain priority, zero being the highest priority. See
127
* Operation::compute_domain for more information.
128
*
129
* The aforementioned logic for operation domain computation is only a default that works for most
130
* cases, but an operation can override the compute_domain method to implement a different logic.
131
* For instance, output nodes have an operation domain the same size as the viewport and with an
132
* identity transformation, their operation domain doesn't depend on the inputs at all.
133
*
134
* For instance, a filter operation has two inputs, a factor and a color, the latter of which is
135
* assigned a domain priority of 0 and the former is assigned a domain priority of 1. If the color
136
* input is not a single value input, then the color input is considered to be the domain input of
137
* the operation and the operation domain is computed to be the same domain as the color input,
138
* because it has the highest priority. It follows that if the factor input has a different domain
139
* than the computed domain of the operation, it will be projected and realized on it to have the
140
* same domain as described above. On the other hand, if the color input is a single value input,
141
* then the factor input is considered to be the domain input and the operation domain will be the
142
* same as the domain of the factor input, because it has the second highest domain priority.
143
* Finally, if both inputs are single value inputs, the operation domain will be an identity domain
144
* and is irrelevant, because the output will be a domain-less single value. */
145
class
Domain
{
146
public
:
147
/* The size of the domain in pixels. */
148
int2
size
;
149
/* The 2D transformation of the domain defining its translation in pixels, rotation, and scale in
150
* the virtual compositing space. */
151
float3x3
transformation
;
152
/* The options that describe how this domain prefer to be realized on some other domain. See the
153
* RealizationOptions struct for more information. */
154
RealizationOptions
realization_options
;
155
156
/* A size only constructor that sets the transformation to identity. */
157
Domain
(
const
int2
&
size
);
158
159
Domain
(
const
int2
&
size
,
const
float3x3
&
transformation
);
160
161
/* Transform the domain by the given transformation. This effectively pre-multiply the given
162
* transformation by the current transformation of the domain. */
163
void
transform
(
const
float3x3
&input_transformation);
164
165
/* Returns a transposed version of itself, that is, with the x and y sizes swapped. */
166
Domain
transposed
()
const
;
167
168
/* Returns a domain of size 1x1 and an identity transformation. */
169
static
Domain
identity
();
170
171
/* Compare the size and transformation of the domain. Transformations are compared within the
172
* given epsilon. The realization_options are not compared because they only describe the method
173
* of realization on another domain, which is not technically a property of the domain itself. */
174
static
bool
is_equal
(
const
Domain
&a,
const
Domain
&
b
,
const
float
epsilon = 0.0f);
175
};
176
177
/* Identical to the is_equal static method with zero epsilon. */
178
bool
operator==
(
const
Domain
&a,
const
Domain
&
b
);
179
bool
operator!=
(
const
Domain
&a,
const
Domain
&
b
);
180
181
math::InterpWrapMode
map_extension_mode_to_wrap_mode
(
const
ExtensionMode
&mode);
182
GPUSamplerExtendMode
map_extension_mode_to_extend_mode
(
const
ExtensionMode
&mode);
183
184
}
// namespace blender::compositor
BLI_math_interp.hh
BLI_math_matrix_types.hh
BLI_math_vector_types.hh
GPU_texture.hh
GPUSamplerExtendMode
GPUSamplerExtendMode
Definition
GPU_texture.hh:323
blender::compositor::Domain
Definition
COM_domain.hh:145
blender::compositor::Domain::size
int2 size
Definition
COM_domain.hh:148
blender::compositor::Domain::Domain
Domain(const int2 &size)
Definition
domain.cc:17
blender::compositor::Domain::is_equal
static bool is_equal(const Domain &a, const Domain &b, const float epsilon=0.0f)
Definition
domain.cc:41
blender::compositor::Domain::transposed
Domain transposed() const
Definition
domain.cc:29
blender::compositor::Domain::transformation
float3x3 transformation
Definition
COM_domain.hh:151
blender::compositor::Domain::transform
void transform(const float3x3 &input_transformation)
Definition
domain.cc:24
blender::compositor::Domain::realization_options
RealizationOptions realization_options
Definition
COM_domain.hh:154
blender::compositor::Domain::identity
static Domain identity()
Definition
domain.cc:36
b
b
Definition
compositor_morphological_distance_infos.hh:24
blender::compositor
Definition
BKE_node.hh:77
blender::compositor::Interpolation
Interpolation
Definition
COM_domain.hh:19
blender::compositor::Interpolation::Anisotropic
@ Anisotropic
Definition
COM_domain.hh:23
blender::compositor::Interpolation::Nearest
@ Nearest
Definition
COM_domain.hh:20
blender::compositor::Interpolation::Bicubic
@ Bicubic
Definition
COM_domain.hh:22
blender::compositor::Interpolation::Bilinear
@ Bilinear
Definition
COM_domain.hh:21
blender::compositor::ExtensionMode
ExtensionMode
Definition
COM_domain.hh:27
blender::compositor::ExtensionMode::Clip
@ Clip
Definition
COM_domain.hh:29
blender::compositor::ExtensionMode::Repeat
@ Repeat
Definition
COM_domain.hh:33
blender::compositor::operator==
bool operator==(const BokehKernelKey &a, const BokehKernelKey &b)
Definition
bokeh_kernel.cc:44
blender::compositor::PaddingMethod::Extend
@ Extend
Definition
COM_algorithm_pad.hh:19
blender::compositor::map_extension_mode_to_extend_mode
GPUSamplerExtendMode map_extension_mode_to_extend_mode(const ExtensionMode &mode)
Definition
domain.cc:70
blender::compositor::operator!=
bool operator!=(const Domain &a, const Domain &b)
Definition
domain.cc:51
blender::compositor::map_extension_mode_to_wrap_mode
math::InterpWrapMode map_extension_mode_to_wrap_mode(const ExtensionMode &mode)
Definition
domain.cc:56
blender::math::InterpWrapMode
InterpWrapMode
Definition
BLI_math_interp.hh:34
blender::int2
VecBase< int32_t, 2 > int2
Definition
BLI_math_vector_types.hh:601
blender::float3x3
MatBase< float, 3, 3 > float3x3
Definition
BLI_math_matrix_types.hh:1008
blender::compositor::RealizationOptions
Definition
COM_domain.hh:42
blender::compositor::RealizationOptions::extension_x
ExtensionMode extension_x
Definition
COM_domain.hh:49
blender::compositor::RealizationOptions::extension_y
ExtensionMode extension_y
Definition
COM_domain.hh:51
blender::compositor::RealizationOptions::interpolation
Interpolation interpolation
Definition
COM_domain.hh:47
Generated on
for Blender by
doxygen
1.16.1