Blender V4.3
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
11
13
14/* Possible interpolations to use when realizing an input result of some domain on another domain.
15 * See the RealizationOptions struct for more information. */
16enum class Interpolation : uint8_t {
17 Nearest,
19 Bicubic,
20};
21
22/* ------------------------------------------------------------------------------------------------
23 * Realization Options
24 *
25 * The options that describe how an input result prefer to be realized on some other domain. This
26 * is used by the Realize On Domain and Transform algorithms to identify the appropriate method of
27 * realization. See the Domain class for more information. */
29 /* The interpolation method that should be used when performing realization. Since realizing a
30 * result involves projecting it on a different domain, which in turn, involves sampling the
31 * result at arbitrary locations, the interpolation identifies the method used for computing the
32 * value at those arbitrary locations. */
34 /* If true, the result will be repeated infinitely along the horizontal axis when realizing the
35 * result. If false, regions outside of bounds of the result along the horizontal axis will be
36 * filled with zeros. */
37 bool wrap_x = false;
38 /* If true, the result will be repeated infinitely along the vertical axis when realizing the
39 * result. If false, regions outside of bounds of the result along the vertical axis will be
40 * filled with zeros. */
41 bool wrap_y = false;
42};
43
44/* ------------------------------------------------------------------------------------------------
45 * Domain
46 *
47 * The compositor is designed in such a way as to allow compositing in an infinite virtual
48 * compositing space. Consequently, any result of an operation is not only represented by its image
49 * output, but also by its transformation in that virtual space. The transformation of the result
50 * together with the dimension of its image is stored and represented by a Domain. In the figure
51 * below, two results of different domains are illustrated on the virtual compositing space. One of
52 * the results is centered in space with an image dimension of 800px x 600px, and the other result
53 * is scaled down and translated such that it lies in the upper right quadrant of the space with an
54 * image dimension of 800px × 400px. The position of the domain is in pixel space, and the domain
55 * is considered centered if it has an identity transformation. Note that both results have the
56 * same resolution, but occupy different areas of the virtual compositing space.
57 *
58 * y
59 * ^
60 * 800px x 600px |
61 * .---------------------|---------------------.
62 * | | 800px x 600px |
63 * | | .-------------. |
64 * | | | | |
65 * | | '-------------' |
66 * ------|---------------------|---------------------|------> x
67 * | | |
68 * | | |
69 * | | |
70 * | | |
71 * '---------------------|---------------------'
72 * |
73 *
74 * By default, results have domains of identity transformations, that is, they are centered in
75 * space, but a transformation operation like the rotate, translate, or transform operations will
76 * adjust the transformation to make the result reside somewhere different in space. The domain of
77 * a single value result is irrelevant and always set to an identity domain.
78 *
79 * An operation is typically only concerned about a subset of the virtual compositing space, this
80 * subset is represented by a domain which is called the Operation Domain. It follows that before
81 * the operation itself is executed, inputs will typically be realized on the operation domain to
82 * be in the same domain and have the same dimension as that of the operation domain. This process
83 * is called Domain Realization and is implemented using an operation called the Realize On Domain
84 * Operation. Realization involves projecting the result onto the target domain, copying the area
85 * of the result that intersects the target domain, and filling the rest with zeros or repetitions
86 * of the result depending on the realization options that can be set by the user. Consequently,
87 * operations can generally expect their inputs to have the same dimension and can operate on them
88 * directly and transparently. For instance, if an operation takes both results illustrated in
89 * the figure above, and the operation has an operation domain that matches the bigger domain, the
90 * result with the bigger domain will not need to be realized because it already has a domain that
91 * matches that of the operation domain, but the result with the smaller domain will have to be
92 * realized into a new result that has the same domain as the domain of the bigger result. Assuming
93 * no repetition, the output of the realization will be an all zeros image with dimension 800px ×
94 * 600px with a small scaled version of the smaller result copied into the upper right quadrant of
95 * the image. The following figure illustrates the realization process on a different set of
96 * results
97 *
98 * Realized Result
99 * +-------------+ +-------------+
100 * | Operation | | |
101 * | Domain | | Zeros |
102 * | | ----> | |
103 * +-----|-----+ | |-----+ |
104 * | | C | | | C | |
105 * | +-----|-------+ +-----'-------+
106 * | Domain Of |
107 * | Input |
108 * +-----------+
109 *
110 * An operation can operate in an arbitrary operation domain, but in most cases, the operation
111 * domain is inferred from the inputs of the operation. In particular, one of the inputs is said to
112 * be the Domain Input of the operation and the operation domain is inferred from its domain. It
113 * follows that this particular input will not need realization, because it already has the correct
114 * domain. The domain input selection mechanism is as follows. Each of the inputs are assigned a
115 * value by the developer called the Domain Priority, the domain input is then chosen as the
116 * non-single value input with the highest domain priority, zero being the highest priority. See
117 * Operation::compute_domain for more information.
118 *
119 * The aforementioned logic for operation domain computation is only a default that works for most
120 * cases, but an operation can override the compute_domain method to implement a different logic.
121 * For instance, output nodes have an operation domain the same size as the viewport and with an
122 * identity transformation, their operation domain doesn't depend on the inputs at all.
123 *
124 * For instance, a filter operation has two inputs, a factor and a color, the latter of which is
125 * assigned a domain priority of 0 and the former is assigned a domain priority of 1. If the color
126 * input is not a single value input, then the color input is considered to be the domain input of
127 * the operation and the operation domain is computed to be the same domain as the color input,
128 * because it has the highest priority. It follows that if the factor input has a different domain
129 * than the computed domain of the operation, it will be projected and realized on it to have the
130 * same domain as described above. On the other hand, if the color input is a single value input,
131 * then the factor input is considered to be the domain input and the operation domain will be the
132 * same as the domain of the factor input, because it has the second highest domain priority.
133 * Finally, if both inputs are single value inputs, the operation domain will be an identity domain
134 * and is irrelevant, because the output will be a domain-less single value. */
135class Domain {
136 public:
137 /* The size of the domain in pixels. */
139 /* The 2D transformation of the domain defining its translation in pixels, rotation, and scale in
140 * the virtual compositing space. */
142 /* The options that describe how this domain prefer to be realized on some other domain. See the
143 * RealizationOptions struct for more information. */
145
146 public:
147 /* A size only constructor that sets the transformation to identity. */
148 Domain(const int2 &size);
149
150 Domain(const int2 &size, const float3x3 &transformation);
151
152 /* Transform the domain by the given transformation. This effectively pre-multiply the given
153 * transformation by the current transformation of the domain. */
154 void transform(const float3x3 &input_transformation);
155
156 /* Returns a domain of size 1x1 and an identity transformation. */
157 static Domain identity();
158};
159
160/* Compare the size and transformation of the domain. The realization_options are not compared
161 * because they only describe the method of realization on another domain, which is not technically
162 * a property of the domain itself. */
163bool operator==(const Domain &a, const Domain &b);
164
165/* Inverse of the above equality operator. */
166bool operator!=(const Domain &a, const Domain &b);
167
168} // namespace blender::realtime_compositor
void transform(const float3x3 &input_transformation)
Definition domain.cc:19
local_group_size(16, 16) .push_constant(Type b
bool operator==(const BokehKernelKey &a, const BokehKernelKey &b)
bool operator!=(const Domain &a, const Domain &b)
Definition domain.cc:34
unsigned char uint8_t
Definition stdint.h:78