1465 Commits

Author SHA1 Message Date
Aras Pranckevicius
facb17b0e3 Cleanup: BLI ENUM_OPERATORS cleanup/robustness
BLI code for enums that are meant to be used as "bit flags" defined
an ENUM_OPERATORS macro in BLI_utildefines.h. This cleans up things
related to said macro:

- Move it out into a separate BLI_enum_flags.hh header, instead of
  "random bag of things" that is the current place,
- Update it to no longer need manual indication of highest individual
  bit value. This originally was added in a31a87f89 (2020 Oct), in
  order to silence some UBSan warnings that were coming
  from GPU related structures (looking at current GPU code, I don't
  think this is happening anymore). However, that caused actual
  user-visible bugs due to incorrectly specified max. enum bit value,
  and today 14% of all usages have incorrect highest individual
  bit value spelled out.
    - I have reviewed all usages of operator ~ and none of them are
      used for directly producing a DNA-serialized value; all the
      usages are for masking out other bits for which the new ~
      behavior that just flips all bits is fine.
- Make the macro define flag_is_set() function to ease check of bits
  that are set in C++ enum class cases; update existing cases to use
  that instead of three other ways that were used.

Pull Request: https://projects.blender.org/blender/blender/pulls/148230
2025-10-17 12:57:50 +02:00
Omar Emara
3aa674966f Nodes: Support disabling outputs in built-in nodes
This patch adds support for disabling outputs in built-in nodes based on
menu inputs using a custom usage_inference callback. This just
essentially calls usage_inference_fn for outputs as well, while it was
only being called for inputs. Additionally, the usage_by_menu methods
were adjusted to only consider outputs if it is being called on inputs.

Some types were renamed to be more general, and not just for inputs.

Pull Request: https://projects.blender.org/blender/blender/pulls/148132
2025-10-15 15:57:56 +02:00
Jacques Lucke
2fc32a2f18 Fix #147747: Shader Nodes: wrong code gen order
Currently, sometimes shader code generation fails because the code of top-level
nodes is interleaved with the code of a repeat zone. See #147747 for more
details.

Previously, the code-generation order was just the standard toposort of the node
tree, but it does not guarantee that all nodes in a zone are next to each other.
Also, it can't easily, because the zone detection itself depends on the
toposort. This patch implements another sorting step on top of the default
toposort. It packs nodes in zones together without changing the validity of the
toposort.

This is an alternative to #147999.

Pull Request: https://projects.blender.org/blender/blender/pulls/148005
2025-10-14 12:06:56 +02:00
Jacques Lucke
578f50aaa6 Merge branch 'blender-v5.0-release' 2025-10-14 11:19:05 +02:00
Jacques Lucke
7fd0a5acef Fix #147878: bad usage inferencing when there is a link cycle
The inferencing algorithm does not work reliably when the tree has cycles. So
return early and assume everything is used. The user is expected to fix the bad
link as soon as possible.

Pull Request: https://projects.blender.org/blender/blender/pulls/148009
2025-10-14 11:18:22 +02:00
Jacques Lucke
51fbcd84ce Merge branch 'blender-v5.0-release' 2025-10-13 18:25:36 +02:00
Jacques Lucke
d690ffd44f Fix #146949: Geometry Nodes: cache usage inference on modifier
This speeds up drawing of the UI of the Geometry Nodes modifier, especially for
very large node trees like in the files from #146949.

A couple previous commits and #147883 speed up the inferencing significantly
already. However, there is a certain limit to how fast this can be on large
complex node trees. While there is some more optimization potential, this patch
implements a cache on the Geometry Nodes modifier level. This means that as long
as the inputs and the node tree stays the same, the inferencing only has to
happen once, instead of on every redraw.

The main difficulty with this cache is that we don't have a good way to
invalidate it eagerly when any of the modifier inputs changes. That can
hopefully become simpler with #138117. For now, we have to check all input
values on redraw to check if anything has changed compared to the last redraw
and recompute the cache if there is any change.

Pull Request: https://projects.blender.org/blender/blender/pulls/147930
2025-10-13 18:23:50 +02:00
Hans Goudey
1d372bdc8b Refactor: Split CustomData attribute and newer attribute headers
Avoid including DNA_customdata_types.h everywhere we include the
attributes header. Over time the older attribute header should be
used less and less.

Part of #122398

Pull Request: https://projects.blender.org/blender/blender/pulls/147980
2025-10-13 15:38:26 +02:00
Damien Picard
2750cc1a70 I18n: Translate Geometry Nodes modifier warnings
Geometry Nodes can generate warnings inside node trees using a Warning
node. This is used to report warnings in the modifier interface.

This commit allows translation of these warnings in the interface
template, and extracts the messages from built-in asset node groups,
by looking at each warning node.

Pull Request: https://projects.blender.org/blender/blender/pulls/147584
2025-10-09 12:09:44 +02:00
Damien Picard
aa6f572ef2 I18n: Translate placeholder text in one prop
Pull Request: https://projects.blender.org/blender/blender/pulls/147580
2025-10-09 12:09:04 +02:00
Hans Goudey
a60e0cd44b Geometry Nodes: Support lists and grids in more function nodes
Now every function node except for "Sample UV Surface" supports
both list and grid outputs. Any grid or list input means the output also
has that type (combinations of grids and lists aren't supported).
However note that some nodes also have inputs that are always fields
evaluated on the target geometry.

There is still plenty of room for optimization. For grids and lists, all
the outputs will be computed, and every function node is evaluated
completely separately. It would be better to build a network similar to
fields and evaluate it lazily (when topology doesn't change anyway).

Pull Request: https://projects.blender.org/blender/blender/pulls/147312
2025-10-08 19:49:03 +02:00
Jacques Lucke
7422f2ea7a Fix #147559: performance regression due to unnecessary geometry copy
The geometry was copied later on when it was modified because there was still a
reference to it in the modifier. Since this uses implicit sharing, if there is
more than one reference, the data has to be copied before it can be modified.

Pull Request: https://projects.blender.org/blender/blender/pulls/147644
2025-10-08 19:14:37 +02:00
Miguel Pozo
71f4277467 GPU: Codegen: Native support for repeat zones
Support loops at the GLSL level instead of relying on
NOD_shader_nodes_inline.
This improves compilation and runtime performance, avoids causing
recompilations on iteration count changes, and allows supporting
dynamic iteration counts.

(EEVEE-only)

Pull Request: https://projects.blender.org/blender/blender/pulls/145269
2025-10-08 16:38:14 +02:00
Jacques Lucke
14966dfe0f Nodes: skip processing some unlinked outputs in usage inferencing
This is a partial fix for #146949. It speeds up drawing by about 15% for me.

Pull Request: https://projects.blender.org/blender/blender/pulls/147612
2025-10-08 13:55:09 +02:00
Jacques Lucke
8ef6127b70 Nodes: minor speedup for usage inferencing
This reduces some overhead for group input nodes where many sockets are not used.
This helps a bit with resolving the performance regression in #146949.

Pull Request: https://projects.blender.org/blender/blender/pulls/147610
2025-10-08 13:00:38 +02:00
Jacques Lucke
a589cb5cf3 Fix #147600: warning pass-through hinders usage inference
The warning node just was not handled in the value inferencer yet.
2025-10-08 10:08:08 +02:00
Jacques Lucke
894d9883b1 Cleanup: Geometry Nodes: use cache mutex for lazy function graph generation
This is a more standard way to handle caches and avoids the need for
a custom double checked lock.

Pull Request: https://projects.blender.org/blender/blender/pulls/147345
2025-10-07 10:46:59 +02:00
Jacques Lucke
93e91f2116 Nodes: simplify editing group interface based on selected group input/output node
This fixes two annoyances when working on node groups: * One has to constantly
switch between the Group and Node tab in the sidebar. * Finding a specific group
input/output in the tree view can be annoying when there are lots of inputs.

This patch implements two features which simplify the process significantly: *
When selecting a group input/output node, activate the corresponding item in the
tree view.
  * When the node has multiple sockets, use the one that's closest to the
  cursor.
* Show the group interface tree view in the node properties when selecting a
Group Input/Output node.

This constains one UI change that may affect other areas: When a new tree view
is added on a redraw, the active element is now scrolled into view, instead of
the scroll bar just being at the very top.  It seems generally good to me, but
could be made optional.

Pull Request: https://projects.blender.org/blender/blender/pulls/147365
2025-10-07 09:22:28 +02:00
Jacques Lucke
c8180af8de Fix #147363: crash when adding asset modifier
This was caused by a stack-use-after-free due to passing a lambda directly
into a `FunctionRef` that keeps a reference to it. This only happened for
me in an asan build, but not in a release/debug build.
2025-10-04 22:34:15 +02:00
Jacques Lucke
a65464fc1b Fix #147334: group outputs are hidden if the linked node group is missing
Assume that no output is disabled when there is an error in the group node.
2025-10-04 15:26:07 +02:00
Jacques Lucke
2323bd2691 Refactor: Nodes: extract value inferencer construction
This extracts the construction of the `SocketValueInferencer` out of
`SocketUsageInferencer`. This leads to better separation of concerns and gives
the caller more flexibility. In the future, I especially want to get information
about which group input values were required to determine the usage of other
group inputs. This might help with caching the inferenced values.

Pull Request: https://projects.blender.org/blender/blender/pulls/147352
2025-10-04 15:18:24 +02:00
Jacques Lucke
155b8b75d4 Geometry Nodes: optimize active gizmo detection
This reduces the constant overhead for the evaluation of the Geometry Nodes
modifier. Currently, it has to detect which gizmos are currently used, because
it has to potentially trigger additional evaluation to make the gizmos work.
Part of that is detecting which inputs are used, because gizmos for inputs that
are not used are hidden. Previously, it would compute whether each input is
used. This patch changes it so that only the inputs that have gizmos are
checked.

This reduces the evaluation time in my test from 2.2ms to 1.5ms.

Pull Request: https://projects.blender.org/blender/blender/pulls/147286
2025-10-04 10:36:42 +02:00
Miguel Pozo
ce29226a6c Shader Nodes: Default to 0 iterations for invalid Repeat Zones
Previously, Repeat Zones with non-static iterations would be fully
disconnected.
With this patch, they behave as if they have 0 iterations.

Co-authored-by: Jacques Lucke

Pull Request: https://projects.blender.org/blender/blender/pulls/147211
2025-10-03 11:49:39 +02:00
Jacques Lucke
6637be1c1c Refactor: Nodes: move socket usage inferencer class to header
The pattern here is very similar to `SocketValueInferencer`. The goal is to make
it easier to reuse this functionality without calling a higher level wrapper
like `infer_group_interface_usage`. This is especially useful when determining
the usage of just a subset of group inputs. I intend to use that to speedup the
detection of what gizmos should be displayed in
`foreach_active_gizmo_exposed_to_modifier`.

Pull Request: https://projects.blender.org/blender/blender/pulls/147234
2025-10-03 09:17:59 +02:00
Jacques Lucke
61cc3af675 Fix #147219: field in bundle is lost when geometry
This was an issue with creatiung the correct `reference_relations` between
input and output sockets. Those are necessary for the automatic lifetime inferencing.
2025-10-02 17:51:11 +02:00
Campbell Barton
88cbc71533 Build: unbreak WITH_OPENVDB=OFF 2025-10-02 21:51:23 +10:00
Hans Goudey
4339a60f78 Geometry Nodes: Add volume grid name search
Very similar to the layer name search added somewhat recently.
This just displays the names of existing grids in the "Name"
inputs to the Store and Get Named Grid nodes.

Pull Request: https://projects.blender.org/blender/blender/pulls/147163
2025-10-02 13:46:12 +02:00
Campbell Barton
b78c5fadf3 Cleanup: various non functional changes for C++ 2025-10-01 23:22:44 +00:00
Hans Goudey
a774ebd5af Geometry Nodes: Field to Grid Node
The purpose of this node is to create a grid with new voxel values on
the same grid topology as an existing grid. The new values are the
result of field evaluation. Multiple grids can be created at the same
time, so that intermediate results used for multiple grids can be
efficiently reused during evaluation. This is more efficient than the
"Volume Cube" node, for instance, because the output grid shares the
sparseness of the input topology grid.

Pull Request: https://projects.blender.org/blender/blender/pulls/147074
2025-10-01 18:40:49 +02:00
Habib Gahbiche
fb7818e55e Python: Create default node tree for new materials and worlds
The motivation is to keep backward compatibility after deprecating
 `material.use_nodes()` and `world.use_nodes`. For example the
following script would behave the same way in 4.5 and 5.0:
```python
mat = bpy.data.materials.new("My new mat")
mat.use_nodes = True
```

Pull Request: https://projects.blender.org/blender/blender/pulls/147052
2025-10-01 15:05:16 +02:00
Jacques Lucke
6614244a69 Geometry Nodes: improve warning panel title
The goal is to give more information to the user without having to open the
panel. Specifically, it's useful to know if there are any warnings/errors or
just info messages.

Pull Request: https://projects.blender.org/blender/blender/pulls/147103
2025-10-01 09:36:27 +02:00
Brady Johnston
8b3be68b3d Geometry Nodes: new Join Bundle Node
Adds a Join Bundle node with a multi-input Bundle socket. Bundles are
iterated on the top level of each input bundle and items added to the resulting
single bundle. While creating the final bundle existing items have priority and
new items with an already existing name are discarded.

There is an info message when there are duplicate keys in the input bundles.

Co-authored-by: Brady Johnston
Co-authored-by: Jacques Lucke
Pull Request: https://projects.blender.org/blender/blender/pulls/146750
2025-10-01 09:20:11 +02:00
Jacques Lucke
d21f9fa07d Refactor: Geometry Nodes: extract function to draw panel content in modifier
Besides extracting a function, this also cleans up the construction of the rna_path.
2025-09-30 06:56:55 +02:00
Jacques Lucke
e53f0066f9 Fix #146409: nested shader node outputs are ignored
This was supported before, and was accidentally removed in 32c301e3cf. This
patch brings back support for nested shader node outputs. Only rule is that they
must not be in a zone.

Pull Request: https://projects.blender.org/blender/blender/pulls/146983
2025-09-29 18:17:35 +02:00
Jacques Lucke
ef92735a95 Nodes: support optional labels for group inputs
Built-in nodes already used the functionality to hide the input labels in a few
situations. However, this functionality was not exposed for node groups before.
It required some refactoring to get the semantics of the flag right. The tricky
aspect is that "Hide Label" would be an incorrect name, because the label is
still shown under various circumstances. Instead, the flag merely indicates that
drawing code may skip drawing the label.

This adds a new "Optional Label" input for node group inputs. Other names are
possible like "Requires Label" which would be the inverse.

Overall the implementation is pretty straight forward after
1f489ea31a,
469a70dba9 and
f79896f5b9.

Pull Request: https://projects.blender.org/blender/blender/pulls/146939
2025-09-29 18:14:41 +02:00
YimingWu
5cde024fc9 Fix #146413: Truncate socket names only if space is present after prefix
In 95259228d9 an optimization was made to
simplify geometry nodes socket names on panels when they contain the
exact group title as prefix, but this leads to issue where `Opening` can
be truncated as `ing` which is not desired. Now will check if a space
character is present after the prefix, then do the truncation.

Note that this implementation still doesn't truncate `CamelCase` or any
CJK name strings because they don't use the space character as
separator.

Pull Request: https://projects.blender.org/blender/blender/pulls/146973
2025-09-29 17:37:17 +02:00
Jacques Lucke
02bdc709c2 Shader Nodes: support Menu Switch node
This implements the Menu Switch node in shader nodes. It's the same node that is
used in Geometry Nodes and the Compositor.

The Menu Switch node is purely handled during preprocessing and thus builds on
top of #141936. Hence, it's input has to be a single value, just like the
iteration count for repeat zones. This limitation can be lifted in the future,
but currently there is no way to produce a non-single menu value in shader
nodes. This will become possible if other Switch nodes are added though.

Pull Request: https://projects.blender.org/blender/blender/pulls/146896
2025-09-29 17:26:38 +02:00
Hans Goudey
b5863c401e Fix: Geometry Nodes: Function nodes crash for unsupported grid types
The multi-function node evaluation code correctly didn't create a grid
with an unsupported type, but then the code crashed in the logging
code when setting default for the outputs. Instead just use a common
utility for that goal. And also add support for executing a function node
if only outputs with supported types are required (for example when
creating a grid for the "Fac" output of the noise node, but not the
color output).

Pull Request: https://projects.blender.org/blender/blender/pulls/146937
2025-09-29 01:49:01 +02:00
Jacques Lucke
96ce5ee0c0 Cleanup: use utility method to get node group input usage
This also results in a small speedup because of the early exit
in is_group_input_used.
2025-09-28 21:19:19 +02:00
Jacques Lucke
f79896f5b9 Refactor: Nodes: unify optional-label handling for sockets
Previously, the input socket drawing code did not cover all cases with required
and optional labels for all socket types. E.g. menu sockets were never drawn
with label (unless there was some error) regardless of whether `optional_label`
was set or not.

This patch unifies the handling of this flag, i.e. all socket types support
drawing with and without label. This is also required before we can expose this
functionality to users.

Since all menu inputs had optional labels by default before, this patch makes
labels optional explicitly by changing the declaration of all the nodes. This
way, there is no expected user-visible change with this patch.

Pull Request: https://projects.blender.org/blender/blender/pulls/146935
2025-09-28 19:38:14 +02:00
Jacques Lucke
469a70dba9 Cleanup: Nodes: rename hide_label to optional_label internally
The new name better represents the actual meaning of the value.
"hide_value" was wrong because it didn't even hide the label in
many cases.

This property just indicates that the input is still understandable
even if the label is not drawn. It's up to the drawing code to make
the final decision whether the label should be drawn or not. This
option just gives it the opportunity to skip the label if that results
in a cleaner UI.
2025-09-28 17:30:21 +02:00
Jacques Lucke
1f489ea31a Cleanup: Nodes: remove some runtime socket flags
This removes the `SOCK_NO_INTERNAL_LINK`, `SOCK_COMPACT` and `SOCK_HIDE_LABEL`
flags from `eNodeSocketFlag`.  Those are not necessary, because they just store
a copy of the data that is stored in the socket declaration and are thus
effectively runtime data.

None of these flags were exposed to Python, so there is no breakage expected.

Pull Request: https://projects.blender.org/blender/blender/pulls/146925
2025-09-28 17:18:49 +02:00
Jacques Lucke
6ad9bf8af8 Fix #146521: Evaluate Closure node without closure behaves incorrectly
This was an oversight in the initial implementation. If there is no closure,
the node should behave like if it's muted, so it passes through inputs to
outputs when the names are equal. This is the same behavior as in
Geometry Nodes.
2025-09-28 16:24:48 +02:00
Jacques Lucke
99f84a8987 Fix #146345: assert when tracing closure value through nested zones
There were two issues:
* Missing null checks when the compute context of a socket can't be detected
  statically.
* Incorrect parent compute context detection for closures. The tricky aspect is
  that closures can be evaluated in a different compute context from where they
  are created.

Pull Request: https://projects.blender.org/blender/blender/pulls/146922
2025-09-28 15:39:17 +02:00
Jacques Lucke
e3e7bd670a Nodes: simplify rule for output visibility inferencing
#140856 added support for output visibility inferencing. Internally, it relied
on checking whether the output value of a group is a constant fallback value,
while on the user level this is mainly controlled with the new `Enable Output`
node. While it works, there are some unexpected behaviors when the user happens
to output the fallback value without expecting the socket to be hidden.
Additionally, this approach required the output value to be inferenced, which
may trigger more evaluation than we'd want.

This patch better aligns the internal behavior with the user-expected behavior.
This is achieved by not relying on any specific fallback values. Instead, for
each output socket it does an explicit check for whether it is connected to an
Enable Output node. Then the Enable input of that node is computed and the
output visibility is derived from that directly. This is still fully composable
with nested node groups etc. It also allows extending this check in the future
to e.g. automatically disable certain anonymous attribute outputs when the
corresponding output geometry is unused.

Note, since only changes in menu sockets are allowed to change visibility by
convention, this also applies here. Same as before.

The main design on the user-level with the Enable Output node is still exactly
the same as before.

Pull Request: https://projects.blender.org/blender/blender/pulls/146918
2025-09-28 13:52:52 +02:00
Jacques Lucke
056dafffb3 Fix: Nodes: avoid creating invalid internal link when initializing closure 2025-09-27 22:58:30 +02:00
Jacques Lucke
ee5e14e5fe Fix: Nodes: forbid muting Group Input nodes
This is already the case for Group Output nodes. It was an oversight
not to do the same for inputs.

Also see https://archive.blender.org/developer/D13364.
2025-09-27 22:52:29 +02:00
Jacques Lucke
1fd6d9263c Nodes: menu switch labels in index switch nodes
The goal here is to simplify working with the common pattern where a Menu Switch
node is followed by an Index Switch node. This is achieved by detecting this
pattern and drawing the item names from the menu switch node in the index switch
node.

This slightly refactors the custom socket drawing callback to make it easier for
it indirectly call the default drawing function.

Pull Request: https://projects.blender.org/blender/blender/pulls/145710
2025-09-27 21:49:47 +02:00
Jacques Lucke
ce85d4cbaf Shader Nodes: improve preservation of repeat zones in shader nodes inlining
These are some cleanups and fixes extracted from #146068. Preserved repeat
zones are not used by any render engine yet.

Pull Request: https://projects.blender.org/blender/blender/pulls/146890
2025-09-27 21:02:29 +02:00
Jacques Lucke
60a416bea4 Geometry Nodes: improve socket shapes for bundle and closure nodes
Previously, the closure and bundle nodes were a bit restrictive when it comes to
socket shapes. Especially the bundle nodes did not support customizing the
socket shape at all, so they always worked with dynamic values. This was
problematic, because it meant that e.g. the outputs of the Separate Bundle node
looked like they couldn't be used as single values, and other similar issues.

With this patch, the following is supported (a few aspects were supported before
but now it all fits better together): * Support manually selecting socket shapes
in Combine Bundle, Separate Bundle, Closure Input, Closure Output and Evaluate
Closure nodes. * Automatic inferencing of shapes in all these nodes, as long as
the socket shape is set to "auto". * A new "Define Signature" option can be
enabled in the nodes. If enabled, linked nodes will also sync the socket shapes
from that node. In the future, we also want to add support for naming the
signature.

Pull Request: https://projects.blender.org/blender/blender/pulls/145550
2025-09-27 14:58:43 +02:00