Commit Graph

5372 Commits

Author SHA1 Message Date
Hans Goudey
835696f152 Geometry Nodes: Move import nodes out of experimental
The import nodes are considered complete enough to expose without
the experimental option. This commit removes the option so they will
be exposed in 4.5. There are still some possible future improvements,
including automatic caching, possibly exposing more input sockets,
and possibly including imported paths in the "Internal Dependencies"
panel. Those are considered non blocking though.

Pull Request: https://projects.blender.org/blender/blender/pulls/135957
2025-03-17 13:54:48 +01:00
Hans Goudey
759923fdd7 Geometry Nodes: Use socket type for store named grid
This used custom data types before, which was misleading and didn't
scale well because the set of attribute types is different than the set
of grid types we can store. Now just use the grid data type, like how
the store named attribute node uses the attribute type.

This covers backward compatibility, but not forward compatibility.

Pull Request: https://projects.blender.org/blender/blender/pulls/135814
2025-03-14 18:36:16 +01:00
Jacques Lucke
51904839ac Fix #135948: Geometry Nodes: support evaluating undefined custom group nodes
The main reason that didn't work before because undefined custom node groups
have the undefined `bNodeType` (and thus are ignored in various places) but are
actually still groups that can be evaluated. The fix is just to handle custom
node groups a bit more explicitly.

In the future, we may want to have a separate "undefined custom group"
`bNodetype`, but that might a be a bit bigger project.

Pull Request: https://projects.blender.org/blender/blender/pulls/135974
2025-03-14 18:31:29 +01:00
Jun Mizutani
200e26ed15 Cleanup: the comma operator was used to separate assignment statements
This was a typo.

Pull Request: https://projects.blender.org/blender/blender/pulls/135900
2025-03-14 15:34:14 +01:00
Jacques Lucke
e297e6dab3 Fix #135815: missing instance attribute propagation 2025-03-14 12:41:17 +01:00
Jacques Lucke
1f223156ac Cleanup: add debug label 2025-03-14 12:21:34 +01:00
Habib Gahbiche
d8d09cdadb Geometry Nodes: shortcuts for viewer nodes
Implement shortcuts for viewer nodes. Viewer nodes are now activated using the operator `bpy.ops.node.activate_viewer()` instead of activating the viewer by setting the node to active.

This also unifies the behavior with viewer shortcuts in the compositor (see attachment in the original PR).

Pull Request: https://projects.blender.org/blender/blender/pulls/134555
2025-03-14 11:26:57 +01:00
Jacques Lucke
c23cf12560 Cleanup: Nodes: simplify getting socket type from static type 2025-03-14 10:16:56 +01:00
Omar Emara
9bf05f4def Refactor: Compositor: Provide const variants for data accessors
This patch provides const variants to the cpu_data accessors that
returns GSpan. This is done to better const correctness. Some code need
non-const data even for read-only data, so we have to const cast those
for the moment.
2025-03-13 14:49:01 +02:00
Campbell Barton
78c3f6a1ee Cleanup: adjust order of terms for BMesh UV map function calls
Order more generic terms first for better ordering, more useful
completion.
2025-03-13 15:23:46 +11:00
Omar Emara
b37afc86d1 Refactor: Compositor: Replace proxy results with data sharing
This patch refactors the result class to replace proxy results with the
possibility of doing data sharing through a shared heap allocated data
reference count. This is more robust and simpler since proxy results no
longer need to be handled as a special case in a lot of the results
code. Additionally, it allows stronger const correctness since inputs to
operations can now be const.

This is somewhat similar to implicit sharing used in other parts of
Blender, so we can look into using that in the future.

Pull Request: https://projects.blender.org/blender/blender/pulls/135778
2025-03-12 16:42:26 +01:00
Bastien Montagne
78969aaff8 Cleanup: nodes: Replace 'void' MEM_[cm]allocN with templated, type-safe MEM_[cm]allocN<T>.
The main issue of 'type-less' standard C allocations is that there is no check on
allocated type possible.

This is a serious source of annoyance (and crashes) when making some
low-level structs non-trivial, as tracking down all usages of these
structs in higher-level other structs and their allocation is... really
painful.

MEM_[cm]allocN<T> templates on the other hand do check that the
given type is trivial, at build time (static assert), which makes such issue...
trivial to catch.

NOTE: New code should strive to use MEM_new (i.e. allocation and
construction) as much as possible, even for trivial PoD types.

Pull Request: https://projects.blender.org/blender/blender/pulls/135855
2025-03-12 12:15:33 +01:00
Falk David
a92b68939a Geometry Nodes: Add "Scale" input to "Curve to Mesh" node
This replaces the implicit use of the `radius` attribute on the input
curves with an input field `Scale` that gets evaluated on the point
domain of the input curves to scale the profile.

It wasn't super intuitive that the `radius` would actually act as
a scale of the profile. E.g. if the radius of the input curve was
`1 meter` the resulting profile was unscaled (scaled by 1), but
wouldn't necessarily have a size of `1 meter` (only if the profile
also had a size of 1m)! If imperial units were used, `3.28084 ft`
would correspond to a scale of 1.

This change makes this behavior a lot more clear and potentially
removes the need for the assumption that the default curve radius
is `1.0f` (Ideally, the default curve radius should be `0.01f`).

While we did consider making the `Scale` input use the `radius`
field implicitly by default, we decided against it, because it again
"hides" the dependency on the radius and the fact that the radius
is used as a scale. Letting the user make this decision seems better.

Pull Request: https://projects.blender.org/blender/blender/pulls/134187
2025-03-11 19:06:47 +01:00
Hans Goudey
d2af128245 Cleanup: Use StringRef for volume grid name access
Previously `.data()` was used incorrectly in some cases.

Pull Request: https://projects.blender.org/blender/blender/pulls/135808
2025-03-11 18:52:23 +01:00
Habib Gahbiche
1230ed9627 Fix: invalid cryptomatte output image when input is not connected
**How to reproduce:**
1. Add Cryptomatte Node
2. Enable 'Object' render passes
3. Connect Cryptomatte to output (composite or viewer node)
4. Optional: set matte ID
5. (Do not connect input image)
6. Render
7. Observe invalid output image (or assert in debug build)
(see also PR for an example blend file)

Only CPU is affected. The solution follows the behavior of the GPU backend, where the input color of the single value input image is multiplied with the matte result to produce a non constant output.

Pull Request: https://projects.blender.org/blender/blender/pulls/135786
2025-03-11 15:22:55 +01:00
Harley Acheson
8ded9a8350 Merge branch 'blender-v4.4-release' 2025-03-10 12:29:11 -07:00
илья _
fd9ac90395 Fix #135581: node tree incorrect evaluation
Instances attributes are propagated by default by `Curve Fill`, but this
is not mentioned in a declaration.

Pull Request: https://projects.blender.org/blender/blender/pulls/135597
2025-03-10 18:10:28 +01:00
илья _
b0dfc90368 Cleanup: Geometry Nodes: Better use of BLI functions
There is a `mod_periodic` function which is equivalent to
`apply_offset_in_cyclic_range` but more general.
Also there is a side cleanup of the naming.

Pull Request: https://projects.blender.org/blender/blender/pulls/135667
2025-03-10 16:10:12 +01:00
Omar Emara
8ade574b9f Shading: Retain alpha in Mix Color shader code
The Mix Color shader node does not retain the alpha channel of the first
input in both the Linear Light and Soft Light modes, while it is retain
for other modes. Further, result clamping also ignores the alpha due to
using the vector clamp function, which introduces implicit conversion
that removes the alpha.

This does not matter for EEVEE because it does nothing with the alpha
channel. But the code will now be shared with the compositor, which does
care about the alpha channel. So adjust the code accordingly to retain
the alpha in those cases.

Pull Request: https://projects.blender.org/blender/blender/pulls/135632
2025-03-10 09:36:44 +01:00
Hans Goudey
59b6212fed Geometry Nodes: Avoid logging entire long strings
To avoid overhead from logging, don't log more than 100 characters.

Pull Request: https://projects.blender.org/blender/blender/pulls/135592
2025-03-07 17:54:26 +01:00
Hans Goudey
06f6d77979 Curves: Fix bounding box ignores radius, add option to geometry node
Unlike the legacy type, the radius isn't included in the bounds for the new
curves type. This hasn't been obvious because the drawing is quite broken
and doesn't use the radius properly.

This commit adds a separate cache for the bounds with the radius, which
is now used by default. The old cache is kept around for backward
compatibility in the bounding box geometry node, where a new
"Use Radius" option accesses the old behavior.

Pull Request: https://projects.blender.org/blender/blender/pulls/135584
2025-03-07 17:38:29 +01:00
Hans Goudey
3f596a651c Geometry Nodes: Add names to String to Curves instance geometries
The name of each instance geometry is the character. This makes debugging
in the spreadsheet much easier, and the objects from "Visual Geometry to Objects"
are actually usable too.

Pull Request: https://projects.blender.org/blender/blender/pulls/135599
2025-03-07 17:01:18 +01:00
Hans Goudey
9287bb759b Geometry Nodes: Import Text node
As a small addition to the import node features for 4.5,
this simple node imports a text file as a string. Potential
use cases include retrieving text for motion graphics.

Currently this just allows .txt files. More extensions could
be allowed in the future.

Pull Request: https://projects.blender.org/blender/blender/pulls/135459
2025-03-06 18:47:30 +01:00
Jacques Lucke
58eaced72d Merge branch 'blender-v4.4-release' 2025-03-06 09:54:51 +01:00
Jacques Lucke
e726357962 Fix: Geometry Nodes: bad attribute propagation with multiple group outputs and warning node
The issue was that sometimes the group inputs of a node group were shuffled
around unexpectedly and thus inputs were passed to the wrong sockets.

The `or_socket_usages` function sorts the given span so that the key is more
likely to be reused, reducing the number of nodes inserted in the graph.  The
issue was that `build_warning_node` passes `group_output_used_sockets_` into the
function the order of which is important. It thus should not be reordered.

The fix is to just never reorder the span passed to `or_socket_usages` but to
make a local copy instead which can be sorted without problems. Often this copy
is done already anyway when the span is inserted into
`graph_params.socket_usages_combination_cache` as `Vector`.

This fix also makes an assumption about `Map.lookup_or_add_cb` which was not
documented before. Namely it assumes that the key is moved into the map only
after the callback has been called. This behavior is now documented and there is
a unit test for it.

Pull Request: https://projects.blender.org/blender/blender/pulls/135528
2025-03-06 09:47:44 +01:00
Hans Goudey
d88d6331fd Cleanup: Modernize mesh variable naming in some cases
Simplify naming of vertex and corner indices, and replace "loop".
2025-03-05 23:16:09 -05:00
илья _
1e4af6719c Fix #135514: Corrupt Mix Shader Node names
Unlike all other nodes, the Mix node did not handle all cases of its
automatic label. This assumption was made in 02281dd26a and caused an
issue with reading uninitialized memory. In order to restrict the nodes
API interface later, this fix simply aligns the behavior of the mix node
with all others.

Pull Request: https://projects.blender.org/blender/blender/pulls/135535
2025-03-05 21:42:00 +01:00
Hans Goudey
0202307e54 Merge branch 'blender-v4.4-release' 2025-03-05 15:36:35 -05:00
Hans Goudey
312516d53e Fix #135517: Geometry nodes convex hull imprecision
The equivalent operation in edit mode reused existing vertices
rather than taking the new positions from the convex hull output.
This commit implements the same behavior for the geometry node.

Pull Request: https://projects.blender.org/blender/blender/pulls/135536
2025-03-05 21:18:45 +01:00
Bastien Montagne
dd168a35c5 Refactor: Replace MEM_cnew with a type-aware template version of MEM_callocN.
The general idea is to keep the 'old', C-style MEM_callocN signature, and slowly
replace most of its usages with the new, C++-style type-safer template version.

* `MEM_cnew<T>` allocation version is renamed to `MEM_callocN<T>`.
* `MEM_cnew_array<T>` allocation version is renamed to `MEM_calloc_arrayN<T>`.
* `MEM_cnew<T>` duplicate version is renamed to `MEM_dupallocN<T>`.

Similar templates type-safe version of `MEM_mallocN` will be added soon
as well.

Following discussions in !134452.

NOTE: For now static type checking in `MEM_callocN` and related are slightly
different for Windows MSVC. This compiler seems to consider structs using the
`DNA_DEFINE_CXX_METHODS` macro as non-trivial (likely because their default
copy constructors are deleted). So using checks on trivially
constructible/destructible instead on this compiler/system.

Pull Request: https://projects.blender.org/blender/blender/pulls/134771
2025-03-05 16:35:09 +01:00
Jacques Lucke
f9e02b5925 Geometry Nodes: support opening images in modifier
Previously, it was unnecessarily complicated to open an image that is passed
into Geometry Nodes.

Pull Request: https://projects.blender.org/blender/blender/pulls/135352
2025-03-04 23:59:22 +01:00
Jacques Lucke
c233955ef9 Geometry Nodes: support custom delimiter in Import CSV node
Previously, only `,` was a valid delimiter, but it's also common to have e.g.
tab or semicolon. Only single characters are supported as delimiters. A few
characters are not allowed because they have other meanings: `\n`, `\r`, `"`,
`\\`.

Note: The best way to get a tab character is the use the Special Characters node
currently.

Pull Request: https://projects.blender.org/blender/blender/pulls/135468
2025-03-04 23:58:02 +01:00
Hans Goudey
a48d155c87 Geometry Nodes: Add "Face" option to Mesh to Curve node
Adds a mode option to the node to choose between the existing
behavior and new behavior that converts each face to a cyclic curve.
Generally this is much faster than the existing mode because it's
easy to parallelize and because curve offsets and face and corner
attributes can be implicitly shared to avoid copies.
Resolves #134671.

Pull Request: https://projects.blender.org/blender/blender/pulls/134773
2025-03-04 19:16:36 +01:00
Omar Emara
c55594f0a1 Fix: Z Combine asserts when one output is unused
The Z Combine node asserts if one of its outputs are unused. That's
because we compete both outputs even if they are not needed. To fix
this, we skip outputs that are not needed by splitting the shaders to
compute each output independently.
2025-03-04 14:05:55 +02:00
Omar Emara
2284b7538a Fix: Keying asserts when Edges output is unused
The Keying node asserts if its Edges output is unused. That's because we
compete the outputs even if it not needed. To fix this, we skip that
output if not needed.
2025-03-04 12:43:08 +02:00
Omar Emara
afcd23fbe2 Fix: Scene Time asserts when one output is unused
The Scene Time node asserts if one of its outputs are unused. That's
because we compete both outputs even if they are not needed. To fix
this, we skip outputs that are not needed.
2025-03-04 10:52:11 +02:00
Aras Pranckevicius
cc2c6692c0 Cleanup: Name more IMB things as "byte" or "float" instead of "rect" and "rectFloat"
- IB_rect -> IB_byte_data
- IB_rectfloat -> IB_float_data
- Rename some functions:
	- IMB_get_rect_len -> IMB_get_pixel_count
	- IMB_rect_from_float -> IMB_byte_from_float
	- IMB_float_from_rect_ex -> IMB_float_from_byte_ex
	- IMB_float_from_rect -> IMB_float_from_byte
	- imb_addrectImBuf -> IMB_alloc_byte_pixels
	- imb_freerectImBuf -> IMB_free_byte_pixels
	- imb_addrectfloatImBuf -> IMB_alloc_float_pixels
	- imb_freerectfloatImBuf -> IMB_free_float_pixels
	- imb_freemipmapImBuf -> IMB_free_mipmaps
	- imb_freerectImbuf_all -> IMB_free_all_data
- Remove IB_multiview (not used at all)
- Remove obsolete "module" comments in public IMB headers

Pull Request: https://projects.blender.org/blender/blender/pulls/135348
2025-03-03 17:11:45 +01:00
Hans Goudey
9cade06f5f Refactor: Nodes: Use Map instead of GHash for compositor previews
Replace `bNodeInstanceHash` with a `Map`. Move it to the node tree
runtime data. Simplify some code by removing the tag from the hash
value and collecting unused previews directly. Then just remove a
bunch of code that's now unused.

Note that texture node previews haven't been working for a while
anyway, and the experimental shader node previews seem to use
a different system (this one is a remnant of Blender Internal).

Pull Request: https://projects.blender.org/blender/blender/pulls/135310
2025-03-03 14:04:20 +01:00
Falk David
2822777f13 Nodes: support boolean inputs as toggles in panel headers
Adds the option to create a boolean socket that can be used as a panel toggle.
This allows creating simpler and more compact node group UIs when a panel
can be "disabled".

The toggle input is a normal input socket that is just drawn a bit differently in
the UI. Whether a boolean is a toggle input or not does not affect evaluation.

Also see #133936 for guides on how to add and remove panel toggles.

Pull Request: https://projects.blender.org/blender/blender/pulls/133936
2025-02-28 19:07:02 +01:00
Omar Emara
e2d886a104 Compositor: Implement link validation
This patch implements link validation for compositor node trees. All
links are valid in the compositor, since there is implicit conversion
between all supported types. This is needed for link gather search
operations.
2025-02-28 16:34:38 +02:00
Hans Goudey
582cdc0cf2 Cleanup: Use Array for FieldInferencingInterface
There is no need for amortized growth for the field interface.
Array seems slightly better than Vector because it's smaller and
doesn't give the impression that the size might change.

Pull Request: https://projects.blender.org/blender/blender/pulls/135257
2025-02-27 17:32:51 +01:00
Jacques Lucke
b05fb3801e Merge branch 'blender-v4.4-release' 2025-02-27 17:16:47 +01:00
Jacques Lucke
66ba309f6e Fix #135031: data-race in Remove Attribute node 2025-02-27 17:16:17 +01:00
Hans Goudey
0c04952a76 Cleanup: Specify backing type for node enums
Otherwise it defaults to int. This change can make a few structs
slightly smaller. Also use a signed integer type for the compositor
enum; that's the convention for non-flag enums.
2025-02-27 10:14:29 -05:00
Omar Emara
fdeda50b5c Cleanup: Nodes: Use common prefix instead of sh_fn
Nodes that are shared between Geometry and Shader nodes use the prefix
sh_fn for their base type and poll functions. The compositor will also
share those nodes very soon, so we generalize the name to use the prefix
"common".
2025-02-27 14:51:24 +02:00
Jacques Lucke
3af79b1d3b Merge branch 'blender-v4.4-release' 2025-02-27 12:48:57 +01:00
Jacques Lucke
09fd1d48e2 Fix #135164: crash when deleting nodes from node tree after appending
The issue was that changing session ids for a data-block were not handled gracefully enough.

Pull Request: https://projects.blender.org/blender/blender/pulls/135230
2025-02-27 12:47:01 +01:00
Jacques Lucke
e05ef4c838 Nodes: support filepath filter for import nodes
Currently, when selecting a file path using the file browser opened from the
node socket, there is no filter active making it harder than necessary to find
the correct file. This patch adds the proper filter. Something similar is done
when using e.g. the gltf import from the menu.

Supporting this requires changes in a bunch of places:
* `StringPropertyRNA` now has a callback that returns the file path pattern.
  This has to be a callback, because the same property is used on all file path
  sockets, but the valid extension depends on the node.
* The string socket declaration also has the optional path pattern. This can be
  set in the node declarations.

Pull Request: https://projects.blender.org/blender/blender/pulls/134931
2025-02-24 18:52:10 +01:00
Omar Emara
c29971c688 Fix #135010: Crash when using Denoise node
Blender crashes when using the Denoise node. That's because the code
assumes normal input would have 4-channels, while this may not be the
case. To fix this, use the channels count from the result or the GPU
texture directly.
2025-02-24 13:22:40 +02:00
Omar Emara
7ab7e1efa6 Fix #134939: Passes are incorrectly interpreted as vectors
Some passes are now interpreted as vectors by the compositor Image node.
This is because it assumes 3-channel passes are always vector, but this
is not the case for passes that are RGB without an alpha channel. To fix
this, we also consider channel IDs to disambiguate the type of the pass.
2025-02-24 11:17:36 +02:00