Commit Graph

50 Commits

Author SHA1 Message Date
Omar Emara
a4502f82c1 Compositor: Add Image Coordinates node
This patch adds a new Image Coordinates node for the compositor. The
Texture Coordinates and Pixel Coordinates outputs were removed from the
Image Info node and were added to the new node instead. Additionally, a
new Normalized Coordinates output was added.

The Pixel Coordinates output now no longer includes half pixel offsets.

Pull Request: https://projects.blender.org/blender/blender/pulls/138935
2025-05-26 08:25:06 +02:00
Omar Emara
6c62fb5ff6 Compositor: Turn Color Balance options to inputs
This patch turns the options of the Color Balance node into inputs.

In the process, each of the wheels were split into two inputs, a base
float and a color. For instance, Gain is controlled using both a Base
Gain and Color Gain, the former controls the gain for all channels while
the latter controls it per channel.

Reference #137223.

Pull Request: https://projects.blender.org/blender/blender/pulls/138610
2025-05-23 15:42:54 +02:00
Omar Emara
499dcc3ae2 Compositor: Avoid clamping after HSVA conversion
This patch avoid clamping HSVA colors after being combined using a
Combine HSVA node in the GPU compositor. This is consistent with the CPU
compositor and other node editors.
2025-05-15 09:58:32 +03:00
Omar Emara
1f51172692 Compositor: Turn Alpha Over options to inputs
This patch turns the options of the Alpha Over node into inputs.

In the process, Convert Premultiplied option was renamed to Straight
Alpha.

Reference #137223.

Pull Request: https://projects.blender.org/blender/blender/pulls/138441
2025-05-05 14:16:27 +02:00
Omar Emara
ebe67e5ca0 Compositor: Remove Premultiplied option from Alpha Over node
This patch removes the Premultiplied option from the Alpha Over node.
The reasoning is as follows:

- The option mixed between alpha being straight and premultiplied, a
  state which doesn't happen in practice.
- The option conflicts with the Convert Premultiplied option, if it is
  not zero, then Convert Premultiplied does nothing.
- The option is implemented in a lossy way. It premultiplies the alpha
  assuming it is straight, then converts the result to straight again,
  then mixed between both results. This is as opposed to mixing the
  original straight input with the premultiplied input. The successive
  alpha conversion causes data loss in transparent regions.

Pull Request: https://projects.blender.org/blender/blender/pulls/138428
2025-05-05 10:51:34 +02:00
Omar Emara
92ac9f3b25 Compositor: Remove Premultiplied option from Brightness node
This patch removes the Convert Premultiplied option from the Brightness
and Contrast node. The reasoning is that it is the only node that has
the option to operate on straight alpha, while not being particularly
different. Adding alpha conversion nodes around it is also very easy.
Furthermore, alpha conversion is a lossy operation, so the option looses
data in emissive pixels, and since it is enabled by default, users not
familiar with the exact mechanism of the option wouldn't know how to fix
this.

Pull Request: https://projects.blender.org/blender/blender/pulls/138318
2025-05-05 08:33:29 +02:00
Omar Emara
510130de07 Compositor: Turn Bilateral Blur options to inputs
This patch turns the options of the Bilateral Blur node into inputs.

In the process, the Sigma Space and Iterations were joined into a single
Size input, previously they were just added together then ceiled to get
the blur size. Furthermore, Sigma Color was renamed to threshold and now
represents the average color difference, not the sum, so it was
previously multiplied by 3.

Versioning and RNA compatibility is not perfect due to joining the two
size options.

Reference #137223.

Pull Request: https://projects.blender.org/blender/blender/pulls/138249
2025-05-01 09:57:57 +02:00
Omar Emara
f216b3ca62 Compositor: Turn Directional Blur options to inputs
This patch turns the options of the Directional Blur node into inputs.

In the process, the node now allows scaling down, not just scaling up.
The transformation options were renamed to Translation, Rotation, and
Scale as opposed to Distance, Spin, and Zoom. Finally, scaling is now
defined as a scale instead of a delta. So 1 is identity, 2 means scale
up two times, and so on. While previously, 0 was an identity scale, 1
means scale up by two types.

Reference #137223.

Pull Request: https://projects.blender.org/blender/blender/pulls/138198
2025-04-30 14:40:13 +02:00
Omar Emara
682ab26994 Compositor: Remove Map UV node Alpha option
This patch removes the Alpha option in the Map UV node. That's because
it currently only has a marginal effect on the result of the node and is
unnoticeable to the user.

The alpha option was supposed to darken the edges of the object that has
the UVs by attenuating the result according to the Laplacian of UV
coordinates. But the attenuation factor was too small to be noticeable.
This option was probably added when UV passes had no anti-aliased alpha
and was therefore needed to smooth the transition at the edges probably.

We asked for user feedback and got feedback from the studio, and it seem
the option is mostly unused.

Pull Request: https://projects.blender.org/blender/blender/pulls/138116
2025-04-29 10:56:33 +02:00
Omar Emara
ddc0f9460d Compositor: Turn Lens Distortion options to inputs
This patch turns the options of the Lens Distortion node into inputs.

The Projector option was turned into an enum between two options.

Reference #137223.

Pull Request: https://projects.blender.org/blender/blender/pulls/138113
2025-04-29 09:54:12 +02:00
Omar Emara
39aa73628d Compositor: Turn Color Correction options to inputs
This patch turns the options of the Color Correction node into inputs.

Reference #137223.

Pull Request: https://projects.blender.org/blender/blender/pulls/138003
2025-04-28 12:19:42 +02:00
Clément Foucault
59df50c326 GPU: Refactor Qualifier and ImageType
This allow to use types closer to GLSL in resource
declaration.

These are aliased for clarity in the GPU
module (i.e. `isampler2D` is shortened to `Int2D`).

Rel #137446

Pull Request: https://projects.blender.org/blender/blender/pulls/137954
2025-04-24 14:38:13 +02:00
Omar Emara
8c616a8a00 Compositor: Turn Keying node options to inputs
This patch turns the options of the Keying node into inputs.

In the process, some options were renamed for clarity and consistency
with other nodes.

Reference #137223.

Pull Request: https://projects.blender.org/blender/blender/pulls/137900
2025-04-23 15:33:22 +02:00
Omar Emara
730cb40f4c Compositor: Turn Color Spill options to inputs
This patch turns the options of the Color Spill node into inputs.

In the process, the Ratio option was renamed to Limit Strength, the
unspill option was renamed to Spill Strength.

Reference #137223.

Pull Request: https://projects.blender.org/blender/blender/pulls/137848
2025-04-22 14:51:26 +02:00
Omar Emara
5e93b6a2cd Compositor: Turn Luminance Key options to inputs
This patch turns the options of the Luminance Key node into inputs.

Reference #137223.

Pull Request: https://projects.blender.org/blender/blender/pulls/137823
2025-04-22 09:09:51 +02:00
Omar Emara
fa7d58ab4c Compositor: Turn Color Key options to inputs
This patch turns the options of the Color Key node into inputs.

Reference #137223.

Pull Request: https://projects.blender.org/blender/blender/pulls/137815
2025-04-21 16:40:17 +02:00
Omar Emara
4f3413ff80 Compositor: Turn Chroma Key options to inputs
This patch turns the options of the Chroma Key node into inputs.

In the process, the minimum and maximum angles were renamed to Minimum
and Maximum for consistency with other matte nodes.

Reference #137223.

Pull Request: https://projects.blender.org/blender/blender/pulls/137812
2025-04-21 15:28:37 +02:00
Omar Emara
89b268bf0c Compositor: Turn Channel Key options to inputs
This patch turns the options of the Channel Key node into inputs.

Reference #137223.

Pull Request: https://projects.blender.org/blender/blender/pulls/137806
2025-04-21 14:02:15 +02:00
Omar Emara
ab81cd7bbb Compositor: Turn Invert node options into inputs
This patch turns the options of the Invert node into inputs.

Reference #137223.

Pull Request: https://projects.blender.org/blender/blender/pulls/137527
2025-04-15 14:18:04 +02:00
Clément Foucault
47d2dffe8c GPU: Shader CodeBase use constexpr instead of const
Do this only when applicable.

This allow better compile time checking in Shader C++ compilation.
Moreover, this allows to have `constexpr` in shared code between
C++ and GLSL.

After investigation the `const` keyword in GLSL has the same
semantic than C/C++.

Rel #137333 and #137446

Pull Request: https://projects.blender.org/blender/blender/pulls/137497
2025-04-15 11:36:53 +02:00
Clément Foucault
3b3a5731df GPU: Shader: Change vector and matrix type to use blender convention
This unify the C++ and GLSL codebase style.

The GLSL types are still in the backend compatibility
layers to support python shaders. However, the C++
shader compilation layer doesn't have them to enforce
correct type usage.

Note that this is going to break pretty much all PRs
in flight that targets shader code.

Rel #137261

Pull Request: https://projects.blender.org/blender/blender/pulls/137369
2025-04-14 13:46:41 +02:00
Clément Foucault
9990273d04 GPU: Change Type enum to use lower case values
This is to help for future resource declaration
using macros.

Rel #137261

Pull Request: https://projects.blender.org/blender/blender/pulls/137367
2025-04-11 22:39:01 +02:00
Clément Foucault
bb52754652 GPU: Use f suffix for float literals
They are actually already some literals with the `f` suffix
that are in our shader codebase and we never had problem in
the past 5 years (or even 8 years).

So I think it is safe to do and improves convergence of codestyles.

Pull Request: https://projects.blender.org/blender/blender/pulls/137352
2025-04-11 18:28:45 +02:00
Maxime-Cots
a4a4dc7da5 Compositor: Expose interpolation in Corner Pin node
This patch exposes an interpolation option to the Corner Pin node,
allowing to choose between Nearest, Bilinear, Bicubic, and Anisotropic.

Pull Request: https://projects.blender.org/blender/blender/pulls/123206
2025-04-08 12:13:47 +02:00
Ben Beilharz
0eccadd452 Compositor: Expose interpolation in Scale node
This patch adds a new interpolation option to the Scale node to control
how pixels are sampled during scaling. For constant sizes, this stores
the interpolation for later realization, while for variable sizes, the
interpolation takes effect immediately.

Pull Request: https://projects.blender.org/blender/blender/pulls/135989
2025-04-03 15:50:57 +02:00
Omar Emara
d6fa68eb58 Compositor: Add boolean socket support
This patch adds support for boolean sockets in the compositor. This
involves adding a new Bool ResultType and handling it in relevant code.
For shader operations, booleans are passes as floats since GPUMaterial
does not yet support boolean types.

Pull Request: https://projects.blender.org/blender/blender/pulls/136296
2025-03-21 12:03:09 +01:00
Omar Emara
ff4237d713 Compositor: Support Int2 and Float2 types in shader operations
This patch adds support for Int2 and Float2 types in shader operations.
They are already supported for multi-function procedures. They are not
used in practice, but implementing them makes adding new types easier
since we don't have to think about types that are supported and those
that aren't. They are both encoded as vec3 due to limited supported for
those types in the GPUMaterial implementation.
2025-03-20 09:52:54 +02:00
Omar Emara
2bc47e1e93 Cleanup: Compositor: Remove unused function 2025-03-19 16:01:45 +02:00
Omar Emara
b5392187ba Compositor: Support conversion to and from int2 and float2
This patch adds support for converting to and from float2 and int2
result types for GPU devices, this is already supported on CPU.
2025-03-19 15:51:57 +02:00
Omar Emara
775df8826b Compositor: Add Image Info node
This patch adds a new Image Info node which returns information about
compositor images. The node has three sources:

The node returns the following information:

- Pixel Coordinates: The coordinates of the centers of the pixels in the
  image. Those are essentially the integer coordinates with half pixels
  offsets added.
- Texture Coordinates: Zero centered pixel coordinates normalized along
  the greater dimension. Somewhat analogous to Object coordinates in
  shader nodes.
- Resolution: The resolution of the image.
- Location: The location of the image in the virtual compositing space.
- Rotation: The rotation of the image in the virtual compositing space.
- Scale: The scale of the image in the virtual compositing space.

This node is very useful to allow greater flexibility and procedural
creations. For instance, coordinates can be used to create procedural
effects like vignette using very simple math nodes. And size can be used
to compute size-relative parameters for pixel-parameter nodes.

Pull Request: https://projects.blender.org/blender/blender/pulls/135104
2025-03-19 11:38:29 +01:00
Omar Emara
0a57002469 Cleanup: Compositor: Remove redundant SMAA types
This patch removes code that handles types other than Float and Color,
that's because SMAA is practically only used for those types only.
2025-03-18 15:51:51 +02:00
Omar Emara
c55594f0a1 Fix: Z Combine asserts when one output is unused
The Z Combine node asserts if one of its outputs are unused. That's
because we compete both outputs even if they are not needed. To fix
this, we skip outputs that are not needed by splitting the shaders to
compute each output independently.
2025-03-04 14:05:55 +02:00
Omar Emara
2284b7538a Fix: Keying asserts when Edges output is unused
The Keying node asserts if its Edges output is unused. That's because we
compete the outputs even if it not needed. To fix this, we skip that
output if not needed.
2025-03-04 12:43:08 +02:00
Omar Emara
20897f5f20 Cleanup: Warning about integers of different signs
The SAT shaders in the compositor contain comparisons of different
signed integers, use uint to fix this.
2025-02-27 11:19:24 +02:00
Omar Emara
e224e437da Cleanup: Compositor: Remove common_math_utils includes
This patches removes common_math_utils includes from compositor shaders
and replaces them with math lib includes. This involves moving some
functions from that file to to the math lib files.

Pull Request: https://projects.blender.org/blender/blender/pulls/135157
2025-02-26 10:47:39 +01:00
Omar Emara
5e8f96277d Compositor: Reduce vector type components to 3
Previously, the vector type in the compositor had 4-components to
accommodated float4 types, while the last component was ignored for the
rest of the vector types. But now that we have a dedicated type for
float4 in #134486. We can reduce that vector type to 3-components.

Pull Request: https://projects.blender.org/blender/blender/pulls/134570
2025-02-20 13:23:54 +01:00
Omar Emara
a5ecde48ae Compositor: Add Float4 type
The compositor previously overloaded the vector type to represent
multiple dimensions that are always stored in a 4D float vector. This
patch introduce a dedicated type for float4, leaving the vector type to
always represent a 3D vector, which will be done in a later commit.

This is not exposed to the user as a separate socket type with a
different color, it is only an internal type that uses the same vector
socket shape and color.

Since the vector socket represents both 4D and 3D vectors, code
generally assumes that such sockets represents 3D vectors, and the
developer is expected to set it to a 4D vector if needed in the node
operation constructor, or use the newly added skip_type_conversion flag
for nodes that do not care about types, like the File Output node.
Though this should be redundant once we add a dimension property for
vector sockets.

Pull Request: https://projects.blender.org/blender/blender/pulls/134486
2025-02-20 10:38:40 +01:00
Clément Foucault
a961c9050d Cleanup: GPU: Remove dependency on legacy common_math_lib.glsl
Replace usage of `common_math_lib.glsl` (deprecated) with gpu shader libs.

Pull Request: https://projects.blender.org/blender/blender/pulls/131579
2025-02-10 18:14:50 +01:00
Omar Emara
2d1e64d32d Fix: Simple Star glare fails in Metal GPU back-end
The Simple Stare glare code writes and reads from the same image in the
same invocation, so we need to insert a fence after the writes.

This is not very efficient, and we can probably use a single fence
between the causal and anti-causal passes. But this can be implemented
later as an optimization.

Pull Request: https://projects.blender.org/blender/blender/pulls/133968
2025-02-03 13:05:46 +01:00
Jeroen Bakker
9f5d8756fc Fix #133866: Compositor: Incorrect Binding info keying node
Keying node has incorrect binding info, what leads to incorrect results
when running on Mesa/RADV driver.

Pull Request: https://projects.blender.org/blender/blender/pulls/133877
2025-01-31 17:20:05 +01:00
Omar Emara
759a7a08d9 Fix: Conversion shader fails compilation on MacOS
Argument names can't be the same as a push constant name, so rename the
push constant.

Pull Request: https://projects.blender.org/blender/blender/pulls/133531
2025-01-24 11:14:56 +01:00
Omar Emara
b8db212d95 Compositor: Use OCIO luminance for color to float conversion
This patch uses OCIO luminance for implicit conversion from color to
float in the compositor. This is done to match other node systems, and
because luminance is a much better default than the average formula used
before.

Versioning was added to retain average conversion for old files.

Pull Request: https://projects.blender.org/blender/blender/pulls/133206
2025-01-24 09:40:43 +01:00
Brecht Van Lommel
7a0a173d39 Fix: Missed case of OCIO luminance coefficients in EEVEE
Following up on #133368. Thanks Omar for spotting this.

Pull Request: https://projects.blender.org/blender/blender/pulls/133400
2025-01-22 11:19:02 +01:00
Omar Emara
3b28cf276e Compositor: Add Glare Highlights Smoothness and Max
This patch adds two new inputs to the Glare node, Highlights Smoothness
and Max Highlights. Smoothness allows the user to control how smooth the
highlights are after thresholding and Max allows the user to suppress
very high brightness pixels.

Those are essentially similar to the Knee and Clamp options in old EEVEE
bloom, though they work differently.

The issue with the Knee parameter in old EEVEE bloom, aside from being
named after a body part, is that it actually isn't smooth or continuous
around zero if the threshold is sufficiently close to zero relative to
the Knee parameter. That's because zero lies in the smoothing kernel
region in those cases, and since zero pixels becoming highlights is very
bad, EEVEE just returned zero as a special case for zero brightness, but
values like 0.0001 will be full blown highlights.

The new nicely named Smoothness input uses adaptive smoothing such that
the smoothing kernel size will be reduced as the threshold nears zero,
such that smoothed highlights will be continuous and smooth around zero.

The Max Highlights input is similar to clamped, it it suppresses very
bright highlights such that their brightness doesn't exceed the
specified max.

This is a partial implementation of #124176 to address #131325.

Pull Request: https://projects.blender.org/blender/blender/pulls/132864
2025-01-13 13:54:07 +01:00
Omar Emara
c37d51f73d Compositor: Allow tinting Glare
This patch adds two new inputs to the Glare node, Saturation and Tint.
Their function is to tint the color of Glare to any color the user
wants.

This is a partial implementation of #124176 to address #131325.

Pull Request: https://projects.blender.org/blender/blender/pulls/132744
2025-01-08 13:18:58 +01:00
Omar Emara
8f8ae302ba Refactor: Compositor: Moved wrapped translation to its own code
This patch moves wrapped translation from a special case of the general
transform algorithm to the Translate node. Since the Translate node is
the only user of this special case, it doesn't make sense to complicate
a generate algorithm with it. This will make future refactors of this
code easier.

Pull Request: https://projects.blender.org/blender/blender/pulls/132793
2025-01-08 12:42:13 +01:00
Brecht Van Lommel
920e709069 Refactor: Make header files more clangd and clang-tidy friendly
When using clangd or running clang-tidy on headers there are
currently many errors. These are noisy in IDEs, make auto fixes
impossible, and break features like code completion, refactoring
and navigation.

This makes source/blender headers work by themselves, which is
generally the goal anyway. But #includes and forward declarations
were often incomplete.

* Add #includes and forward declarations
* Add IWYU pragma: export in a few places
* Remove some unused #includes (but there are many more)
* Tweak ShaderCreateInfo macros to work better with clangd

Some types of headers still have errors, these could be fixed or
worked around with more investigation. Mostly preprocessor
template headers like NOD_static_types.h.

Note that that disabling WITH_UNITY_BUILD is required for clangd to
work properly, otherwise compile_commands.json does not contain
the information for the relevant source files.

For more details see the developer docs:
https://developer.blender.org/docs/handbook/tooling/clangd/

Pull Request: https://projects.blender.org/blender/blender/pulls/132608
2025-01-07 12:39:13 +01:00
Omar Emara
004e3d39fa Compositor: Improve Glare node UX
This patch redesigns the Glare node to improve the user experience. The
improvements are as follows.

Two new outputs were added, Glare and Highlights. The Glare output gives
the generated glare without the input, and is useful when the user wants
to adjust the glare before adding it to the image. The Highlights output
gives the areas that are considered highlights when computing the glare,
and is useful if the user wants to temporally check the highlights while
doing adjustments or wants to use those as a base for creating a custom
glare setup.

The Mix node option was removed and a new Strength single value input
was added to serve the same functionality. The Mix option had a range of
[-1, 1], where the [-1, 0] sub-range essentially controlled the strength
of the glare, 0 being full strength and -1 being zero strength. While
the [0, 1] range returned the generated glare with an attenuated version
of the image added, that is, it was useless except for the value of 1,
which returned the generate glare only.
Aside from being a very intuitive range, it also meant that the power of
glare can't be boosted beyond the full strength of, you guessed it, 0.
The newly added Strength input has a soft range of [0, 1] and can be
boosted beyond 1. If the users want the glare only, they can use the
newly provided Glare output.

The Size node option used for Bloom and Fog Glow was removed and a new
Size single value input was added. The Size node option had yet another
very intuitive range of [1, 9], and it was related exponentially to the
actual size of the Glare. For Bloom, the actual bloom size relative to
the image was 2^(Size-9), so a Size of 8 means the bloom covers half of
the image. For Fog Glow, the actual bloom size in pixels is 2^Size, so
the glare size is not relative to the image size and would thus change
as the image resolution change. Furthermore, the maximum possible glare
size was 512 pixels, and the user couldn't make fine adjustments to the
size.
The newly added Size input has a range [0, 1], where 1 means the glare
covers the entire image, 0.5 means it covers half the image, and so on.
That means it is consistent between Bloom and Fog Glow, it is relative
to the image size, it allows as large of a glare as possible, it is
continuous for Fog Glow, but not for Bloom because that requires an
algorithmic change that will be implemented separately.

The Threshold, Streaks, Streaks Angle, Iterations, Fade, and Color
Modulation node option was turned into a single value node input to
allow the option to be used in node groups.

---

Versioning was added to transfer node options into sockets, but it is
not all 1:1 versioning, since the old Size option was not relative to
the image size, so it depends on runtime information of the input size.
As a guess, we assume the render size in that case. Versioning the
[0, 1] range of the Mix option intentionally omits the attenuation of
the image input, because that is almost certainly not what the user
wants and was probably done thinking it controls the strength.

Glare code now sets the alpha channel to 1, that's because it was
already ignored in the mixing step, but now that we expose the Glare
output, we need to set it to 1. So this is not a functional change.

The get_glare_size() method was renamed for clarity since it now
conflicts with the newly added Size input.

---

This is a partial implementation of #124176 to address #131325. In
particular, it adjust existing functionality, it doesn't add any new
ones. Those will be added in separate patches.

Pull Request: https://projects.blender.org/blender/blender/pulls/132499
2025-01-07 11:15:26 +01:00
Omar Emara
b3623feab2 Compositor: Support node integer sockets
This patch adds support for using integer sockets in compositor nodes.
This involves updating the Result class, node tree compiler, implicit
conversion operation, multi-function procedure operation, shader
operation, and some operations that supports multiple types.

Shader operation internally treats integers as floats, doing conversion
to and from int when reading and writing. That's because the GPUMaterial
compiler doesn't support integers. This is also the same workaround used
by the shader system. Though the GPU module are eyeing adding support
for integers, so we will update the code once they do that.

Domain realization is not yet supported for integer types, but this is
an internal limitation so far, as we do not plan to add nodes that
outputs integers soon. We are not yet sure how realization should happen
with regards to interpolation and we do not have base functions to
sample integer images, that's why I decided to delay its implementation
when it is actually needed.

Pull Request: https://projects.blender.org/blender/blender/pulls/132599
2025-01-06 10:09:26 +01:00
Aras Pranckevicius
a401089a9d Cleanup: move compositor files out of realtime_compositor folder
By now it is just a "compositor", so move the files one folder up.
Things that were under realtime_compositor/intern move into
already existing intern folder.

Pull Request: https://projects.blender.org/blender/blender/pulls/132004
2024-12-17 10:34:24 +01:00