Commit Graph

2414 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
Miguel Pozo
e6638d6e5e Refactor: GPU: GPUMaterial & GPUPass compilation
Cleanup and simplification of GPUMaterial and GPUPass compilation.
See #133674 for details/goals.

- Remove the `draw_manage_shader` thread.
  Deferred compilation is now handled by the gpu::ShaderCompiler
  through the batch compilation API.
  Batch management is handled by the `GPUPassCache`.
- Simplify `GPUMaterial` status tracking so it just queries the
  `GPUPass` status.
- Split the `GPUPass` and the `GPUCodegen` code.
- Replaced the (broken) `GPU_material_recalc_flag_get` with the new
  `GPU_pass_compilation_timestamp`.
- Add the `GPU_pass_cache_wait_for_all` and
  `GPU_shader_batch_wait_for_all`, and remove the busy waits from
   EEVEE.
- Remove many unused functions, properties, includes...

Pull Request: https://projects.blender.org/blender/blender/pulls/135637
2025-05-22 17:53:22 +02:00
Omar Emara
f790547fe9 Compositor: Use realize size for relative to pixel conversion
The Relative To Pixel node considers the original resolution of the
image with no transformation, while it is more useful for it to consider
the realized size instead, because that's what later processing nodes
will be using.
2025-05-21 10:31:09 +03: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
Jeroen Bakker
542e7bb8e7 Compositor: Add GPU debug groups
This PR adds debug groups to improve using GPU tools like debuggers
and profilers. It will try to use the node type as debug group name when
available.

Pull Request: https://projects.blender.org/blender/blender/pulls/138768
2025-05-12 15:45:45 +02:00
Omar Emara
17db65dfd0 Compositor: Remove Gamma from Blur and Defocus nodes
This patch removes the Gamma option from the Defocus and Blur nodes. The
reasoning is as follows.

- The option was originally added when the compositor wasn't working on
  a strictly linear workflow. So this is rarely needed now.
- It is easy to insert a Gamma node around Blur nodes to perform any
  gamma correction if really needed.
- Since we are moving options to inputs, it doesn't seem worth it to
  provide this option as an input in the process.

Pull Request: https://projects.blender.org/blender/blender/pulls/138673
2025-05-12 13:18:46 +02:00
Sergey Sharybin
7ceb4495c5 Refactor: OpenColorIO integration
Briefly about this change:
- OpenColorIO C-API is removed.
- The information about color spaces in ImBuf module is removed.
  It was stored in global ListBase in colormanagement.cc.
- Both OpenColorIO and fallback implementation supports GPU drawing.
- Fallback implementation supports white point, RGB curves, etc.
- Removed check for support of GPU drawing in IMB.

Historically it was implemented in a separate library with C-API, this
is because way back C++ code needed to stay in intern. This causes all
sort of overheads, and even calls that are strictly considered bad
level.

This change moves OpenColorIO integration into a module within imbuf,
next to movie, and next to IMB_colormanagement which is the main user
of it. This allows to avoid copy of color spaces, displays, views etc
in the ImBuf: they were used to help quickly querying information to
be shown on the interface. With this change it can be stored in the
same data structures as what is used by the OpenColorIO integration.
While it might not be fully avoiding duplication it is now less, and
there is no need in the user code to maintain the copies.

In a lot of cases this change also avoids allocations done per access
to the OpenColorIO. For example, it is not needed anymore to allocate
image descriptor in a heap.

The bigger user-visible change is that the fallback implementation now
supports GLSL drawing, with the whole list of supported features, such
as curve mapping and white point. This should help simplifying code
which relies on color space conversion on GPU: there is no need to
figure out fallback solution in such cases. The only case when drawing
will not work is when there is some actual bug, or driver issue, and
shader has failed to compile.

The change avoids having an opaque type for color space, and instead
uses forward declaration. It is a bit verbose on declaration, but helps
avoiding unsafe type-casts. There are ways to solve this in the future,
like having a header for forward declaration, or to flatten the name
space a bit.

There should be no user-level changes under normal operation.
When building without OpenColorIO or the configuration has a typo or
is missing a fuller set of color management tools is applies (such as the
white point correction).

Pull Request: https://projects.blender.org/blender/blender/pulls/138433
2025-05-09 14:01:43 +02:00
Hans Goudey
f90e448c6a Cleanup: Use blender::Mutex for various static mutexes
Change almost all `static ThreadMutex` to `static blender::Mutex`.
See b7a1325c3c.

Pull Request: https://projects.blender.org/blender/blender/pulls/138556
2025-05-07 19:32:00 +02:00
Hans Goudey
e51d538ee8 Refactor: Move image runtime out of DNA
Like other runtime structs, it doesn't make sense to write this
data to files. And moving it out of DNA to an allocated C++ struct
means we can use other C++ features in it, like the new Mutex
type which I switched to in this commit.

Pull Request: https://projects.blender.org/blender/blender/pulls/138551
2025-05-07 18:01:34 +02: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
Miguel Pozo
f24ad7a470 Build: Add WITH_OPTIMIZED_BUILD_TOOLS
Enable optimizations on Debug builds for executables used for the build
process (datatoc and glsl_preprocess) and enable unity builds for
shader preprocessing targets.

Debug: From 28.9s to 5.7s
Release: From 4.9s to 3.5s

Pull Request: https://projects.blender.org/blender/blender/pulls/138274
2025-05-02 18:33:44 +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
Campbell Barton
43af16a4c1 Cleanup: spelling in comments, correct comment block formatting
Also use doxygen comments more consistently.
2025-05-01 11:44:33 +10: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
Clément Foucault
d24b0e4a4e GPU: Remove runtime parsing of GLSL source
See #129009 for context.

The preprocessor parses metadata and writes a header file containing
an inline function that inits the `GPUSource` with the metadata.

These header files are then included inside `gpu_shader_dependency.cc`.

This still keep the usage of the `metadata` enums and classes to avoid
pulling the whole blender module inside the preprocessor executable.

This speeds-up startup time in Debug build:
`gpu_shader_dependency_init`
- Before : 37ms
- After : 4ms

I didn't measure release, but it is unlikely to be noticeable (in the
order of 4ms > 1ms).

Pull Request: https://projects.blender.org/blender/blender/pulls/138070
2025-04-29 15:32:36 +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
d4a57e6cbb Fix #138001: File output node with no inputs crash
Blender crashes when rendering a scene that has a file output node with
no inputs. That's because the preview code assumes that nodes would
always have inputs. So we simply guard against this case.
2025-04-28 13:41:10 +03: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
Campbell Barton
3933f45f52 Cleanup: move doc-strings to declarations
Move into headers or to the top of the function body for internal
implementation details, in some cases remove duplicate doc-strings.
2025-04-18 22:58:36 +10:00
Lukas Stockner
160c5e7b44 Fix: Compositor: Crash in Movie Distortion node with extreme distortions (again)
Second version of 2dff457a7c, now without breaking negative deltas.
Thanks to @OmarEmaraDev for the suggestion.
2025-04-15 23:32:24 +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
Omar Emara
aacd22c186 Fix: Compositor: Boolean socket fails in shader node
Boolean sockets were not handled in shader nodes, so they were assigned
a NONE GPU type which causes crashes later on. No such sockets exist
yet, so this is a fix for future work.
2025-04-15 12:51:41 +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
Campbell Barton
5741e28770 Revert "Fix: Compositor: Crash in Movie Distortion node with extreme distortions"
This reverts commit 2dff457a7c.

This caused compositor_cpu_distort test to fail.
2025-04-15 15:26:14 +10:00
Lukas Stockner
2dff457a7c Fix: Compositor: Crash in Movie Distortion node with extreme distortions
While testing some distortion options, I noticed that the Movie Distortion node
would crash when used with e.g. (0.0, 0.0, 0.5) as the lens parameters.

This appears to be caused by 00ee917fd. Turns out that even though the input was
512x384, the extended size ended up being around 600000x500000, which obviously
caused some issues.

Therefore, this patch a) clamps the margin to be at most as wide as the input
(so 9x the pixels in the worst case) and b) fixes the indexing calculations to
not overflow the int32 values in case the input is legitimately huge.

Pull Request: https://projects.blender.org/blender/blender/pulls/137440
2025-04-14 20:29:42 +02:00
Jacques Lucke
7f1a99e862 Refactor: BLI: Make some CPPType properties public instead of using methods
This makes accessing these properties more convenient. Since we only ever have
const references to `CPPType`, there isn't really a benefit to using methods to
avoid mutation.

Pull Request: https://projects.blender.org/blender/blender/pulls/137482
2025-04-14 17:48:17 +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
Campbell Barton
af1110fb3c Render: support pixel density in the render pipeline
Add a "Pixel Density" sub-panel to render output settings which
can be used to set the density (as pixels per inch for example).

This is then written to images that support pixel density.

Details:

- The scene has two values a PPM factor and a and base unit.
- The base unit defaults to pixels per inch as this is the most
  common unit used.
- Unit presets for pixels per inch/centimeter/meter are included.
- The pixel density is stored in the render result & EXR cache.
- For non 1:1 aspect renders, the density increases on the axis
  which looks "stretched", so the PPM will print the correct
  aspect with non-square pixels.

Ref !127831
2025-04-05 08:49:22 +00:00
Omar Emara
cc21dcb436 Fix #136866: Voronoi 1D crashes GPU compositor
The GPU compositor crashes if 1D Voronoi is used. That's because the
vector input is unavailable in that mode, but the GPU material compiler
considers all inputs, even unavailable ones. So we need to link those
sockets to some arbitrary constant value.
2025-04-04 14:04:05 +02:00
Omar Emara
cc84830abc Cleanup: No previous declaration warning 2025-04-04 12:47:29 +02:00
Omar Emara
56b0b709ea Compositor: Support GPU OIDN denoising
This patch supports GPU OIDN denoising in the compositor. A new
compositor performance option was added to allow choosing between CPU,
GPU, and Auto device selection. Auto will use whatever the compositor is
using for execution.

The code is two folds, first, denoising code was adapted to use buffers
as opposed to passing in pointers to filters directly, this is needed to
support GPU devices. Second, device creation is now a bit more involved,
it tries to choose the device is being used by the compositor for
execution.

Matching GPU devices is done by choosing the OIDN device that matches
the UUID or LUID of the active GPU platform. We need both UUID and LUID
because not all platforms support both. UUID is supported on all
platforms except MacOS Metal, while LUID is only supported on Window and
MacOS metal.

If there is no active GPU device or matching is unsuccessful, we let
OIDN choose the best device, which is typically the fastest.

To support this case, UUID and LUID identifiers were added to the
GPUPlatformGlobal and are initialized by the GPU backend if supported.
OpenGL now requires GL_EXT_memory_object and GL_EXT_memory_object_win32
to support this use case, but it should function without it.

Pull Request: https://projects.blender.org/blender/blender/pulls/136660
2025-04-04 11:17:08 +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
Jorn Visser
3561b11851 Fix #136310: Crash when using both viewport and normal compositor with fog glow
The issue is caused by the fact that when both compositors are used,
`fftwf_plan_dft_r2c_2d` can end up being called in parallel, which is
only thread-safe if `fftwf_make_planner_thread_safe` is called before.
This is done by `fftw::initialize_float`, but only if the FFTW threading
support library is available. Said library was not detected correctly on
Windows because of a typo, which this change addresses. This should also
make the fog glow faster on Windows because it'll now use multithreaded
FFT as intended.

This change also moves the call to `initialize_float` to the main
function because the FFTW functions it calls are not thread-safe and
because FFTW is also used by Audaspace, which cannot call it.

Pull Request: https://projects.blender.org/blender/blender/pulls/136557
2025-03-27 10:20:15 +01:00
David Murmann
afee81753e OpenEXR: Preserve compression and depth settings when re-saving file
Set the flags on the image buffer when loading an EXR file, so they can be
used when saving.

This also removes IB_halffloat and replaces it by the file options flag.

Pull Request: https://projects.blender.org/blender/blender/pulls/135656
2025-03-26 21:35:20 +01:00
Omar Emara
c0fe2ef766 Compositor: Use input order for unset domain priority
This patch makes it such that the compositor fallback to using the
order of the inputs to infer the domain priority if no domain priority
is specified. This is more robust since some nodes do not declare their
domain priorities and indirectly rely on the order of insertions in some
containers and thus might fail in the future.

We opt for this as opposed to requiting all nodes to declare their
priorities for code brevity.
2025-03-26 16:14:05 +02:00
Omar Emara
36154a1ab4 Compositor: Initial support for implicit inputs
This patch adds initial support for implicit inputs in pixel operations.
This is currently a non-functional change but will be used in the
future to support implicit inputs in texture nodes or so.

This works by exposing extra inputs to pixel operation for each of the
supported implicit input types if needed, and linking those inputs to
instances of the ImplicitInputOperation operation.

Only a single implicit input exist for now and we do not differentiate
between any of the implicit inputs type. In order to do that, we need to
refactor how input declarations for implicit inputs happen, since they
are now tied to the Geometry Nodes specifically.
2025-03-26 13:42:21 +02:00