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
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.
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
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
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.
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.
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.
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
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.
- 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.
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.
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
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
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.
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
- 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
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