Commit Graph

1912 Commits

Author SHA1 Message Date
Aras Pranckevicius
0bfffdaf82 VSE: bilinear upscaling no longer adds transparent border around the image
Part of overall "improve image filtering situation" (#116980), this PR addresses
two issues:
- Bilinear (default) image filtering makes half a source pixel wide transparent
  border around the image. This is very noticeable when scaling images/movies up
  in VSE. However, when there is no scaling up but you have slightly rotated
  image, this creates a "somewhat nice" anti-aliasing around the edge.
- The other filtering kinds (e.g. cubic) do not have this behavior. So they do
  not create unexpected transparency when scaling up (yay), however for slightly
  rotated images the edge is "jagged" (oh no).

More detail and images in PR.

Pull Request: https://projects.blender.org/blender/blender/pulls/117717
2024-02-02 16:28:51 +01:00
Omar Emara
ce2a945dff Cleanup: Correctly name bokeh blur shaders
The bokeh blur shaders are incorrectly named as standard blur shaders,
while this isn't the case. Rename them to include the bokeh keyword.
2024-02-02 13:15:59 +02:00
Hans Goudey
dccf0e8699 Cleanup: Move GPU_material.h to C++ 2024-02-01 10:40:30 -05:00
Sybren A. Stüvel
e2c4058d6c Fix build error when compiling without OpenImage denoiser
Fix build error when compiling `WITH_OPENIMAGEDENOISE=OFF`.

No functional changes, just a working build.
2024-02-01 10:21:42 +01:00
Sergey Sharybin
8315143c59 Compositor: Allow early abort of OIDN denoiser
This change makes it so the OIDN is listening to the node execution
being cancelled, allowing for a more instant user feedback on the
compositor graph changes. It is especially visible when dealing with
4k images, and using pre-filter on the guiding passes.

Similar implementation to what Cycles does.

This change covers tiles and full-frame compositors.
The GPU compositor needs extra work to have this supported.

Pull Request: https://projects.blender.org/blender/blender/pulls/117698
2024-01-31 17:12:09 +01:00
Hans Goudey
69d2dd0731 Cleanup: Remove unnecessary keywords in C++ headers 2024-01-30 14:56:04 -05:00
Omar Emara
049b0e6539 Compositor: Rewrite and optimize Double Edge Mask node
This patch rewrites and optimizes the Double Edge Mask node to be orders
of magnitude faster. For a 1k complex mask, it is 650x faster, while for
a 1k simple mask, it is only 50x faster.

This improvement is attributed to the use of a new Jump Flooding
algorithm as well as multi-threading, matching the GPU implementation.

The result of the new implementation differs in that the boundaries of
the masks are now identified as the last pixels inside the mask.

Pull Request: https://projects.blender.org/blender/blender/pulls/117545
2024-01-30 19:49:32 +01:00
Omar Emara
316f14b834 Compositor: Unify behavior of Z Combine node across CPU and GPU
The GPU implementation of the Use Alpha option of the Z Combine node
only worked if the first image is closer, since it sampled the alpha
channel from it and used it for mixing. Instead, the mix factor should
depend on the closer pixel, like the CPU implementation.
2024-01-30 18:48:58 +02:00
Omar Emara
5d0b506463 Fix: Z Combine node switches inputs when changing Use Alpha
The Z Combine node switches its inputs when changing the Use Alpha
option if both Z values are equal. That's because the operations used by
the node internally use two different conditions, less than and less
than or equal. This patch fixes that by unifying it to the less than
case.
2024-01-30 18:45:40 +02:00
Omar Emara
1aafb6802b Compositor: Use SMAA for anti-aliasing in all nodes
This patch changes all anti-aliasing operations to use SMAA instead of
the Scale3x-based operation. That's because SMAA is more accurate while
the Scale3x one is more a hack.
2024-01-29 18:44:10 +02:00
Omar Emara
8b7b165ad9 Fix: Compositor lighten mix mode is wrong for factors < 1
The Lighten mix mode in the Mix RGB node is wrong for factors less than
one. The lighten blend mode is a simple component-wise maximum in EEVEE,
Cycles, and other implementations. While the compositor seems to define
it as a weighted maximum using the factor as the weight. It should be
noted that its Darken counterpart is correctly implemented for the same
node, so Lighten should follow, which this patch do.

GPU compositor shares the EEVEE code, so it is already correct.

Pull Request: https://projects.blender.org/blender/blender/pulls/117630
2024-01-29 15:58:57 +01:00
Omar Emara
5cc76ea118 Fix: Mask node has an output even with no mask
The Mask compositor node still has an output even when no mask is
selected in the node. Fix this by outputing a single zero value in that
case.
2024-01-29 16:55:53 +02:00
Jacques Lucke
932b2d1727 Cleanup: simplify naming of get_default_hash 2024-01-26 11:45:56 +01:00
Sergey Sharybin
ca767644eb Compositor: Align matte edge calculation to GPU implementation
The CPU implementation had the following downsides:

- The kernels sizes below 3 did not make much sense, often leading
  to a full white image.
- The way how the total number of pixels in the kernel was calculated
  quite strangely.

From these points of view the GPU compositor behaves more user friendly.

There is a versioning code which lowers the kernel size, to match the
result prior to these tweaks.

Pull Request: https://projects.blender.org/blender/blender/pulls/117505
2024-01-25 15:57:15 +01:00
Aras Pranckevicius
5ed2eea0f6 ImBuf: Refactor pixel interpolation functions
There exist a bunch of "give me a (filtered) image pixel at this location"
functions, some with duplicated functionality, some with almost the same but
not quite, some that look similar but behave slightly differently, etc.
Some of them were in BLI, some were in ImBuf.

This commit tries to improve the situation by:
* Adding low level interpolation functions to `BLI_math_interp.hh`
  - With documentation on their behavior,
  - And with more unit tests.
* At `ImBuf` level, there are only convenience inline wrappers to the above BLI
  functions (split off into a separate header `IMB_interp.hh`). However, since
  these wrappers are inline,   some things get a tiny bit faster as a side
  effect. E.g. VSE image strip, scaling to 4K resolution (Windows/Ryzen5950X):
  - Nearest filter: 2.33 -> 1.94ms
  - Bilinear filter: 5.83 -> 5.69ms
  - Subsampled3x3 filter: 28.6 -> 22.4ms

Details on the functions:
- All of them have `_byte` and `_fl` suffixes.
- They exist in 4-channel byte (uchar4) and float (float4), as well as
  explicitly passed amount of channels for other float images.
- New functions in BLI `blender::math` namespace:
  - `interpolate_nearest`
  - `interpolate_bilinear`
  - `interpolate_bilinear_wrap`. Note that unlike previous "wrap" function,
    this one no longer requires the caller to do their own wrapping.
  - `interpolate_cubic_bspline`. Previous similar function was called just
    "bicubic" which could mean many different things.
- Same functions exist in `IMB_interp.hh`, they are just convenience that takes
  ImBuf and uses data pointer, width, height from that.

Other bits:
- Renamed `mod_f_positive` to `floored_fmod` (better matches `safe_floored_modf`
  and `floored_modulo` that exist elsewhere), made it branchless and added more
  unit tests.
- `interpolate_bilinear_wrap_fl` no longer clamps result to 0..1 range. Instead,
  moved the clamp to be outside of the call in `paint_image_proj.cc` and
  `paint_utils.cc`. Though the need for clamping in there is also questionable.

Pull Request: https://projects.blender.org/blender/blender/pulls/117387
2024-01-25 11:45:24 +01:00
Sergey Sharybin
aca0cf27e3 Fix cryptomatte GPU compositor node on NVidia Linux
This commit fixes node_cryptomatte test in the matte category
when using GPU compositor on Linux with NVidia GPU. Before this
fix the result image was squished horizontally.

The issue was caused by mismatch in the shader info and the
actual allocation of the matte image.

Pull Request: https://projects.blender.org/blender/blender/pulls/117475
2024-01-24 13:58:47 +01:00
Omar Emara
70a8a9e4d9 Compositor: make Flip node works in local space
This patch changes the operation space of the Flip node from the global
space to the local space. This means that the Flip node will now flip
the image without changing its location.
2024-01-24 11:08:41 +02:00
Sergey Sharybin
dd1374fb7b Fix keying matte operation in GPU compositor
The calculation of the matte could lead to a division-by-zero
leading to completely different results on different graphics
backends.

Perform the same checks of the input and key saturation before
performing division as it is done in the CPU compositors.

The `node keying matte` test is still failing on Metal, but the
look of the result is much closer to what it would be.
2024-01-24 09:55:48 +01:00
Hans Goudey
99f9084bee Cleanup: Replace some CLAMP macros with C++ functions
Pull Request: https://projects.blender.org/blender/blender/pulls/117460
2024-01-23 21:10:33 +01:00
Omar Emara
46322e4927 Fix: Compositor Texture node differ between CPU and GPU
The compositor Texture node differ between CPU and GPU. That's because
CPU falls back to the texture intensity as the alpha channel if no alpha
channel exists. And it also broadcast the texture intensity to all color
channels if no RGB evaluation exist. So adjust the GPU implementation to
follow that.
2024-01-23 11:59:38 +02:00
Omar Emara
02fc4d6481 Fix: Tonemap node has a wrong luminance scale
The Tonemap node has a wrong luminance scale. This is because the
parallel reduction shader for logarithmic sum had a wrong identity
value. In particular, its identity was set to 0.0, but since its
initialization macro computed the log, the zero becomes a rather large
negative value.

To fix this, the general structure of the parallel reduction shader was
changed such that the identity is used as is, and not passed to the
INITIALIZE or LOAD macros. This simplifies the implementation and even
avoid the extra texel fetches at the boundary.
2024-01-22 22:03:05 +02:00
Hans Goudey
0618de49ad Cleanup: Replace MIN/MAX macros with C++ functions
Use `std::min` and `std::max` instead. Though keep MIN2 and MAX2
just for C code that hasn't been moved to C++ yet.

Pull Request: https://projects.blender.org/blender/blender/pulls/117384
2024-01-22 15:58:18 +01:00
Campbell Barton
d43988e014 Unbreak build from missing include 2024-01-22 11:54:10 +11:00
Bastien Montagne
d8d44a62f7 Cleanup: Move BKE_appdir.h to full Cpp header BKE_appdir.hh. 2024-01-21 19:42:13 +01:00
Aras Pranckevicius
d2e4da0f5b Cleanup: reduce C-isms in imbuf headers
Pull Request: https://projects.blender.org/blender/blender/pulls/117327
2024-01-19 20:29:43 +01:00
Aras Pranckevicius
a705259b4b Cleanup: move imbuf .h files to .hh 2024-01-19 20:29:38 +01:00
Omar Emara
4bf08198a7 Compositor: Do not flip bounds of Crop node
The Crop node currently flips its bounds if the lower bound is larger
than the higher bound, which is not a good design. Instead, clamp the
bounds.
2024-01-19 18:42:45 +02:00
Sergey Sharybin
73d9271701 Fix Keying Screen node on Metal GPU
The "Keying Screen" texture is written by the compositor_keying_screen
shader and is not read by the shader. Use appropriate usage flag which
matches the shader behavior.

Note that the texture is read by a node down the road, so both flags are
needed.

Pull Request: https://projects.blender.org/blender/blender/pulls/117340
2024-01-19 17:20:07 +01:00
Jacques Lucke
4b47b46f9c Cleanup: rename PIL to BLI
The term `PIL` stands for "platform independent library." It exists since the `Initial Revision`
commit from 2002. Nowadays, we generally just use the `BLI` (blenlib) prefix for such code
and the `PIL` prefix feels more confusing then useful. Therefore, this patch renames the
`PIL` to `BLI`.

Pull Request: https://projects.blender.org/blender/blender/pulls/117325
2024-01-19 14:32:28 +01:00
Martijn Versteegh
a3b7674c6e Compositor: Add a Nearest sampling to Map UV node
When using the MapUV node for certain NPR workflows (for example palette
based remapping of colors) it can be useful to not use the default
anisotropic filtering.

In preparation of potentially adding more filter modes at a later stage
and to keep things consistent with the 'transform' node we use the full
set of interpolation modes in the enum, but expose only the implemented
ones in RNA..
2024-01-19 13:24:22 +01:00
Omar Emara
23f90dea4c Fix #117317: Empty Defocus output when Z is less than 0
The Defocus node produces an empty output when the Z input is less than
0. This patch fixes that by ensuring zero or positive blur radius.
2024-01-19 13:19:22 +02:00
Omar Emara
d537e63fa6 Fix: Plane Deform mask retains original alpha
The Plane Deform mask output retains the original alpha of the input
image, while it should be a binary mask. This patch ignores the alpha of
the image and uses a binary mask instead.
2024-01-19 12:59:31 +02:00
Omar Emara
538ace5750 Fix: GPU Directional Blur distorts input
The GPU Directional Blur node distorts the inputs if the resolution is
not square. This is because rotation is performed on normalized
coordinates. This patch performs the normalization at the texture
evaluation.
2024-01-18 16:19:44 +02:00
Omar Emara
feb2d02709 Realtime Compositor: Rewrite Pixelate node
This patch rewrites the pixelate node to average a window of a certain
pixel size, following the new CPU implementation.

Pull Request: https://projects.blender.org/blender/blender/pulls/117243
2024-01-18 11:52:20 +01:00
Omar Emara
5309d1c574 Fix: Crash in Defocus node when no camera exist
The Defocus node crashes when no camera exist in the scene. We fix this
by defaulting to a focus distance of 10 when a camera doesn't exist.
2024-01-18 12:34:55 +02:00
Sergey Sharybin
baab14ca38 Compositor: Re-write Pixelate node for CPU compositor
The old implementation was a simple rounding operation and was not
implemented for full-frame compositor.

The issue with the old implementation is that it will not give
satisfactory results for images with high frequency details,
including cases when is used for a preview on Cycles render with
low number of samples. Additionally, when applied on animated
footage it produces very noisy result.

The new algorithm uses an explicit pixel size setting, which allows
the node to be used on its own, without need to have scale-down and
scale-up nodes. It also uses neighbour averaging, which produces
better looking result during animation and noisy input images.

The old tiled compositor setup will render without changes with
this change. This commit does not include modifications in the GPU
compositor implementation.

Ref #88150

Pull Request: https://projects.blender.org/blender/blender/pulls/117223
2024-01-18 11:30:55 +01:00
Omar Emara
e4a93d7b8c Compositor: Add High Precision option to Kuwahara
For high radii Kuwahara, we use a Summed Area Table (SAT) implementation
to accelerate the classic variant of the algorithm. The problem is that
due to limited floating point precision, the SAT can produce artifacts
in its output.

An attempt to fix this was implemented in #114191, and while that patch
improved precision by 10x, the artifacts still existed, albeit less
noticeable. But since the improved precision also meant a performance
penalty, it was decided that the improvement is not worth it.

Since the artifacts are only noticeable for scenes with very high
values, this patch adds a High Precision option that defaults to false
and can be enabled by the user upon noticing any artifacts. The option
simply uses direction convolution instead of SAT in this case. The
downside, of course, is that it can be orders of magnitude slower.

An alternative to using this option is for the user to clamp the input
or downsample the image. Both methods should be documented in the
documentation.

Fixes: #113578.

Pull Request: https://projects.blender.org/blender/blender/pulls/115763
2024-01-17 14:30:29 +01:00
Omar Emara
65e1a3a5c3 Compositor: Port redesigned Defocus node to CPU
This patch ports the redesigned GPU Defocus node to the CPU.

Pull Request: https://projects.blender.org/blender/blender/pulls/117174
2024-01-17 13:19:10 +01:00
Hans Goudey
3e76a1a6c2 Cleanup: Move BKE_lib_id.h to C++ 2024-01-15 12:44:14 -05:00
Aras Pranckevicius
709b00179f VSE: add Bicubic filtering option, and optimize bicubic performance
Part of overall "improve filtering situation" (#116980) task:

* Add Bicubic filtering option to strip Transform "Filter" setting.
Previously this option only existed in Transform Effect "Interpolation"
setting.
  - With this addition, it feels like the transform effect could
    possibly be marked as legacy/deprecated, since the regular Transform
    that is on all strips can do everything that Transform Effect did?
* Speed up bicubic filtering (used now in VSE, but also in CPU Compositor,
  image paint, etc.) by slightly simplifying the code and using some SIMD.
  Upscaling 96x54 image to 3840x2160 resolution, using Bicubic filtering:
  - Windows (VS2022, Ryzen 5950X): 35.5ms -> 15.1ms
  - Mac (clang 15, M1 Max): 29.6ms -> 24.4ms
* Add gtest coverage for bicubic functionality.

Pull Request: https://projects.blender.org/blender/blender/pulls/117100
2024-01-15 16:38:41 +01:00
Damien Picard
3bd41cf9bc I18n: Go over TIP_ and IFACE_ usages, change to RPT_ when relevant
The previous commit introduced a new `RPT_()` macro to translate
strings which are not tooltips or regular interface elements, but
longer reports or statuses.

This commit uses the new macro to translate many strings all over the
UI.

Most of it is a simple replace from `TIP_()` or `IFACE_()` to
`RPT_()`, but there are some additional changes:
- A few translations inside `BKE_report()` are removed altogether
  because they are already handled by the translation system.
- Messages inside `UI_but_disable()` are no longer translated
  manually, but they are handled by a new regex in the translation
  system.

Pull Request: https://projects.blender.org/blender/blender/pulls/116804

Pull Request: https://projects.blender.org/blender/blender/pulls/116804
2024-01-12 13:37:32 +01:00
Omar Emara
e84dc990b1 Realtime Compositor: Implement Vector Blur node
This patch implements the Vector Blur node for the Realtime Compositor.
The implementation is a direct and mostly identical port of the EEVEE
motion blur implementation with the necessary adjustments to make it
work with the compositor.

The exposed parameters in the node does not match those exposed in
EEVEE, so only the parameters shared between both are currently
implemented. In the future, we should make a decision to either unify
both, or just consider them independent implementations, with the
possibility of sharing the full or part of the code.

Further, it would also make sense to port the implementation to the CPU
compositor, since the new implementation is higher in quality while also
being faster.

The default value of the node shutter setting was changed to 0.25 to
approximately match the default settings of EEVEE and Cycles, since in
their default settings, they evaluate the previous and next frames at
plus and minus 0.25.

Pull Request: https://projects.blender.org/blender/blender/pulls/116977
2024-01-12 12:12:01 +01:00
Campbell Barton
7a4f7a1d51 Cleanup: spelling in comments, comment blocks 2024-01-11 16:46:46 +11:00
Omar Emara
cbb738191e Compositor: Redesign Sun Beams node for CPU
This patch ports the new GPU implementation of the Sun Beams node to the
CPU compositor. Introduced in 9e358fcd44.
2024-01-10 19:36:52 +02:00
Brecht Van Lommel
5cc0c0671e Fix: build error when not using unity build 2024-01-10 18:06:28 +01:00
Omar Emara
9e358fcd44 Compositor: Redesign Sun Beams node
This patch redesigns the Sun Beams node. The old implementation produces
unexpected results with an arbitrary alpha channel, due to the use of a
step count normalization instead of a weighted normalization. The
quality is also questionable due to the use of nearest neighbour
interpolation as well as a low resolution integration.

This patches redesign the node to be a simple line integration towards
the source, limited by the maximum ray length. The sampling resolution
covers the entire path of the integration and the image is sampled using
bilinear filtering, producing smoother results. No alpha is introduced.

Pull Request: https://projects.blender.org/blender/blender/pulls/116787
2024-01-10 14:30:58 +01:00
Omar Emara
08130211b1 Fix: GPU Directional Blur node does not match CPU
The GPU Directional Blur node does not match CPU. This is because GPU
accumulates the scale, while the CPU increments it. This patch
incremenets the scale for the GPU to make them match.
2024-01-08 13:42:32 +02:00
Campbell Barton
617f7b76df Cleanup: comment block formatting 2024-01-08 11:31:43 +11:00
Campbell Barton
0ba83fde1f Cleanup: spelling in comments 2024-01-08 11:24:37 +11:00
Bastien Montagne
95b30b3516 Build: Ninja: Move 'Unity builds' to heavy pooljobs.
This commit adds a new helper to define expected properties when a
target needs to use the unity build feature.

That new helper does what was already done for existing cases, and in
addition add the target to the Ninja 'heavy' pooljobs if relevant.

Pull Request: https://projects.blender.org/blender/blender/pulls/116791
2024-01-05 18:35:48 +01:00