Blender V5.0
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"
12
13#include "GPU_texture.hh"
14
15namespace 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. */
25
26/* Possible extension modes when computing samples in the domain's exterior. */
27enum class ExtensionMode : uint8_t {
28 /* Areas outside of the image are filled with zero. */
30 /* Areas outside of the image are filled with the closest boundary pixel in the image. */
32 /* Areas outside of the image are filled with repetitions of the image. */
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. */
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. */
48 /* The extend mode for the x-axis. Defaults to Zero padding. */
50 /* The extend mode for the y-axis. Defaults to Zero padding. */
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. */
145class Domain {
146 public:
147 /* The size of the domain in pixels. */
149 /* The 2D transformation of the domain defining its translation in pixels, rotation, and scale in
150 * the virtual compositing space. */
152 /* The options that describe how this domain prefer to be realized on some other domain. See the
153 * RealizationOptions struct for more information. */
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. */
178bool operator==(const Domain &a, const Domain &b);
179bool operator!=(const Domain &a, const Domain &b);
180
183
184} // namespace blender::compositor
GPUSamplerExtendMode
Domain(const int2 &size)
Definition domain.cc:17
static bool is_equal(const Domain &a, const Domain &b, const float epsilon=0.0f)
Definition domain.cc:41
Domain transposed() const
Definition domain.cc:29
void transform(const float3x3 &input_transformation)
Definition domain.cc:24
RealizationOptions realization_options
static Domain identity()
Definition domain.cc:36
bool operator==(const BokehKernelKey &a, const BokehKernelKey &b)
GPUSamplerExtendMode map_extension_mode_to_extend_mode(const ExtensionMode &mode)
Definition domain.cc:70
bool operator!=(const Domain &a, const Domain &b)
Definition domain.cc:51
math::InterpWrapMode map_extension_mode_to_wrap_mode(const ExtensionMode &mode)
Definition domain.cc:56
VecBase< int32_t, 2 > int2
MatBase< float, 3, 3 > float3x3