Commit Graph

2119 Commits

Author SHA1 Message Date
Omar Emara
885db0986c Refactor: Remove concept of temporary result
Temporary results are essentially results with a default reference count
of 1, so we default to 1 for all results and set the initial reference
count differently as need.
2024-08-06 19:37:18 +03:00
Omar Emara
69ae62a94e Refactor: Store reference to context in Result
This patch stores a reference to the entire context in the Result class,
as opposed to just the texture pool. This is in preparation for adding
CPU side texture to the result, such that allocations can automatically
allocate CPU or GPU textures based on context.
2024-08-05 18:38:32 +03:00
Sergey Sharybin
89ededeec4 Cleanup: Code style 2024-08-02 14:41:33 +02:00
Omar Emara
9c44349204 Fix #124023: File output always saves PNG in sRGB
The File Output node doesn't provide an option to save byte formats like
PNG in a space that is not sRGB. This is problematic for data images
like normal maps, which need to be saved as non-color.

This patch adds a Color Space option to the File Output node to allows
users to override the assumed color space. This also adds a new global
Save As Render option that is used if Use Node Format is enabled.

Pull Request: https://projects.blender.org/blender/blender/pulls/124238
2024-08-02 13:52:22 +02:00
Bill-Spitzak
2042669e23 Refactor: Reformulate math in domain realization
Directly calculate the transformation matrix by multiplying and
inverting the Domain matrices. This removes a double-invert and
decomposition of the matrices so it should be more accurate, and I think
makes the math a lot easier to figure out.

This also moves the "bias" for Nearest to be done in the input space
rather than output. This should make it select the same pixels from the
input even if the image is rotated 180 degrees.

Co-authored-by: Bill Spitzak <bills@sidefx.com>
Pull Request: https://projects.blender.org/blender/blender/pulls/125543
2024-08-02 13:26:46 +02:00
Bill Spitzak
984feb48fc Cleanup: Remove unused integer wrap_pixel method 2024-08-01 14:22:30 +03:00
Bill Spitzak
1479c9cde6 Cleanup: Use compositor read() for read_elem_bilinear()
This patch reuses the read method for the read_elem_bilinear method to
deduplicate code and also get the same fixes that were committed in
ef1d22aea5.
2024-08-01 14:20:50 +03:00
Bill Spitzak
ef1d22aea5 Fix #124842: Translation leaves empty pixels at edges
The Translate node leaves empty pixels at the boundary of the image.
This caused by incorrect clipping when sampling the pixels. To fix this,
we adjust COM_MemoryBuffer::read to read using Extend or Repeat using
BLI interpolation, then multiply that by a clipping rectangle. The
read_elem_sampled function is now defined in terms of the read method.

This also coincidentally fixes off by half a pixel error in nearest
neighbour interpolation.
2024-08-01 14:06:50 +03:00
Jesse Yurkovich
67186ae8ac Fix: Error in builds without OCIO
The methods on the `OCIOColorSpaceConversionShader` expect
`shader_creator_` to be valid so, in case of a build without OCIO
support, ensure we have a valid GPUShaderCreator available.

In this case we use the "stub" implementation.

Pull Request: https://projects.blender.org/blender/blender/pulls/125631
2024-07-30 02:20:27 +02:00
Hans Goudey
570ac3ebaa Fix: Build error in lite build without OCIO 2024-07-29 14:16:01 -04:00
Jesse Yurkovich
69154a5e3b Fix #125402: Guard against missing OCIO data for realtime compositor
The newly added viewport compositor was missing a try-catch guard around
the OCIO `getProcessor` call. All prior call sites were protected except
this one.  Unhandled exceptions can occur if the user tries to use a
colorspace config that is not present in their OCIO configuration.

The surrounding code paths need some work in order to not crash at a
later point, which would also impact builds with no OCIO support at all.
In the case of no OCIO support at all, a warning label is placed on the
node as well.

Pull Request: https://projects.blender.org/blender/blender/pulls/125526
2024-07-29 18:37:23 +02:00
Omar Emara
406a2d3ff0 Fix #125380: Viewport compositor slows complex scenes
The viewport compositor slows down complex scenes even if it has very
simple setups. That's because it internally computes previews which
involves a fair bit of CPU computation, however, those previews are
actually never written to the original tree, so previewers weren't
really visible so it is effectively redundantly computations.

To fix this, we double down on disabling previews for the viewport
compositor and avoid any redundant computations in that case.
2024-07-26 19:08:58 +03:00
Bill Spitzak
0d70481d15 Refactor: Optimize compositor realization shader
This patch optimizes the compositor realization shader by moving the
centring offset to the host code as opposed to the shader.
2024-07-25 18:58:29 +03:00
Bill Spitzak
b3e62d3052 Fix #124133: Compositor transforms are off by 0.5 pixels
The GPU compositor transforms are off by half a pixel in some cases.
That's because the realization shader was to perform transforms, and it
includes logic to move images by half a pixel if the domain and image
had different even/odd sizes. To fix this, we only move by half a pixel
if we are doing realization, while transforms are left as is.
2024-07-25 17:23:25 +03:00
Bill Spitzak
b76603b6bf Fix: Scale node is off by half a pixel
The Scale node was off by half a pixel because pixels were not evaluated
at their center. To fix this, we scale the pixels at their center.
2024-07-25 12:06:32 +03:00
Jesse Yurkovich
b112549296 Cleanup: Formatting 2024-07-24 22:27:29 +02:00
Bill Spitzak
f701a71b0e Fix: Compositor Rotate node is off by 0.5 pixel
The Rotate node was off by 0.5 pixels because pixels were not evaluated
at their center. Furthermore, the center of rotation was also off by
half a pixel. To fix this, we ensure rotation happen around the exact
center as well as rotate the pixels at their center.
2024-07-24 22:28:35 +03:00
Bill Spitzak
ab51d879c3 Fix #124339: Compositor artifacts with 0.5 translation
The compositor translate node produces artifacts when its fractional
part is 0.5. That's because GPUs do round-to-even for nearest neighbour
sampling in case samples were at pixel boundaries.

To fix this, we bias translations by a small value to break the
rounding and ensure predictable rounding direction.
2024-07-24 19:22:00 +03:00
Jesse Yurkovich
ec4fc2d34a CMake: Modernize the optional TBB dependency
This continues the cmake modernization effort and introduces support for
allowing our optional dependencies to integrate properly. TBB is added
here as it's proven troublesome to maintain correctly.

Currently the only Blender project which uses the TBB headers directly
is `blenlib`.  However, all downstream projects which require blenlib as
their dependency, and wish to properly make use of its threading
facilities, needed to define various TBB items in their CMake files. Not
only is this unnecessary and arcane, but several projects didn't do this
and ended up not using threading as well as producing ODR violations
along the way[1].

This PR makes TBB a modern dependency and exposes it PUBLIC'ly from
`blenlib`.  All downstream projects which depend on blenlib will now
receive everything they require from TBB automatically. This includes
the `WITH_TBB` define, the headers, and the library itself.

[1] blender/blender@05241f47f5

Pull Request: https://projects.blender.org/blender/blender/pulls/124916
2024-07-19 23:30:56 +02:00
Omar Emara
0e7f80b262 Refactor: Remove redundant Cryptomatte frame update
Cryptomatte layer initialization required the active scene to update the
image user frame, but the image user is already updated through other
mechanisms and is thus redundant to do at draw time, so we remove the
frame update call as well as the scene argument from the call chain. The
frame number of the image user is ignored at compositing time in any
case since it is set to the compositing scene frame.

This is needed for #124738.
2024-07-17 10:12:48 +03:00
Bastien Montagne
c607ead4b7 Refactor: Makesrna: move generated code further in C++.
This commit moves generated `RNA_blender.h`, `RNA_prototype.h` and
`RNA_blender_cpp.h` headers to become C++ header files.

It also removes the now useless `RNA_EXTERN_C` defines, and just
directly use the `extern` keyword. We do not need anymore `extern "C"`
declarations here.

Pull Request: https://projects.blender.org/blender/blender/pulls/124469
2024-07-15 16:39:45 +02:00
Omar Emara
970ec097e3 Cleanup: Fix missing declaration warning 2024-07-15 11:42:35 +03:00
Lukas Stockner
021bce8b48 Compositor: Add White Point mode to the Color Balance node
This adds a new mode to the Color Balance node, which applies a white point
transformation similar to the one applied in the view transform.

Unlike the view transform, the compositor node allows specifying both the
source and the destination white point for more flexibility. Both default
to the D65 white point, so just leaving the destination alone achieves the
same behavior.

Pull Request: https://projects.blender.org/blender/blender/pulls/124110
2024-07-14 23:22:58 +02:00
Campbell Barton
8fdb190278 Cleanup: typos in comments (duplicate words) 2024-07-14 18:55:43 +10:00
Omar Emara
308b53746b Fix #101263: Vector pass wrongly saved in File Output
The vector pass and potentially other vectors that store 4 values are
stored wrongly, in particular, the last channel is ignored. To fix this
we identify if a vector pass is 4D and store the information in the
result meta data, then use this information to either save a 3D or a 4D
pass in the File Output node.

This is a CPU implementation of the same mechanism in the GPU compositor
implemented in 57a6832b17. The CPU implementation is a bit more complex
because the CPU compositors stores 4D vectors in color images internally
which can lead to information loss in case of implicit conversion when
the File Output has vector sockets. So what we do is force all vector
inputs to the File Output operation to be color, then save that as 3D or
4D depending on the meta data as well as the original UI socket type.

Pull Request: https://projects.blender.org/blender/blender/pulls/124580
2024-07-12 12:53:16 +02:00
Jesse Yurkovich
6ace3eb065 Merge branch 'blender-v4.2-release' 2024-07-11 08:44:58 -07:00
Jesse Yurkovich
7a076d26a6 Fix: Guard against null operation in ImageNode::convert_to_operations
Properly guard the conditionals inside ImageNode::convert_to_operations
against null operations.

I've duplicated the null check in order to not add another layer of
nesting in an already very deep set of conditionals.

Pull Request: https://projects.blender.org/blender/blender/pulls/124473
2024-07-11 17:43:45 +02:00
Omar Emara
acd4a85d6b Fix #124445: Sun beams produces sharp results
The Sun beams node produces sharp results when the background has an
alpha channel. That's because the sun beams samples were weights by the
alpha channel, and when the image is mostly transparent, no smooth
falloff can exist.

This is a regression in the Sun Beams redesign that took place in v3.6.
I was mislead by the fact that the alpha was multiplied to the weight.
But the original code actually multiplied the alpha of the border color,
not the sample color. So this fix essentially restores the old behavior.

Pull Request: https://projects.blender.org/blender/blender/pulls/124532
2024-07-11 16:10:50 +02:00
Omar Emara
57a6832b17 Fix #101263: Vector pass wrongly saved in File Output
The vector pass and potentially other vectors that store 4 values are
stored wrongly, in particular, the last channel is ignored. To fix this
we identify if a vector pass is 4D and store the information in the
result meta data, then use this information to either save a 3D or a 4D
pass in the File Output node.

This is a partial fix for the GPU compositor only. The complete fix for
the CPU compositor will be submitted separately as it is not
straightforward and will likely require a refactor.

Pull Request: https://projects.blender.org/blender/blender/pulls/124522
2024-07-11 16:08:19 +02:00
Omar Emara
d14ad05078 Fix #124208: Cryptomatte are compressed in File Output
The Cryptomatte layers in the compositor are saved compressed and saved
in half precision in the File Output node. That's because the EXR writer
makes decision about compression and half float based on channel names.
And Cryptomatte are currently saved using RGBA channel names like other
color images.

To fix this, we follow the Cycles convention of using lowercase rgba for
Cryptomatte images, allowing them to be saved without compression and
always in full precision since they are otherwise useless.

Fixes #124208, #87988.

Pull Request: https://projects.blender.org/blender/blender/pulls/124508
2024-07-11 12:47:58 +02:00
Omar Emara
f954a6b5fb Compositor: Support meta data in GPU compositor
This patch adds support for meta data in the GPU compositor much like
the mechanism that already exist in the CPU compositor. Only Cryptomatte
meta data is handled at the moment because that is the only meta data
that the compositor supports.

The is_data member of the result was moved to the meta data structure for
consistency with the CPU compositor.

Fixes #124222.

Pull Request: https://projects.blender.org/blender/blender/pulls/124460
2024-07-11 11:03:03 +02:00
Omar Emara
30643fcf9b Fix: Bloom glare crashes when image is too small
The Bloom mode of the Glare node crashes if the input image is too
small. This is because bloom is computed using a down-sampling followed
by an up-sampling chain, and if the user supplied size is not maximum,
the computed chain length might be zero or negative, which is not
handled gracefully. To fix this, we just sanitize the chain length.

Pull Request: https://projects.blender.org/blender/blender/pulls/124089
2024-07-03 11:27:26 +02:00
Omar Emara
2c345cfe31 Fix: Compositor frees cached resources when canceled
The GPU compositor frees some of the cached resources when it gets
canceled during interactive editing, making the experience less smooth.

This is because when the compositor gets canceled mid-evaluation, some
of the operations won't get the chance to mark their used resources as
still in use.

To fix this, we skip the cache manager reset after canceling,
effectively only resetting when a full evaluation happens, giving all
operations the chance to keep their cached resources.

Pull Request: https://projects.blender.org/blender/blender/pulls/123886
2024-06-28 15:27:09 +02:00
Omar Emara
2eb7c4c329 Fix: Linked images don't work in GPU compositor
Linked images that share the same name as an image in the file will fail
to load in the GPU compositor. That's because cached resources are keyed
using only their ID name, while they should also be keyed by the library
name.

Pull Request: https://projects.blender.org/blender/blender/pulls/123898
2024-06-28 15:26:01 +02:00
Omar Emara
f19a9e9b4d Fix #123607: Plane Track Deform produces wrong output
The Plane Track Deform node produces wrong outputs in the GPU compositor
in case the input size was different from the movie size. That's because
the coordinates were normalized based on the input size, while they
should be normalized based on the output size, which is what this
patches does.
2024-06-25 16:37:18 +03:00
Sergey Sharybin
320c2e8878 Fix: Compositor crash when second image of Mix node is missing
The first input of the compositor Mix node determines resolution,
leading to situation when the second input will always be attempted
to be evaluated. If the first input is a longer image sequence than
the second input it leads to a crash.

Do a null-pointer check and return transparent image in this cases,
similar to what the Movie Clip operation is doing.

Pull Request: https://projects.blender.org/blender/blender/pulls/123493
2024-06-21 10:22:42 +02:00
Omar Emara
4329dafb4c Fix #123340: Zero division in Difference Key node
The Difference Key node suffered from zero division when the falloff is
zero. Fix that by using safe division.
2024-06-19 11:46:09 +03:00
Fabian-Herb
354b1a5db9 Fix #122933: Enable Compositor OpenImageDenoise on Linux ARM64
Pull Request: https://projects.blender.org/blender/blender/pulls/123066
2024-06-11 19:29:42 +02:00
Sergey Sharybin
a2795852cd Fix ##122962: Regression: Backdrop update triggers crash
Pull Request: https://projects.blender.org/blender/blender/pulls/122991
2024-06-10 11:45:01 +02:00
Omar Emara
1e359f4173 Fix #112742: File output node ignores colorspace overrides
The File Output node ignores color space overrides for EXR images. To
fix this, we save the images using save_as_render set to true. We don't
need to provide this as an option similar to other image types because
even when save_as_render is set to true, it will not have an effect
unless the user chooses to override the color space explicitly, since it
is not affected by view transforms and the like.

Pull Request: https://projects.blender.org/blender/blender/pulls/122791
2024-06-07 17:38:18 +02:00
Omar Emara
79da892126 Fix #122587: File Output node can only save one size
The File Output node forces all inputs to have the same size, which
should only be the case for multilayer files. This is a regression in
931c188ce5. To fix this, we allow inputs to have any size, except for
multilayer files, which are realized on the automatic operation domain
of the operation.

Pull Request: https://projects.blender.org/blender/blender/pulls/122824
2024-06-07 17:34:14 +02:00
Omar Emara
d66e3f899a Fix #102240: Viewer node does not work inside group
The CPU compositor does not recognize viewer groups inside node groups
unless a viewer node exists at the top level node group. This is caused
by bad logic when registering viewer node at the node operation builder.
And the fix is just to correct the logic to always register viewers if
no active viewer already exists, which can then later be overwritten if
a viewer node that takes precedence was discovered.

Pull Request: https://projects.blender.org/blender/blender/pulls/122869
2024-06-07 17:33:25 +02:00
Campbell Barton
7f7648c6ed Cleanup: spelling in code comments & minor edits
- Use uppercase NOTE: tags.
- Correct bNote -> bNode.
- Use colon after parameters.
- Use doxy-style doc-strings.
2024-06-06 09:55:13 +10:00
Omar Emara
4f21b26675 Fix #121639: Glare shifts the colors of highlights
The Glare node shifts the color of the highlights when the threshold is
high. That's because the thresholding algorithm simply subtracts the
threshold from the RGB data, which is not expected to retain the same hue
of the color.

To fix this, we do the thresholding only on the luminance of the color
in HSV color space. This eliminates the color shifting and also helps to
smooth the edges of the highlights.

This is a breaking change, but it is more of a fix rather than a change
of behavior.

Pull Request: https://projects.blender.org/blender/blender/pulls/122570
2024-06-04 20:59:32 +02:00
Sergey Sharybin
44ce0e01cd Fix #122669: Compositor: Corrupted output and occasional crash
This change fixes:
- Constant folder uses rect of size INT_MIN .. INT_MAX, which overflows integer
  when calculating size.
- Calculation of an offset inside of input can lead to integer overflow for big
  resolutions.
- texture_bilinear_extend() and texture_nearest_extend() do not seem to handle
  single element buffers correctly.
- Kuwahara has division of zero when the input size is 0.

Pull Request: https://projects.blender.org/blender/blender/pulls/122674
2024-06-04 15:48:48 +02:00
Sergey Sharybin
5401a69627 Fix: Compositor translate uses un-initialized delta
The issue is visible when adding an assert in the delta accessors of
the TranslateOperation operation (get_delta_x and get_delta_y), and
rendering compositor-nodes-desintegrate-wipe-01.blend (either command
line or F12, doesn't matter).

Seems that under certain circumstances the system might skip determining
the area of interest. For such cases ensure delta from the beginning of
the threaded code.

Pull Request: https://projects.blender.org/blender/blender/pulls/122686
2024-06-04 09:43:34 +02:00
Habib Gahbiche
192d4dc9dc Compositor: implement bicubic interpolation for Stabilize2DNode
This patch also fixes a crash when image input of `Stabilize2DNode` is unconnected and interpolation is set to bicubic.

Differences to GPU compositor:
- ~1px difference is observed due to different rounding of domain size vs. canvas size. This difference is constant for all image sizes.
- If image input is unconnected but other inputs are, CPU compositor doesn't consider the operation to be constant, whereas GPU compositor still outputs a constant result.

Pull Request: https://projects.blender.org/blender/blender/pulls/122288
2024-05-30 17:38:41 +02:00
Campbell Barton
c5a27f011e Cleanup: spelling in comments 2024-05-29 12:49:07 +10:00
Omar Emara
0dca908191 Compositor: Add GPU per-node execution time report
This patch adds support for timing GPU compositor executions. This was
previously not possible since there was no mechanism to measure GPU
calls, which is still the case. However, since 2cf8b5c4e1, we now flush
GPU calls immediately for interactive editing, so we can now measure the
GPU evaluation on the host, which is not a very accurate method, but it
is better than having no timing information. Therefore, timing is only
implemented for interactive editing.

This is different from the CPU implementation in that it measures the
total evaluation time, including any preprocessing of the inputs like
implicit type conversion as well as things like previews.

The profiling implementation was moved to the realtime compositor since
the compositor module is optional.

Pull Request: https://projects.blender.org/blender/blender/pulls/122230
2024-05-28 08:13:46 +02:00
Sergey Sharybin
f4a7c42255 Fix crash in viewer node with quick toggle of frame in Compositor
The issue was caused by a non-initialized ibuf_ used to set the non-color
space to. For now limit the tweaks to the image data-block, which is always
ensured. This makes it consistent with the GPU compositor which does not
have access to ibuf at the moment when the meta-data is being checked.

Ideally we do need to set the color space, but it needs to happen consistently,
and in a thread-safe manner. The way how the CPU compositor releases the
ibuf right after acquisition does not feel safe, so less we rely on it is
better.
2024-05-24 19:26:50 +02:00