Commit Graph

2049 Commits

Author SHA1 Message Date
Omar Emara
73aea76202 Fix: Map UV and Displace nodes produce wrong outputs
The Map UV and Displace nodes produce unexpected outputs. That's because
the derivatives computed for anisotropic filter were computed in the
sampler's space, while it should be in texel space, as expected bu the
textureGrad function.
2024-05-06 15:26:20 +03:00
Omar Emara
7f222d0fe2 Fix #121305: Corner Pin node returns single color
The Corner Pin node as well as the Plane Track Deform nodes always
return a single color that appears to be the average of the input.
That's because the derivatives were computed in the sampler's space,
while they should be in texel space. Large derivatives meant that the
textureGrad function would always sample the lowest MIP level, hence the
constant average color.

This might be an issue with other uses of textureGrad in the compositor,
so their use should be investigated.
2024-05-06 13:36:03 +03:00
Omar Emara
9a3c7290a9 Fix #121447: Simple Blur node takes too long
The Blur node takes too long to execute even though it is in a simple
configuration. That's because the CPU compositor uses variable size
blurring even if the size is constant. So ensure the input size is
actually variable before using variable size blurring.
2024-05-06 10:46:05 +03:00
Campbell Barton
9918488bb1 Cleanup: use uppercase tags, following own style guide 2024-05-03 11:33:21 +10:00
Sergey Sharybin
1b0012d51c Refactor: Require C++ for users of BLI_simd.h
This is because sse2neon.h might be used to emulate SSE intrinsics
on ARM64 architecture, and it uses some preprocessor which is not
available for C language when using MSVC.

The old-style math file math_matrix.c uses this header, so needed
to become C++. Simple rename did not work since there is a new math
utility math_matrix.cc exists. Following some existing convention
the math_matrix.c is renamed to math_matrix_c.cc. Eventually all the
code should switch to use C++ style math, and the C style removed,
so it seems reasonable to not mix old and new style of API in the
same file.

There should be no functional changes.

Pull Request: https://projects.blender.org/blender/blender/pulls/121335
2024-05-02 16:22:19 +02:00
Campbell Barton
530999fb76 Cleanup: add missing SPDX-FileCopyrightText 2024-05-02 16:46:26 +10:00
Habib Gahbiche
483c854612 Compositor: implement interpolation methods for Translate node
Compositor: Expose interpolation methods Nearest, Bilinear and Bicubic to the user for translate node

This is part of #119592.

Pull Request: https://projects.blender.org/blender/blender/pulls/119603
2024-05-01 14:44:01 +02:00
Omar Emara
74300f88a0 Cleanup: Missing include in recursive blur algorithm 2024-05-01 12:08:08 +03:00
Omar Emara
382131fef2 Realtime Compositor: Implement Fast Gaussian blur
This patch implements the Fast Gaussian blur mode for the Realtime
Compositor. This is a faster but less accurate implementation of
Gaussian blur.

This is implemented as a recursive Gaussian blur algorithm based on the
general method outlined in the following paper:

 Hale, Dave. "Recursive gaussian filters." CWP-546 (2006).

In particular, based on the table in Section 5 Conclusion, for very low
radius blur, we use a direct separable Gaussian convolution. For medium
blur radius, we use the fourth order IIR Deriche filter based on the
following paper:

  Deriche, Rachid. Recursively implementating the Gaussian and its
  derivatives. Diss. INRIA, 1993.

For high radius blur, we use the fourth order IIR Van Vliet filter based
on the following paper:

  Van Vliet, Lucas J., Ian T. Young, and Piet W. Verbeek. "Recursive
  Gaussian derivative filters." Proceedings. Fourteenth International
  Conference on Pattern Recognition (Cat. No. 98EX170). Vol. 1. IEEE,
  1998.

That's because direct convolution is faster and more accurate for very
low radius, while the Deriche filter is more accurate for medium blur
radius, while Van Vliet is more accurate for high blur radius. The
criteria suggested by the paper is a sigma value threshold of 3 and 32
for the Deriche and Van Vliet filters respectively, which we apply on
the larger of the two dimensions.

Both the Deriche and Van Vliet filters are numerically unstable for high
blur radius. So we decompose the Van Vliet filter into a parallel bank
of smaller second order filters based on the method of partial fractions
discussed in the book:

  Oppenheim, Alan V. Discrete-time signal processing. Pearson Education
  India, 1999.

We leave the Deriche filter as is since it is only used for low radii
anyways.

Compared to the CPU implementation, this implementation is more
accurate, but less numerically stable, since CPU uses doubles, which is
not feasible for the GPU.

The only change of behavior between CPU and this implementation is that
this implementation uses the same radius, so Fast Gaussian will match
normal Gaussian, while the CPU implementation has a radius that is 1.5x
the size of normal Gaussian. A patch to change the CPU behavior #121211.

Pull Request: https://projects.blender.org/blender/blender/pulls/120431
2024-05-01 09:57:30 +02:00
Omar Emara
f595345f52 Compositor: Match size of Fast Gaussian with Gaussian
This patch matches the size of the Fast Gaussian mode of blur with the
standard Gaussian mode. The sigma value was computed as half the radius,
while it should be third of the radius, since Blender's Gaussian
function is truncated at 3 of the standard deviation of the unit
Gaussian. The patch include versioning to adjust the size of existing
files.

Pull Request: https://projects.blender.org/blender/blender/pulls/121211
2024-05-01 09:01:53 +02:00
Omar Emara
98043d3fc3 Fix #121264: Crash when File Output has preview
Blender crashes when a File Output was created when the Use Preview
option of the render output settings was enabled. This is a regression
introduced in 931c188ce5, where the image format of the node was
initialized from the scene image settings, so the preview option was
carried over, yet it is not supported nor exposed to the user in the
File Output node. To fix this, ensure the file output code will ignore
previews.
2024-04-30 17:44:02 +03:00
Aaron Carlisle
f5157b00a9 Compositor: Remove left over code from tile based compositor
The compositor used to have a feature that would calculate tiles for the viewer based on a custom order. Since the removal of the tile based compositor, this code is unused.

Pull Request: https://projects.blender.org/blender/blender/pulls/121176
2024-04-30 13:47:45 +02:00
Omar Emara
0eacf3cfef Cleanup: Clarify variable names in Fast Gaussian 2024-04-29 15:15:37 +03:00
Omar Emara
3d2a2a9bd2 Cleanup: Remove unused FastGaussianBlurValueOperation 2024-04-29 14:52:18 +03:00
Campbell Barton
c0def6c93d Cleanup: spelling in comments 2024-04-27 11:58:02 +10:00
Campbell Barton
019d3ef939 Cleanup: spelling in comments 2024-04-24 10:48:45 +10:00
Omar Emara
614e5ecf7d Fix #120857: Blender crashes for huge compositor images
Blender crashes when the user scales up an image into huge scales. This
is due to integer overflow when doing memory allocations. So we fix this
by using larger integers when doing math on memory allocations and
indexing.

Note that while this solves the random crashes, users scaling up images
to huge scales will face things like the OOM killer activating or at
best significant slow downs due to swapping.

It is not clear how to handle such cases, but something like a global
maximum size option that is set to 16k by default might be worth adding.

Pull Request: https://projects.blender.org/blender/blender/pulls/120921
2024-04-23 09:44:33 +02:00
Habib Gahbiche
f1d4859e2a Compositor: implement bicubic spline for CPU compositor
Affected nodes:
- Rotate
- Translate
- Stabilize 2D node

Pull Request: https://projects.blender.org/blender/blender/pulls/120886
2024-04-22 20:58:43 +02:00
Campbell Barton
fd589fdca4 Cleanup: various non functional C++ changes 2024-04-20 13:46:14 +10:00
Omar Emara
dd321a47a6 Fix #120715: File Output node writes empty outputs
The File Output node writes single elements as full images in 4.1, while
such values were skipped in 4.0. This included invalid outputs, for
instance, when the Render Layers node does not have a result for the
selected view layer. Which would then just write an image with an
arbitrary color.

To fix this, we detect single element values and skip writing file
outputs for them.

Pull Request: https://projects.blender.org/blender/blender/pulls/120749
2024-04-19 12:38:31 +02:00
Omar Emara
5e3932595f Compositor: Allow constant folding of set operations
This patch replaces the is_set_operation flag with the
is_constant_operation flag to allow input constants to propagate
through the node tree using the constant folder.
2024-04-19 12:34:43 +02:00
Clément Foucault
f2ae04db10 GPU: Implement missing UBO/SSBO bind tracking
This PR adds a context function to consider all
buffer bindings obsolete. This is in order to
track missing binds and invalid lingering states
accross `draw::Pass`es.

The functions `GPU_storagebuf_debug_unbind_all`
and `GPU_uniformbuf_debug_unbind_all` do nothing
more than resetting the internal debug slot bits
to zero. This is what OpenGL backend does as it
doesn't track the bindings themselves.

Other backends might have other way to detect
missing bindings. If not they should be
implemented separately anyway.

I renamed the function to `debug_unbind_all` to
denote that it actually does something related to
debugging.

This also add SSBO binding check for OpenGL as it
was also missing.

#### Future

This error checking logic is pretty much backend
agnostic. While it would be nice to move it at
`gpu::Context` level, we don't have the resources
for that now.

Pull Request: https://projects.blender.org/blender/blender/pulls/120716
2024-04-17 11:06:39 +02:00
Omar Emara
757da9dbc1 Cleanup: Remove redundant compositor arguments
The compositor execute functions have a `rendering` argument to specify
if the compositor is executing as part of the render pipeline. But the
render context argument is null if we are not rendering, so the
`rendering` arguement is redundant and can be removed.

Additionally, we no longer use use_file_output as a hack to detect
rendering.

Pull Request: https://projects.blender.org/blender/blender/pulls/120659
2024-04-16 09:11:39 +02:00
Omar Emara
2cf8b5c4e1 Compositor: Improve interactivity for GPU compositing
This patch improves the interactivity of the GPU compositor for
interactive node tree edits by waiting on GPU work to finish to support
more granular canceling.

This does have a performance penalty, but it does not affect final
rendering and it seems worth it because even though it is slower it will
feel faster for users.

Pull Request: https://projects.blender.org/blender/blender/pulls/120656
2024-04-16 09:10:36 +02:00
Campbell Barton
e4529592d6 Cleanup: sort cmake file-lists 2024-04-16 12:28:38 +10:00
Campbell Barton
6e3eaae299 Cleanup: spelling in comments 2024-04-14 12:13:55 +10:00
Campbell Barton
09ee8d97e6 Cleanup: use C-style comments for descriptive text 2024-04-11 17:44:27 +10:00
Omar Emara
26f059ae55 Realtime Compositor: Support variable scaling
This patch adds support for variable scaling in the Scale node for the
Realtime Compositor. This is supported for the CPU compositor.

Pull Request: https://projects.blender.org/blender/blender/pulls/120314
2024-04-09 16:02:47 +02:00
Omar Emara
3a551a859a Compositor: Allow inter-operation canceling
This patch adds support for inter-operation canceling. Though it should
be noted that canceling will actually not take place except in certain
circumstances because operations are already submitted to the GPU by
this point and can't be canceled.

However, for operations that do CPU<->GPU transfers, like OIDN denoise,
which is one of the most expensive operations, this will actually cancel
the evaluation and greatly improve interactivity.

Pull Request: https://projects.blender.org/blender/blender/pulls/119917
2024-04-08 16:23:58 +02:00
Campbell Barton
2b595e7bcc Cleanup: quiet missing-declarations warnings 2024-04-08 21:57:41 +10:00
Omar Emara
0dc98f784c Fix: Vector Blur slightly differs between CPU and GPU
The Vector Blur implementation slightly differs between CPU and GPU due
to different precision in the sqrt2 constant, so use the float variant
in CPU to make it closer to GPU.
2024-04-05 10:25:27 +02:00
Omar Emara
b229d32086 Compositor: Port GPU Vector Blur to CPU
This patch ports the GPU Vector Blur node to the CPU, which is in turn
ported from EEVEE. This is a breaking change since it produces different
motion blur results that are more similar to EEVEE's motion blur.
Further, the Curved, Minimum, and Maximum options were removed on the
user level since they are not used in the new implementation.

There are no significant changes to the code, except in the max velocity
computation as well as the velocity dilation passes. The GPU code uses
atomic indirection buffers, while the CPU runs single threaded for the
dilation pass, since it is a fast pass anyways. However, we impose
artificial constraints on the precision of the dilation process for
compatibility with the atomic implementation.

There are still tiny differences between CPU and GPU that I haven't been
able to solve, but I shall solve them in a later patch.

Pull Request: https://projects.blender.org/blender/blender/pulls/120135
2024-04-05 09:48:03 +02:00
Campbell Barton
a00843d560 Cleanup: use const references instead of values 2024-04-05 11:31:53 +11:00
Campbell Barton
52ce8d408f Cleanup: use const arguments & variables 2024-04-04 10:55:10 +11:00
Campbell Barton
b24a295af1 Cleanup: pass arguments by const reference instead of value 2024-04-03 14:40:39 +11:00
Omar Emara
5de40790d0 Compositor: Set W to 1 in Float to Vector conversion
Set the w component to 1 in Float to Vector implicit conversion for the
Realtime Compositor. That's because the Vector Output node expects a
vector for the velocity input, but the CPU compositor fakes it as a
color input, while assumes a fourth component of 1.
2024-04-02 18:10:13 +02:00
Omar Emara
fd7e74aa23 Compositor: Retain alpha in Color to Vector conversion
Retain the alpha channel in Color to Vector implicit conversion for the
Realtime Compositor. That's because speed passes are exposed as color
sockets, so connecting them to a node like Vector Blur will lose the
y component of the next vectors.

The CPU compositor handles that by faking vector sockets as color
sockets internally, while the realtime compositor does not do that.
2024-04-02 12:35:12 +02:00
Omar Emara
db13fc01ad Compositor: Unify Defocus node between CPU and GPU
This patch unifies the Defocus node between the CPU and GPU compositors.
Both nodes now use a variable sized bokeh kernel which is always odd
sized for a center pixel guarantee. Further the CPU implementation now
properly handles half pixel offsets when doing interpolation, and always
sets the threshold to zero similar to the GPU implementation.
2024-03-28 14:35:13 +02:00
Omar Emara
042c50b65f Compositor: Unify Bokeh Image node between CPU and GPU
This patch unifies the CPU and GPU implementation for the Bokeh Image
node. The bokeh is now evaluated at the center of pixels and allows
different sizes for the output kernel.
2024-03-28 13:23:58 +02:00
Campbell Barton
cd0b0a9272 CMake: remove non-existing include directory
As of [0] this is no longer created.

[0]: f5f7024040
2024-03-28 08:48:02 +11:00
Omar Emara
0709c07d04 Cleanup: Use actual class instead of base class
Use the TranslateCanvasOperation class in the declaration instead of its
TranslateOperation class. This is just to clarify the code when reading
it.
2024-03-27 12:54:42 +02:00
Omar Emara
4d9678c483 Fix: Sun Beams node is off by half a pixel
The Sun Beams node is off by half a pixel. That's because we add a half
pixel offset to the initial coordinates, but then sample the texture
with the half pixel. To fix thus, use the texture_bilinear_extend
utility to sample the image, which takes care of the half pixel offset.
2024-03-27 12:49:21 +02:00
Omar Emara
9aa63aa1e8 Fix: Lens Distortion node is off by half a pixel
The Lens Distortion node is off by half a pixel because their normalized
coordinates were at the pixel corners as opposed to their centers, where
this patch changes the behavior to the latter.
2024-03-27 09:04:34 +02:00
Omar Emara
aa208d3d18 Fix: Plane Deform nodes are off by half a pixel
The Plane Track and Corner Pin nodes are off by half a pixel because
their mask is computed at the pixel corners as opposed to their center,
where this patch changes the behavior to the latter.
2024-03-27 08:54:04 +02:00
Omar Emara
7113692206 Fix: Directional Blur node is off by half a pixel
The Directional Blur node is off by half a pixel because it transforms
the pixels at their corner as opposed to their center, where this patch
changes the behavior to the latter.
2024-03-27 08:50:44 +02:00
Omar Emara
6df333a3c7 Fix: Movie Distort node is off by half a pixel
The Movie Distort node is off by half a pixel because it evaluates the
distortion at the corner of pixels as opposed to their center, where
this patch changes the behavior to the latter.
2024-03-27 08:47:07 +02:00
Campbell Barton
40ab214c0a Cleanup: spelling in comments 2024-03-27 10:25:31 +11:00
Omar Emara
df9b3d35a2 Fix: Compositor retains old images
The compositor does not correctly free, wrap, or allocate images. That's
because the resetting mechanism didn't reset all members. This patch
rests all members and only retains the important ones.
2024-03-26 12:32:36 +02:00
Campbell Barton
155dae94d7 Cleanup: code-comments, use doxygen formatting & spelling corrections
Also move some function doc-strings from the implementation
to their declarations.
2024-03-26 17:55:20 +11:00
Omar Emara
6d7b4e049e Compositor: Refactor backdrop offset
This patch refactors the backdrop offset to be stored as a float instead
of an int and to be stored in the image runtime structure instead of the
image itself.

Pull Request: https://projects.blender.org/blender/blender/pulls/119877
2024-03-26 07:49:33 +01:00