Commit Graph

120055 Commits

Author SHA1 Message Date
Clément Foucault
2513fbedca GPU: Shader: Add support for references
Implementation of #137341

This adds support for using references to any variable in a local scope
inside the shader codebase.

Example:
```cpp
int a = 0;
int &b = a;
b++; /* a == 1 */
```
Using `auto` is supported for reference definition as the type is not
preserved by the copy paste procedure. Type checking is done by the
C++ shader compilation or after the copy paste procedure during shader
compilation. `auto` is still unsupported for other variable declarations.

Reference to opaque types (`image`, `sampler`) are supported since
they are never really assigned to a temp variable.

This implements all safety feature related to the implementation being
copy pasting the definition string. That is:
- No `--`, `++` operators.
- No function calls.
- Array subscript index needs to be int constants or constant variable.

The copy pasting does not replace member access:
`auto &a = b; a.a = c;` becomes  `b.a = c;`
The copy pasting does not replace function calls:
`auto &a = b; a = a();` becomes  `b = a();`

While limited, this already allows for nicer syntax (aliasing) for
accessing SSBOs and the potential overhead of a copy semantic:
```cpp
ViewMatrices matrices  = drw_view_buf[0];
matrices.viewmat = float4x4(1);
drw_view_buf[0] = matrices;
```
Can now be written as;
```cpp
ViewMatrices &matrices  = drw_view_buf[0];
matrices.viewmat = float4x4(1);
```
Which expands to;
```cpp
drw_view_buf[0].viewmat = float4x4(1);
```

Note that the reference semantic is not carried through function call
because arguments are transformed to `inout` in GLSL. `inout` has
copy semantic but it is often implemented as reference by some
implementations.

Another important note is that this copy-pasting doesn't check if a
symbol is a variable. It can match a typename. But given that our
typenames have different capitalizations style this is unlikely to be
an issue. If that issue arise, we can add a check for it.

Rel #137446

Pull Request: https://projects.blender.org/blender/blender/pulls/138412
2025-05-06 13:36:59 +02:00
Falk David
6c092909ab Fix: Grease Pencil: Crash in Set Spline Resolution node
Blender would crash in the "Set Spline Resolution" when the
Grease Pencil object had a bezier curve and the resolution is
changed.

This was because the triangle cache of the drawing wasn't
recomputed after the number of evaluated points changed.
2025-05-06 12:16:44 +02:00
Blastframe
bc6b2a98fb Fix #138420: Grease Pencil: "Add" Operator Applies 'Show In Front' and 'Use Lights' to all object types
This patch ensures that the "Show In Front" and "Use Lights" options
in the Grease Pencil Add operator are respected for all object types,
not just those using the Line Art modifier (e.g. GREASE_PENCIL_LINEART_*).

Pull Request: https://projects.blender.org/blender/blender/pulls/138422
2025-05-06 11:17:39 +02:00
Clément Foucault
41ed07d55e GPU: Shader: Add support for basic template support through preprocessor
Allows basic usage of templated functions.
There is no support for templated struct.

Benefit:
- More readable than macros in shader sources.
- Compatible with C++ tools.
- More sharing possible with host C++ code.

Requirements/Limitations:
- No default arguments to template parameters.
- Must use explicit instantiation for all variant needed.
- Explicit instantiation needs to **not** use argument deduction.
- Calls to template needs to have all template argument explicit
  or all implicit.
- Template overload is not supported (redefining the same template
  with different template argument or function argument types).

Currently implemented as Macros inside the build-time pre-pocessor,
but that could change to copy-paste to allow better error reporting.
However, the Macros keep the shader code reduced in the final binary
and allow different file to declare different instantiation.

The implementation is done by declaring overloads for each explicit
instantiation.

If a template has arguments not present in function
arguments, then all arguments **values** are appended to the
function name. The explicit template callsite is then modified to use
`TEMPLATE_GLUE` which will call the correct function. This is
why template argument deduction is not supported in this case.

Rel #137446

Pull Request: https://projects.blender.org/blender/blender/pulls/137441
2025-05-06 10:41:25 +02:00
YimingWu
2d1904d957 Fix #138439: Eraser/stabilizer brush cursor drawing correction
Correct small Eraser/stabilizer brush cursor drawing issues introduced
by typos in 7d97ba4c5f.

Pull Request: https://projects.blender.org/blender/blender/pulls/138443
2025-05-06 09:32:02 +02:00
Jacques Lucke
6ba9d4b21f Nodes: take the viewer node label into account in context path
Previously, only the node name was taken into account. However, this
is not practical, because the user usually renames the label instead of the
name and it makes sense to show the user-defined name in the context path.
2025-05-06 08:55:53 +02:00
Jacques Lucke
4469f850fe Fix: Nodes: missing viewer path name update
Previously, when the viewer node or node group name changes,
the change was not updated directly in the spreadsheet. It was
only updated later when the viewer path changed entirely.
2025-05-06 08:55:53 +02:00
Jacques Lucke
a7cce5abde Fix: Nodes: bring back node group name in viewer path
This worked in e.g. Blender 4.0 but was broken at some point accidentally.
Now, the context path in the spreadsheet contains the names of node
groups again.
2025-05-06 08:55:52 +02:00
Guillermo Venegas
4845ae8bf2 Refactor: UI: Replace uiLayoutPanel with class method uiLayout::panel
This converts the public `uiLayoutPanel` function to an object oriented
API (`uiLayout::panel`), matching the python API.
This reduces the difference between the C++ API with the python version,
its also helps while converting code from python to C++ code (or vice-versa),
making it almost seamless.

Pull Request: https://projects.blender.org/blender/blender/pulls/138461
2025-05-06 07:58:02 +02:00
Campbell Barton
7ab348bf06 Fix: low UV opacity hides UV selection in edge-select mode
In vertex & face modes the selection remained visible when the UV
opacity was zero (or near zero).

In those cases applying the opacity to the edge selection makes sense,
however in edge-select mode this caused UV's to become invisible.
2025-05-06 04:22:00 +00:00
Campbell Barton
4f18c5e389 Cleanup: naming for MeshUVs members
- Use "select_{vert/edge/face}_" convention for UV's
  matching edit-mesh naming.
- Rename `show_face_` to `show_face_overlay_` for 3D & UV views.
- Rename `show_face_dots_` to `select_face_dots_` since they're
  they display selection and aren't used in object mode.
2025-05-06 04:00:37 +00:00
Campbell Barton
490ab44e47 Cleanup: split private member for showing faces into two values
The same value was used to show selected UV faces & object mode face
overlays. This made logic a little more difficult to follow as the
same value was set & used differently based on the context.
2025-05-06 13:49:38 +10:00
Campbell Barton
429399fc1a Cleanup: use underscore suffix for private member in MeshUVs 2025-05-06 13:49:03 +10:00
Richard Antalik
6dcd732555 Fix #138321: Movieclip strip does not blend with background
Movieclip can output buffer with smaller resolution than scene
resolution, but this was not handled in `strip_raw_image_size_get()`.

Small downside of this change is, that if movieclip source file can not
be read, its width and height is initialized to `IMG_SIZE_FALLBACK`.
So this may be confusing to users, but this would be quite rare
scenario.

Pull Request: https://projects.blender.org/blender/blender/pulls/138352
2025-05-06 05:25:51 +02:00
Richard Antalik
4a11be2656 VSE: Add option to translate pivot point
This feature allows you to change postion of origin/pivot for images
without changing their position.

It is implemented as property of transform operator. It is activated
by pressing `Ctrl + .` shortcut.
Move Origin item was also added to transform menu.

Origin can be snapped to 3x3 grid on strip image. This represents
most usual anchor points.

Ref: #134251
Pull Request: https://projects.blender.org/blender/blender/pulls/134206
2025-05-06 05:16:56 +02:00
Campbell Barton
509b39f90e UV: support sticky modes when edge sync-select is enabled
Previously sync-select in edge-select mode behaved in much the same
way as vertex selection, since a selected edge could cause a vertex
on an a disconnected UV island to be selected.

Now single vertices are no longer considered selected when the
Sticky-Mode is set to "Location" (the default).

Notes on changes when sync-select is enabled:

- The main change from a user perspective is edge & face select modes
  show the selected edges.

- This resolves a problem in edge & face selection modes where it wasn't
  possible to differentiate between a selected edge and two selected
  vertices on either side of an unselected edge.
2025-05-06 02:59:40 +00:00
Jacques Lucke
1363319844 Geometry Nodes: add Import VDB node
This adds an Import VDB node. It loads all the grids from a .vdb file and hence
outputs a Volume geometry instead of an individual grid.

The grids are cached through the existing volume grid file cache, so they are
automatically deduplicated when volume grids are loaded from files in other
ways.

Pull Request: https://projects.blender.org/blender/blender/pulls/138380
2025-05-06 04:13:11 +02:00
Jacques Lucke
0553f96bec Fix: Nodes: missing node tree centering
When a new node tree becomes active based on the context, the node editor was
not centered on the new tree. This can easily lead to the situation where there
is no node visible, and the user first has to search for the nodes.

The reason for this is unexpectedly special:
* `snode_set_context` calls `ED_node_tree_start` which adds the `NC_SCENE |
  ND_NODES` notifier.
* Typically, this would update the `View2D` of the region in
  `node_area_listener`.
* However, `snode_set_context` is called from
  `wm_event_do_refresh_wm_and_depsgraph` which happens after(!) the listeners
  run. Therefore, the node editor is redrawn before the listener is handled.
* During redraw, the stored view center is overridden. When it is later used in
  the listener, the value is lost already.

This patch solves this by updating the view center eagerly when opening changing
what node tree is visible, instead of trying to it lazily where the required
information might be lost already.

Pull Request: https://projects.blender.org/blender/blender/pulls/138389
2025-05-06 04:12:03 +02:00
Campbell Barton
01d9b7b095 Cleanup: improve naming, simplify logic for UV face-dot check
Avoid setting non-sync-select values then overwriting with sync-select
as it makes the logic less straightforward.
2025-05-06 01:55:15 +00:00
Campbell Barton
7827286620 Fix: UV face-dots not showing in face select mode
Regression in [0] which missed a rename.

[0]: 3f11d16501
2025-05-06 11:47:30 +10:00
Sean Kim
fd8728c596 Cleanup: Reorganize eUnifiedPaintSettingsFlags
Pull Request: https://projects.blender.org/blender/blender/pulls/138468
2025-05-06 03:42:14 +02:00
Sean Kim
9747e9072d Cleanup: Move dyntopo brush check macro to method
Pull Request: https://projects.blender.org/blender/blender/pulls/138470
2025-05-06 03:36:39 +02:00
Campbell Barton
fd6ac498b0 Cleanup: spelling in comments, strings (make check_spelling_*)
Also replace some triple-quoted non-doc-string strings with commented
blocks in examples.
2025-05-06 00:18:39 +00:00
Sean Kim
b47332c40d Fix: brush.asset_edit_metadata truncates author and description
Both fields have the RNA value defined with a max size of `MAX_NAME`,
despite the underlying DNA value being a dynamic length string.

To fix this, remove the length restriction for the operator.

Pull Request: https://projects.blender.org/blender/blender/pulls/138377
2025-05-05 21:19:31 +02:00
Miguel Pozo
7aeadd397d Workbench: Lazy subpasses initialization
Avoid initializing supbasses (and requesting their shaders) unless
they're actually needed.
Reduces the number of compiled Workbench shaders at startup
from 27 to 9.
Improves startup times.

Pull Request: https://projects.blender.org/blender/blender/pulls/138456
2025-05-05 20:24:16 +02:00
Aras Pranckevicius
aad7b2390b FBX: Speedup new importer
1. Do most of the work in creating meshes in parallel (i.e. everything that
   can happen on the non-Main mesh object)
2. Faster creation of transform F-Curves using the same machinery as
   !137004 (mostly speeds up animated characters import)
3. Make ufbx do FBX file parsing itself in parallel

Generally makes import 2x-5x faster, more detailed timings in the PR.

Pull Request: https://projects.blender.org/blender/blender/pulls/138367
2025-05-05 19:55:55 +02:00
Jacques Lucke
1b61e419a6 Geometry Nodes: support caching imported files
Currently, the import nodes always reimport on each evaluation. This patch adds
support for caching the loaded geometries. This is integrated with
`BLI_memory_cache.hh` and thus also takes the cache size limit into account. If
an imported file is modified on disk, the cache is invalidated. However,
Geometry Nodes will not automatically reevaluate when a file changes, so the
user would have to trigger the evaluation in some other way.

This is an alternative solution to #124369. The main benefits are that the cache
invalidation happens automatically and that the cache system is more general and
does not have to know about e.g. the different file types.

Caching speeds up node setups that heavily rely on import nodes significantly.

Pull Request: https://projects.blender.org/blender/blender/pulls/138425
2025-05-05 19:25:05 +02:00
YimingWu
3cd15d70b2 Fix #138398: Physics: Re-init rbw->shared->runtime loading old files
`RigidBodyWorld_Shared::runtime` is always expected to be valid. This
fix does this versioning for old files.

Pull Request: https://projects.blender.org/blender/blender/pulls/138418
2025-05-05 19:18:32 +02:00
Hans Goudey
c108d7bfd4 Cleanup: Missing include for integer type in BLI_generic_key.hh 2025-05-05 12:41:36 -04:00
Jacques Lucke
e09ccc9b35 Core: add templated version of BKE_id_new_nomain to reduce explicit casting
This adds a version of `BKE_id_new_nomain` that takes the ID type parameter as
template argument. This allows the function the return the newly created ID with
the correct type, removing the need to use `static_cast` on the call-site.

To make this work, I added a static `id_type` member to every ID struct. This
can also be used to create a similar API for other id management functions in
future patches.

```cpp
// Old
Mesh *mesh = static_cast<Mesh *>(BKE_id_new_nomain(ID_ME, "Mesh"));

// New
Mesh *mesh = BKE_id_new_nomain<Mesh>("Mesh");
```

Pull Request: https://projects.blender.org/blender/blender/pulls/138383
2025-05-05 18:41:03 +02:00
Clément Foucault
dd52130f92 Fix: Vulkan: Broken shader compilation
Was missing a newline after the shader stage define.
2025-05-05 18:38:37 +02:00
Jacques Lucke
20a6956079 Nodes: support searching for dynamic node labels
Previously, the ctrl+F search was only searching for either node names or explicitly
labeled nodes. Now it takes dynamic labels like node group nodes into account
making it much more useful.

Pull Request: https://projects.blender.org/blender/blender/pulls/138427
2025-05-05 18:09:22 +02:00
Clément Foucault
f844ed7869 GPU: Shader Preprocess: Processing time optimizations
Guarding expensive regex computation by much
cheaper checks to reduce compilation time.

Compiling `time ninja -j 1 bf_draw_shaders`

On MacOS M1 Max (debug build with glsl_preprocess optimization turned on):
Before 13.01 sec
After  9.08 sec

Pull Request: https://projects.blender.org/blender/blender/pulls/138336
2025-05-05 15:14:16 +02:00
Sergey Sharybin
bbfc97ad6f Move tests/data and assets to the main repository
This change moves the tests data files and publish folder of assets
repository to the main blender.git repository as LFS files.

The goal of this change is to eliminate toil of modifying tests,
cherry-picking changes to LFS branches, adding tests as part of a
PR which brings new features or fixes.

More detailed explanation and conversation can be found in the
design task.

Ref #137215

Pull Request: https://projects.blender.org/blender/blender/pulls/137219
2025-05-05 15:10:22 +02:00
Omar Emara
1f51172692 Compositor: Turn Alpha Over options to inputs
This patch turns the options of the Alpha Over node into inputs.

In the process, Convert Premultiplied option was renamed to Straight
Alpha.

Reference #137223.

Pull Request: https://projects.blender.org/blender/blender/pulls/138441
2025-05-05 14:16:27 +02:00
YimingWu
787f7272ae Fix #138439: Annotation: Correct immVertex when drawing stabilizer
the float/int version of `immVertex` can not be mixed in one
`immBegin/End` block. This fix corrects the usage and prevent invalid
int values from passing into the batch.

Pull Request: https://projects.blender.org/blender/blender/pulls/138442
2025-05-05 13:45:36 +02:00
Clément Foucault
7aef8c2917 GPU: Shader Preprocess: Add utility to search for references
This utility will only match `&` character inside a
reference declaration. This is needed for speeding up the
regex matches.
2025-05-05 13:42:42 +02:00
Clément Foucault
74e6d2c575 GPU: Shader: Add support for basic loop unrolling through preprocessor
This adds basic unrolling support for 2 syntax:
- `[[gpu::unroll]]` which does full loop unrolling
- `[[gpu::unroll(x)]]` which unrolls `x` iteration

Nesting is supported.

This change is motivated by the added cost in compilation
and execution time that some loops have even if they have
compile time defined iteration counts.

The syntax is inspired by `GL_EXT_control_flow_attributes`.
However, we might want to have our own prefix to show it is
a blender specific feature and that it differs from the standard.
I propose `[[gpu::unroll]]`.

In the future, we could extend this to support more directives that
can be expanded to backend specific extension / syntax. This would
avoid readability issue an error prone copy paste of large amount
of preprocessor directives.

Currently, given that GL's GLSL flavor doesn't support
any of these attributes, the preprocessor does some copy-pasting
that does the unrolling at the source level. Note that the added
`#line` allow for correct error logging.

For the `[[gpu::unroll]]` syntax, the `for` declaration
needs to follow a specific syntax to deduce the number
of loop iteration.
This variant removes the continue condition between iteration,
so all iterations are evaluated. This could be modified
using a special keyword.

For the `[[gpu::unroll(n)]]` syntax, the usercode needs
to make sure that `n` is large enough to cover all iterations
as the loop is completely removed.
We could add shader `assert` to make sure that there is
never a remaining iteration.
This behavior is usually different from what you see in other
implementation as we do not keep a loop at all. Usually, compilers
still keep the loop if it is not unrolled fully. But given we don't
have IR, this is the best we can do.

`break` and `continue` statement are forbidden at the unrolled loop
scope level. Nested loop and switch can contain these keywords.
This is accounted for by checks in the pre-processor.

Only `for` loops are supported for now. There are no real
incentive to add support for `while` given how rare it is
in the shader codebase.

Rel #137446

Pull Request: https://projects.blender.org/blender/blender/pulls/137444
2025-05-05 13:37:51 +02:00
Jacques Lucke
c271c3b291 Fix: ID code not should not be passed as part of name
Found in #138383.
2025-05-05 11:47:42 +02:00
YimingWu
e441095edb Fix #137918: LineArt: Prevent invalidating the wrong cache
When baking multiple line art modifiers at once, line art can pick the
wrong cache data and free it before all modifiers have finished baking.
This fix corrected that logic so that when baking all line art, it will
always use/create/free the correct cache data.

Pull Request: https://projects.blender.org/blender/blender/pulls/138114
2025-05-05 11:03:58 +02:00
Clément Foucault
a14fa6bfe5 GPU: Shader Preprocess: Add string utilities
Allow faster and more robust parsing / mutation.
2025-05-05 11:03:36 +02:00
Omar Emara
ebe67e5ca0 Compositor: Remove Premultiplied option from Alpha Over node
This patch removes the Premultiplied option from the Alpha Over node.
The reasoning is as follows:

- The option mixed between alpha being straight and premultiplied, a
  state which doesn't happen in practice.
- The option conflicts with the Convert Premultiplied option, if it is
  not zero, then Convert Premultiplied does nothing.
- The option is implemented in a lossy way. It premultiplies the alpha
  assuming it is straight, then converts the result to straight again,
  then mixed between both results. This is as opposed to mixing the
  original straight input with the premultiplied input. The successive
  alpha conversion causes data loss in transparent regions.

Pull Request: https://projects.blender.org/blender/blender/pulls/138428
2025-05-05 10:51:34 +02:00
Falk David
a7d2b7850e Grease Pencil: Add initial support for Node Tools
This adds inital Grease Pencil support for node tools.

Node tools work in `Object Mode`, `Edit Mode`,`Sculpt Mode`,
and `Draw Mode`.

While Grease Pencil has many editing tools, including editing
multiple frames at the same time, for now, node tools only
allow editing the current frame.

Currently, the idea is that node tools can do arbitrary changes
to the drawings, but cannot do changes to the existing layer tree, e.g.
changing the order of layers, removing a layer or groups, etc.

All the node tool specific nodes like `Selection` and `Set Selection`
are adapted to work with Grease Pencil. In `Draw Mode`, we currently
interpret everything as selected.
The `Active Element` node has a `Layer` mode that provides the
index of the active layer (if there is one).

When `Auto-Key` is used, a new keyframe is created on the
current frame.
Locked/invisible layers cannot be edited with node tools.

Pull Request: https://projects.blender.org/blender/blender/pulls/136624
2025-05-05 10:41:21 +02:00
Clément Foucault
8dee08996e GPU: Shader: Add wrapper to stage agnostic function
This avoid having to guards functions that are
only available in fragment shader stage.

Calling the function inside another stage is still
invalid and will yield a compile error on Metal.

The vulkan and opengl glsl patch need to be modified
per stage to allow the fragment specific function
to be defined.

This is not yet widely used, but a good example is
the change in `film_display_depth_amend`.

Rel #137261

Pull Request: https://projects.blender.org/blender/blender/pulls/138280
2025-05-05 09:59:00 +02:00
Omar Emara
92ac9f3b25 Compositor: Remove Premultiplied option from Brightness node
This patch removes the Convert Premultiplied option from the Brightness
and Contrast node. The reasoning is that it is the only node that has
the option to operate on straight alpha, while not being particularly
different. Adding alpha conversion nodes around it is also very easy.
Furthermore, alpha conversion is a lossy operation, so the option looses
data in emissive pixels, and since it is enabled by default, users not
familiar with the exact mechanism of the option wouldn't know how to fix
this.

Pull Request: https://projects.blender.org/blender/blender/pulls/138318
2025-05-05 08:33:29 +02:00
Daniel Salazar
a36c9adfe4 Fix: Description error in uv_layers.remove()
Description for uv_layers.remove() is wrong, copy paste error.

Pull Request: https://projects.blender.org/blender/blender/pulls/124940
2025-05-05 08:28:21 +02:00
Sean Kim
bf0018d75b Cleanup: Add comment for tilt_sensitivity constant
Derived from discussions on D8893

Pull Request: https://projects.blender.org/blender/blender/pulls/138417
2025-05-05 04:45:48 +02:00
Hans Goudey
91c340a1a5 Cleanup: Remove redundant break after return in switch 2025-05-04 22:07:23 -04:00
Hans Goudey
beadd08fb7 Fix: A few small issues with spreadsheet row filters
- int2 and short2 filters were completely disfunctional
- Don't use threshold for integer comparisons; it's not in the UI
- Filter with geometry set name for instance "Name" column
2025-05-04 22:07:23 -04:00
Nicola
33bef53c3e Sculpt: Use box test to select BVH nodes affected by Clay Strips
Implements a box test to select nodes affected by Clay Strips. The ratio
of nodes selected compared to the sphere test depends heavily on the
mesh, but is generally between 50% and 70%. This results in better
performance and reduces memory usage.

Pull Request: https://projects.blender.org/blender/blender/pulls/138170
2025-05-05 04:01:01 +02:00