Commit Graph

208 Commits

Author SHA1 Message Date
Hans Goudey
504ac41ae7 Cleanup: Remove math include from two headers 2024-12-04 08:52:37 -05:00
Habib Gahbiche
4de34c8205 UI: Implement snapping for node resizing
When snap is active, resizing nodes now snaps the edge of the node to
grid. Holding `CTRL` inverts snapping.

Part of https://projects.blender.org/blender/blender/issues/128612

Pull Request: https://projects.blender.org/blender/blender/pulls/130379
2024-11-27 11:09:48 +01:00
Leon Schittek
13e0077c5c Nodes: Add new shader for node sockets
Add a new shader specifically for node sockets rather than using the
keyframe shader.

Motivation:
1. Allow easier addition of new socket shapes
2. Simplify socket drawing by avoiding special handling of multi-inputs
3. Support multi-inputs for all socket types (diamond, square, etc.)

The new shader is tweaked to look the same to the old ones.

**Comparison**
The biggest difference is that the multi socket is now more consistent
with the other sockets.
For single sockets there can be small size differences depending on zoom
level because the old socket shader always aligned the sockets to the
pixel grid. This could cause a bit of jiggling compared to the rest of
the node when slowly zooming. Therefore I left it out of the new shader
and it now scales strictly linear with the view.

**Multi Socket Types**
While there currently is no need for (.) internally, there are a few
obvious use-cases for multi-input field (diamond) sockets like
generalized math nodes with an arbitrary number of inputs (Add,
Multiply, Minimum etc.).

Co-authored-by: Jacques Lucke <jacques@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/119243
2024-11-23 16:42:38 +01:00
Bastien Montagne
0b3a7cbe69 Cleanup: Move BKE_image.h and related headers to C++.
NOTE: This also required some changes to Cycles code itself, who is now
directly including `BKE_image.hh` instead of declaring a few prototypes
of these functions in its `blender/utils.h` header (due to C++ functions
names mangling, this was not working anymore).

Pull Request: https://projects.blender.org/blender/blender/pulls/130174
2024-11-12 16:53:54 +01:00
Campbell Barton
4df285ccd5 Cleanup: move function comments into headers or implementation notes
For C/C++ doc-strings should be located in headers,
move function comments into the headers, in some cases merging
with existing doc-strings, in other cases, moving implementation
notes into the function body.
2024-11-02 17:27:09 +11:00
Sybren A. Stüvel
b1d2a70dbd Anim: send notifier when deleting a node from a node tree/group
Send a WM notifier when deleting a node from a node tree/group. Removing
a node also removes its animation data, and thus animation editors need
to receive a notification to refresh.

Pull Request: https://projects.blender.org/blender/blender/pulls/128255
2024-09-27 16:24:06 +02:00
Jacques Lucke
a34b0e17d6 Fix: Geometry Nodes: avoid dangling zone nodes when copying zones
Previously, it was possible to get an invalid zone by copying e.g. the Simulation Input.
Now, whenever copying only one zone node, the other one will automatically be selected
as well. This effectively avoids the dangling zone node.

The same happens already when deleting and grouping nodes.

There are still ways to get dangling zone nodes, especially from Python.
2024-09-23 01:31:59 +02:00
Iliya Katueshenock
1b67be14c6 Cleanup: BKE: Nodes: Functions renaming
Use snake style naming for all the kernel nodes functions.
Omit kernel prefix in the names since of the using namespace.
Use full forms of the terms
('iter' -> 'iterator', 'ntree' -> 'node_tree', 'rem' -> 'remove', ...).

Pull Request: https://projects.blender.org/blender/blender/pulls/126416
2024-08-19 20:27:37 +02:00
Omar Emara
f40cf759c7 Compositor: Add experimental option for new CPU compositor
This patch introduces a new experimental option for the new CPU
compositor under development. This is to make development easier such
that it happens directly in main, but the compositor is not expected to
work and will probably crash.

Pull Request: https://projects.blender.org/blender/blender/pulls/125960
2024-08-08 15:40:06 +02:00
Jacques Lucke
5861b078f7 Core: rename ID.flag and ID.tag values
Previously, values for `ID.flag` and `ID.tag` used the prefixes `LIB_` and
`LIB_TAG` respectively. This was somewhat confusing because it's not really
related to libraries in general. This patch changes the prefix to `ID_FLAG_` and
`ID_TAG_`. This makes it more obvious what they correspond to, simplifying code.

Pull Request: https://projects.blender.org/blender/blender/pulls/125811
2024-08-07 12:12:17 +02: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
95eb3e13bf Fix #119211: Masks do not update in GPU compositor
Masks are not updated when edited when using the GPU compositor. That's
because the GPU compositor caches static resources and invalidates them
according to the recalculate flags that the depsgraph flushes to IDs.
The issue is that the flags are not flushed to the evaluated IDs of the
compositor depsgraph, but rather to some other evaluated versions of the
IDs.

To fix this, we make the compositor depsgraph persistent and store it in
the scene runtime. This allows us to reliably track changes to resources
used by the compositor and also reduces the overhead of depsgraph
creation in the compositor job.

Patch originally provided by Sergey.

Fixes #121188.

Pull Request: https://projects.blender.org/blender/blender/pulls/123085
2024-06-13 07:43:11 +02:00
Omar Emara
20d62d3805 Fix: Crash when toggling compositor device
Blender crashes when toggling the compositor device from CPU to GPU.
This is because when submitting the compositor job, the device might be
set to CPU, so GPU related data are not initialized in the job, but
between the time the job is submitted and the time it gets executed, the
device might change to GPU, which then tries to accept the uninitialized
GPU data from the job.

To fix this, we use the evaluated scene from the depsgraph since it
captures the state of the scene used in the job initialization.

Pull Request: https://projects.blender.org/blender/blender/pulls/122661
2024-06-03 16:50:15 +02:00
Omar Emara
a162149cfa Fix #121761: Crash when compositing while rendering
Blender crashes when the interactive GPU compositor is running in a node
editor while rendering. This is because the GPU compositor is sharing
the same GPU context used for rendering, which is not allowed. To fix
this, we use a dedicated render list for interactive compositing, to use
its dedicated GPU context.

This is implemented by keeping another render list for the purpose of
compositing and similarly clearing its context when it is no longer
needed.

Pull Request: https://projects.blender.org/blender/blender/pulls/122472
2024-06-03 09:56:58 +02:00
Omar Emara
99fca1a149 Compositor: Only create GPU context when needed
This patch makes it such that the GPU context required for the
compositor is only created when the GPU compositor is in use. This
should fix #121761 for the CPU compositor, but generally also make the
CPU compositor more robust to such errors in the future, and a tiny bit
faster since context creation is skipped.

Pull Request: https://projects.blender.org/blender/blender/pulls/122420
2024-05-30 15:03:15 +02:00
Habib Gahbiche
9484770551 Compositor: Switch View: automatically update views when render views are enabled/disabled
Remove the button "Update Views" that requires the user to update visible views manually. This is now consistent with the automatic update of compositor tree, when views are added or deleted, see #120685.

The patch also addresses #109866 (not really a fix since behavior in that bug report is intentional).

Pull Request: https://projects.blender.org/blender/blender/pulls/122290
2024-05-30 13:18:10 +02: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
Iliya Katueshenock
10befe6de7 Fix: Nodes: Assert on node copy
Fix of issue after fac97d6c49.
If node have dynamic declaration, update of node cause update of the declaration and its sockets.
So, links update have to be in separate loop.

Pull Request: https://projects.blender.org/blender/blender/pulls/122261
2024-05-25 14:55:15 +02:00
Sergey Sharybin
1b18e07232 Fix #121480: Cryptomatte shows some objects as black
The issue originates to the change in default view transform from Filmic
to AgX, which does slightly different clipping, and clips color to black
if there is any negative values.

This change implements an idea of skipping view transform for viewer
node when it is connected to the Pick output of the cryptomatte node.
It actually goes a bit deeper than this and any operation can tag its
result as a non-color data, and the viewer node will respect that.
It is achieved by passing some extra meta-data along the evaluation
pipeline. For the CPU compositor it is done via MetaData, and for the
GPU compositor it is done as part of Result.

Connecting any other node in-between of viewer and Cryptomatte's Pick
will treat the result as color values, and apply color management.

Connecting Pick to the Composite output will also consider it as color,
since there is no concept of non-color-managed render result.

An alternative approaches were tested, including:

- Doing negative value clamping at the viewer node.
  It does not work for legacy cryptomatte node, as it needs to have
  access to original non-modified Pick result.

- Change the order of components, and store ID in another channel.

  Using one of other of Green or Blue channels might work for some view
  transforms, but it does not work for AgX.

  Using Alpha channel seemingly works better, but it is has different
  issues caused by the fact that display transform de-associates alpha,
  leading to over-exposed regions which are hard to see in the file from
  the report. And might lead to the similar issues as the initial report
  with other objects or view transforms.

- Use positive values in the Pick channel.

  It does make things visible, but they are all white due to the nature
  of how AgX works, making it not so useful as a result.

Pull Request: https://projects.blender.org/blender/blender/pulls/122177
2024-05-24 17:25:57 +02:00
Jacques Lucke
ebb61ef30f Nodes: avoid removing link when inserting incompatible node
Previously, when dropping a node on a link with incompatible sockets, the link
would be removed. While sometimes useful in super simple setup, it is generally
useless for most work. Even worse, users might not notice that they accidentally
removed a link (this has been reported in the recent geometry nodes workshop).

This patch changes this behavior in two ways:
* A node can't be inserted onto an incompatible link anymore.
* A link will be dimmed while dragging a node over it, if it is incompatible or if
  alt is pressed.

Pull Request: https://projects.blender.org/blender/blender/pulls/121975
2024-05-23 19:52:37 +02:00
Leon Schittek
fac97d6c49 Fix: Nodes: Update multi-socket link positions after duplicating
When not all links connecting to a multi-input socket are duplicated
with the multi-input, the link position needs to be updated to avoid
the links being offset.

Pull Request: https://projects.blender.org/blender/blender/pulls/122074
2024-05-22 05:57:35 +02:00
Sergey Sharybin
727a90a0f1 Compositor: Make GPU compositor an official feature
Effectively, make GPU compositor available without need to enable
an experimental feature set.

The compositor device is now exposed in the Performance panel of
Render Buttons. It is also still available in the compositor's
N-panel, together with some other options which are more about how
editing works, and not exactly related to render performance.

Pull Request: https://projects.blender.org/blender/blender/pulls/121398
2024-05-14 15:49:20 +02:00
Iliya Katueshenock
75d17b1db5 Cleanup: Move BKE_node to namespace
Move all header file into namespace.
Unnecessary namespaces was removed from implementations file.
Part of forward declarations in header was moved in the top part
of file just to do not have a lot of separate namespaces.

Pull Request: https://projects.blender.org/blender/blender/pulls/121637
2024-05-13 16:07:12 +02:00
Sergey Sharybin
7b4232e8aa Compositor: Move Execution Mode and Precision from bNodeTree to Scene
This allows to expose these settings in the Performance panel in the
render buttons. Also moves compositor-specific options away from the
generic node tree structure.

For the backwards-compatibility the options are still present in the
DNA for the bNodeTree. This is to minimize the impact on the Studio
which has used the GPU compositor for a while now. They can be
removed in a future release.

There is no functional changes expected.

Pull Request: https://projects.blender.org/blender/blender/pulls/121583
2024-05-10 18:08:33 +02:00
Sergey Sharybin
149e547de6 Compositor: Remove quality setting from DNA and UI
It was meant to be included into the previous commit in the area,
but was forgotten due to some technicalities.

Also remove the DisplaceSimpleOperation, which is now not used.

Pull Request: https://projects.blender.org/blender/blender/pulls/121580
2024-05-08 16:56:32 +02:00
Bastien Montagne
ec350a6115 BKE ID copy: Pass new owner ID when possible.
Advanced ID copying code can now take a `new_owner_id` ID pointer parameter,
and use it to set the relevant 'loopback' pointer to its owner ID by the
copy code itself.

Besides avoiding the need for all code copying embedded IDs to set the
loopback pointer themselves, this also means that `lib_id` copying code
itself does not need to use `IDWALK_IGNORE_MISSING_OWNER_ID` anymore.

This change is not expected to have any effect in current codebase.
2024-05-02 17:17:04 +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
Jacques Lucke
7ed713e772 Fix #120087: wrong node selection after duplicating node 2024-04-02 15:40:51 +02:00
Hans Goudey
8b514bccd1 Cleanup: Move remaining GPU headers to C++
Pull Request: https://projects.blender.org/blender/blender/pulls/119807
2024-03-23 01:24:18 +01:00
Jacques Lucke
3ad4ea81d1 Nodes: rename multi_input_socket_index to multi_input_sort_id
For historical reasons, the `multi_input_socket_index` was actually reversed
(large index comes first). This patch renames it to `multi_input_sort_id` and
adds a comment. This new name makes it less confusing that the id is reversed.

Pull Request: https://projects.blender.org/blender/blender/pulls/119652
2024-03-19 13:42:09 +01:00
Hans Goudey
81a63153d0 Despgraph: Rename "copy-on-write" to "copy-on-evaluation"
The depsgraph CoW mechanism is a bit of a misnomer. It creates an
evaluated copy for data-blocks regardless of whether the copy will
actually be written to. The point is to have physical separation between
original and evaluated data. This is in contrast to the commonly used
performance improvement of keeping a user count and copying data
implicitly when it needs to be changed. In Blender code we call this
"implicit sharing" instead. Importantly, the dependency graph has no
idea about the _actual_ CoW behavior in Blender.

Renaming this functionality in the despgraph removes some of the
confusion that comes up when talking about this, and will hopefully
make the depsgraph less confusing to understand initially too. Wording
like "the evaluated copy" (as opposed to the original data-block) has
also become common anyway.

Pull Request: https://projects.blender.org/blender/blender/pulls/118338
2024-02-19 15:54:08 +01:00
Sergey Sharybin
a8a05ebba1 Compositor: Switch CPU compositor to Full-Frame
The tiled compositor code is mainly still around, which is only
expected to be a short-lived period. Eventually it will also be
removed.

The OpenCL, Group Buffers, and Chunk size options are already removed.

Pull Request: https://projects.blender.org/blender/blender/pulls/118010
2024-02-14 14:23:49 +01:00
Campbell Barton
b372ebae68 Cleanup: unused headers for source/blender/editors
Remove 1317 includes from editors.
2024-02-13 10:02:53 +11:00
Bastien Montagne
5aaadebbe4 Cleanup: Make BKE_scene.h a full Cpp header. 2024-02-10 19:16:25 +01:00
Bastien Montagne
29fe777445 Cleanup: Make BKE_report.h a full Cpp header. 2024-02-10 18:34:29 +01:00
Bastien Montagne
54618dbae3 Cleanup: Make BKE_global.h a Cpp header. 2024-02-10 18:25:14 +01:00
Bastien Montagne
deab8c085a Cleanup: Move BKE_callbacks.h and BKE_cachefile.h to CPP headers. 2024-02-09 19:29:34 +01:00
Bastien Montagne
45e7827898 Clenup: Move BLT headers to Cpp.
Noisy but fairly straight forward.
2024-02-09 18:59:42 +01:00
Sergey Sharybin
467a132166 Compositor: Implement per-node execution time report
Visually it is the same as the execution time implemented for the
geometry nodes, and it is to be enabled in the overlay popover.

The implementation is separate from the geometry nodes, as it is
not easy or practical to re-use the geometry nodes implementation.

The execution time is stored in a run-time hash, indexed by a node
instance key. This is similar to the storage of the mode preview
images, but is stored on the scene runtime data and not on the node
tree. Indexing the storage by key allows to easily copy execution
statistics from localized tree to its original version.

The time is only implemented for full-frame compositor, as for the
tiled compositor it could be tricky to calculate reliable time for
pixel processing nodes which process one pixel at a time.

Pull Request: https://projects.blender.org/blender/blender/pulls/117885
2024-02-09 10:19:24 +01:00
Hans Goudey
dccf0e8699 Cleanup: Move GPU_material.h to C++ 2024-02-01 10:40:30 -05:00
Aras Pranckevicius
a705259b4b Cleanup: move imbuf .h files to .hh 2024-01-19 20:29:38 +01:00
Hans Goudey
3e76a1a6c2 Cleanup: Move BKE_lib_id.h to C++ 2024-01-15 12:44:14 -05:00
Pratik Borhade
8ce2bacaf9 Fix #116996: Problem linking to reroute nodes
Cause by d19e7cbb5a
Skip reroute node case when cursor is over header

Pull Request: https://projects.blender.org/blender/blender/pulls/117014
2024-01-11 12:18:54 +01:00
Jacques Lucke
d19e7cbb5a Fix #115540: nodes with sockets only on one side are hard to resize
This was caused by 74dd1e044b.

The fix implemented here disables socket picking in the header region of
non-collapsed nodes. This way, resizing always works when on the left
and right side of the header.
2024-01-09 13:19:48 +01:00
Omar Emara
123da3412b Cleanup: Move Cryptomatte node defines into enums 2023-12-13 12:40:34 +02:00
Omar Emara
931c188ce5 Compositor: Refactor File Output node
This patches refactors the compositor File Output mechanism and
implements the file output node for the Realtime Compositor. The
refactor was done for the following reasons:

1. The existing file output mechanism relied on a global EXR image
   resource where the result of each compositor execution for each
   view was accumulated and stored in the global resource, until the
   last view is executed, when the EXR is finally saved. Aside from
   relying on global resources, this can cause effective memory leaks
   since the compositor can be interrupted before the EXR is written and
   closed.
2. We need common code to share between all compositors since we now
   have multiple compositor implementations.
3. We needed to take the opportunity to fix some of the issues with the
   existing implementation, like lossy compression of data passes,
   and inability to save single values passes.

The refactor first introduced a new structure called the Compositor
Render Context. This context stores compositor information related to
the render pipeline and is persistent across all compositor executions
of all views. Its extended lifetime relative to a single compositor
execution lends itself well to store data that is accumulated across
views. The context currently has a map of File Output objects. Those
objects wrap a Render Result structure and can be used to construct
multi-view images which can then be saved after all views are executed
using the existing BKE_image_render_write function.

Minor adjustments were made to the BKE and RE modules to allow saving
using the BKE_image_render_write function. Namely, the function now
allows the use of a source image format for saving as well as the
ability to not save the render result as a render by introducing two new
default arguments. Further, for multi-layer EXR saving, the existent of
a single unnamed render layer will omit the layer name from the EXR
channel full name, and only the pass, view, and channel ID will remain.
Finally, the Render Result to Image Buffer conversion now take he number
of channels into account, instead of always assuming color channels.

The patch implements the File Output node in the Realtime Compositor
using the aforementioned mechanisms, replaces the implementation of the
CPU compositor using the same Realtime Compositor implementation, and
setup the necessary logic in the render pipeline code.

Pull Request: https://projects.blender.org/blender/blender/pulls/113982
2023-12-13 11:08:03 +01:00
Habib Gahbiche
153f14be2b Compositor: Make split viewer a regular split node
Changes:
- Renamed Split Viewer Node to Split Node
- Split Node is now under `Utilities` (similar to Switch node)
- Versioning: split viewer from 4.0 and before is replaced with the new split node connected to a new viewer node.

Pull Request: https://projects.blender.org/blender/blender/pulls/114245
2023-12-03 23:20:44 +01:00
Bastien Montagne
3acb64e7ac BKE_main: move header to be a fully CPP one.
Pull Request: https://projects.blender.org/blender/blender/pulls/115681
2023-12-01 20:38:54 +01:00
Omar Emara
5af7d3e2be Fix #115043: Compositor crashes for huge render sizes
The experimental GPU compositor crashes when the render size is huge.
This is just due to GPU texture allocation failing. The patch fixes that
by downscaling the render result when reading, then upscaling it again
when writing. Additionally, the render size was adapted to the
downscaled size since it is used by other input nodes. This is not an
ideal solution, but it a good temporary solution to prevent crashes
until we have proper support for huge textures.

Pull Request: https://projects.blender.org/blender/blender/pulls/115299
2023-12-01 16:16:19 +01:00
Habib Gahbiche
ff083c1595 Compositor: UI: better node visibility for default node tree
Create default compositor node tree centred around x-axis, and with lower y-offset for better visibility

Pull Request: https://projects.blender.org/blender/blender/pulls/115439
2023-11-28 18:45:37 +01:00