Commit Graph

25005 Commits

Author SHA1 Message Date
Bogdan Nagirniak c0a0de617c Hydra: export Blender shader nodes as MaterialX node graph
This adds initial support for rendering Cycles and EEVEE shaders in Hydra
render engines that support MaterialX. Not all nodes are currently
supported, see the detailed compatibility list in #112864.

Co-authored-by: Georgiy Markelov <georgiy.m.markelov@gmail.com>
Co-authored-by: Vasyl Pidhirskyi <vpidhirskyi@gmail.com>

Pull Request: https://projects.blender.org/blender/blender/pulls/111765
2023-09-26 18:52:41 +02:00
Nathan Vegdahl 49eab72141 Fix #107030: return accurate action frame ranges from the Python API
This changes the `action.frame_range` Python API to return an accurate
frame range for actions.  Specifically, it was previously special-cased
to return a range with length 1 whenever the length was actually 0.  This
led to a bizarre situation where a real frame range of `[0.0, 0.2]` would
return that range as-is, but a real frame range of `[0.0, 0.0]` would
instead return a range of `[0.0, 1.0]`.

The new behavior simply always returns the real frame range.

The reason for the previous behavior was obscure: the relevant code was
also used internally in Blender's NLA system, and returning a zero-length
range could result in NLA strips getting infinite scale.  The code is now
separated out appropriately so that the NLA system still gets the
non-zero-length range, while the Python API for actions returns the real
range.

Pull Request: https://projects.blender.org/blender/blender/pulls/112709
2023-09-26 18:18:56 +02:00
Sybren A. Stüvel c524fbe623 Anim: Improve readability of channel colors in channel list
Draw anim channel colors as a little rectangle in the channel list,
instead of taking over the entire channel name background. This keeps
the channel names readable, regardless of the channel colors.

Channel colors are typically set via the bone colors, and since those
are chosen for visual contrast in the 3D Viewport, they aren't
guaranteed to also be a suitable background color for the channel list.
Because of this, it's no longer used as such.

The channel 'data' background (i.e. the keyframe area) is now drawn with
a consistent color, and much more subtle.

This also enables the 'Channel Group Colors' setting in the preferences
by default, as it is now way less obnoxious and invasive.

Design task: https://projects.blender.org/blender/blender/issues/69059
Reviewed-On: https://projects.blender.org/blender/blender/pulls/112861
2023-09-26 17:06:35 +02:00
Hans Goudey 395f279166 Fix: Missing node asset menu updates after mark asset
Use of node group assets relies on a few properties written to asset
meta-data for proper filtering of assets in menus (add modifier menu,
node add menu, 3D view menus for tools). Currently these meta-data
properties are written when updating their source properties and when
saving the file. That means they *aren't* written when marking a group
as an asset, which is necessary because the meta-data doesn't exist
before when the group isn't an asset. Currently users have to save the
file to update menus in this case, which isn't intuitive.

As a fix, call the function to write the meta-data when marking a
data-block as an asset.

Pull Request: https://projects.blender.org/blender/blender/pulls/112743
2023-09-26 16:38:50 +02:00
Jacques Lucke 5c5a041edd Fix #112022: allow vertex groups and attributes with same names again
This was discussed in #112022 and on devtalk:
https://devtalk.blender.org/t/vertex-groups-generic-attributes-and-name-clashing/31073

While vertex groups with the same name as attributes should be avoided, since
it can cause ambiguities when using attributes, it's something we can handle
gracefully for now. Enforcing unique names for vertex groups resulted in breaking
other functionality under some circumstances.

This effectively reverts 12ef20990b, except for
the bug fix in `BKE_id_attribute_new`.

#112891 adds a warning to avoid make users aware of duplicate names so that they
can be avoided in practice.

Pull Request: https://projects.blender.org/blender/blender/pulls/112889
2023-09-26 15:36:12 +02:00
Hans Goudey 97f2b01ea9 Fix #112351: Sculpt implicit sharing thread safety crash
Currently the iteration over a PBVH node's vertices retrieves mutable
access to the mask custom data layer. This isn't threadsafe, but it is
done in the multithreaded loops over all nodes.

In general, we need to be more careful and conservative about storage
of non-const pointers to mesh data. Ideally we would only have one
mutable reference to a resource at a time. And we should avoid doing
work like looking up custom data layers more than we need to.

To that end, make the pointer to the custom data layer used everywhere
const, and retrieve mutable access before parallel node iteration with
a specific function, and write to the mask data with that in mind.

This pushes us in the direction of sharing less code per PBVH type.
In my opinion that's a good thing, because we can actually optimize for
each type. For example, `write_mask_data` gives a picture of
how each of these hot loops could become much simpler.

Pull Request: https://projects.blender.org/blender/blender/pulls/112690
2023-09-26 14:21:07 +02:00
Alexander Gavrilov 0055ae01ab Anim: implement a new curve-aware vertex to B-Bone segment mapping mode.
Currently vertices are mapped to B-Bone segments without taking the
rest pose curve into account. This is very simple and fast, but causes
poor deformations in some cases where the rest curvature is significant,
e.g. mouth corners in the new Rigify face rig.

This patch implements a new mapping mode that addresses this problem.
The general idea is to do an orthogonal projection on the curve. However,
since there is no analytical solution for bezier curves, it uses the
segment approximation:

* First, boundaries between segments are used for a binary space
  partitioning search to narrow down the mapping to one segment.
* Then, a position on the segment is chosen via linear
  interpolation between the BSP planes.
* Finally, to remove the sharp discontinuity at the evolute surface
  a smoothing pass is applied to the chosen position by blending to
  reduce the slope around the planes previously used in the BSP search.

In order to make per-vertex processing faster, a new array with the
necessary vectors converted to the pose space, as well as some
precomputed coefficients, is built.

The new mode is implemented as a per-bone option in order to ensure
backward compatibility, and also because the new mode may not be
optimal for all cases due to the difference in performance, and
complications like the smoothed but still present mapping
discontinuities around the evolute surface.

Wiki: https://wiki.blender.org/wiki/Source/Animation/B-Bone_Vertex_Mapping

Pull Request: https://projects.blender.org/blender/blender/pulls/110758

Pull Request: https://projects.blender.org/blender/blender/pulls/110758
2023-09-26 14:17:21 +02:00
Campbell Barton 077832e063 Cleanup: spelling in comments 2023-09-26 19:50:48 +10:00
Hans Goudey 2aa393e727 Cleanup: Remove unnecessary struct keyword in BKE_screen.hh 2023-09-25 17:53:11 -04:00
Hans Goudey 916d4c9d9b Cleanup: Move BKE_screen.h to C++
See #103343
2023-09-25 17:53:11 -04:00
Weizhen Huang def9b76207 Shader: Change specular tint in Principled BSDF from float to color
For more artistic control. Tints the reflection of dielectric materials
at normal incidence.

Ref #99447

Pull Request: https://projects.blender.org/blender/blender/pulls/112192
2023-09-25 19:42:05 +02:00
Sergey Sharybin 19db9a213e Light linking: Allow re-ordering in the light linking collections
The order of collections in the light linking collection is important
as it is used for tie-breaking when the same object is reachable from
multiple linked collections with different light linking state.

This commit utilizes the generic tree view reordering operations to
allow insertion of elements to a specific location and to re-order
existing objects and collections in the light linking collection.

It is possible to re-order both collections and objects, even tough
re-ordering objects does not really make a difference for the light
linking behavior. It is not possible to place an object before
collections.

Pull Request: https://projects.blender.org/blender/blender/pulls/112849
2023-09-25 18:00:28 +02:00
Sybren A. Stüvel ac1c5d943c Anim: make `ANIM_bonecolor_posebone_get` handle const only
The color returned by `ANIM_bonecolor_posebone_get()` is not supposed
to be edited, so just return it as `const` and take a `const bPoseChannel`
as argument.

This makes the function usable in a wider range of situations, for example
the drawing code (which shouldn't alter any of these colors).
2023-09-25 17:29:04 +02:00
Sybren A. Stüvel eab95fa2aa Anim: enable visual keying of IK-influenced bones
Enable visual keying of bones that are influenced by an IK constraint.
This wasn't possible before, as the visual keying system only checked
constraints on the bone itself, and not whether the bone was part of an
IK chain.

This commit introduces a new `bPoseChannel::constflag` value
`PCHAN_INFLUENCED_BY_IK` that is set whenever the pose bone is part of
an IK chain.

The `pchan->constflag` field is computed during depsgraph evaluation. If
the depsgraph is active, it is now also written back to the original
pchan, so that it can be used in the "should visual keying be used"
function.

Fixes: #76791 "Different results when keyframing visual transforms and
applying transforms manually on IK constraint". Note that visually
keying does *not* copy the visual pose to the current pose. Furthermore,
when visually keying only part of the IK chain, the result of
re-evaluating the IK constraint (for example by moving the scene forward
and then backward by one frame) may still produce a different result, as
the IK chain now has a different start orientation.

Note that commit explicitly does not cover Spline IK constraints. They
can introduce heavy shear, especially with the default settings, which
cannot be represented by keys on loc/rot/scale.

For historical reference: 876cfc837e
introduces the 'use visual keying' preference option, where Blender
automatically chooses whether or not to use visual keying. This is why
there is a function at all that determines whether to use visual keying
or not.
2023-09-25 14:37:22 +02:00
Sybren A. Stüvel caf46c9fbb Refactor: anim, rename flag PCHAN_HAS_TARGET to PCHAN_HAS_NO_TARGET
Rename the `bPoseChannel::flag` `PCHAN_HAS_TARGET` to `PCHAN_HAS_NO_TARGET`
as that is actually the meaning of the flag (in the majority of the code).

Since the flag was so confusingly named, there were some mixups in the
armature overlay drawing code as well, which have been fixed now too.
2023-09-25 14:33:51 +02:00
Sybren A. Stüvel 05b725c744 Anim: redefine `PCHAN_HAS_CONST` flag to mean "has a constraint"
Change the definition of the `PCHAN_HAS_CONST` pose channel flag. It used
to mean "has a constraint that is not IK or Spline IK", and now it just
means "has a constraint".

This has no direct effect yet, as the flag is only used in drawing code
when there is no (spline) IK constraint. However, I feel that the flag
name should match its expected behaviour, and IMO, in this case, making
that behaviour simpler is better than documenting more.
2023-09-25 14:33:51 +02:00
Sybren A. Stüvel 12fc4b6c58 Refactor: anim, change if-elseif-else chain to switch + reduce iterations
Refactor `BKE_pose_channel_copy_data()` so that it iterates over the entire
armature only once (instead of twice), and to use a `switch` instead of
a chain of `if`/`else if`/`else` clauses.

No functional changes.
2023-09-25 14:33:51 +02:00
Hans Goudey 6875925efa Geometry Nodes: Add option to force inputs to be single values
Add a checkbox to node group inputs to force inputs to be single values
and not accept varying fields. While this could also be done more
automatically, and it could be argued that requiring the flexibility is
helpful for users who want to use attributes, there are cases where the
field inferencing doesn't work, or the "use attribute" option is just
unhelpful. People use workarounds with primitive nodes to get the same
behavior anyway.

Pull Request: https://projects.blender.org/blender/blender/pulls/112745
2023-09-25 13:39:44 +02:00
Jeroen Bakker a6d6251b6e Fix #111532: Partial Update Byte Data Texture with Scaling Broken
When texture painting on a Non-color byte texture with Texture limit active
(or the texture didn't fit on the GPU) the data for partial updating of a GPU
texture was incorrect.

`gpu_texture_update_scaled` expects an input buffer clipped to
the bounds of the input area that needs to be updated. In case for Byte
textures with Non Color colorspace  it received the unmodified input
buffer, resulting in incorrect data to be uploaded to the GPU texture.

This PR fixes this by selecting the non-optimized branch when the
texture is a Byte buffer with Data color space and scaling should
happen.

Pull Request: https://projects.blender.org/blender/blender/pulls/112834
2023-09-25 12:46:17 +02:00
Falk David 16e195a111 Cleanup: GPv3 layer tree manipulations
In preparation of https://projects.blender.org/blender/blender/pulls/112535, we need to make sure all layer tree manipulations are in functions on the `GreasePencil` struct so we can keep the `CustomData` for layers in sync with the layer tree.

 This PR makes sure that all the functions that change the layer tree in any way are `protected` on the `LayerGroup` class. The `GreasePencil` struct is declared `friend` with `LayerGroup`.

We also cleanup and remove a lot of code duplication between layers and layer groups and try to write functions in a generic way for `TreeNode` (both layers and layer groups are tree nodes).

Pull Request: https://projects.blender.org/blender/blender/pulls/112837
2023-09-25 12:11:18 +02:00
Jacques Lucke 8362563949 UI: show recently selected items at the top of searches
The goal is to make the search faster to use by dynamically adapting to the user.
This can be achieved using the simple but common approach of showing recently
selected items at the top. Note, that the "matching score" between the query and
each search item still has precedence when determining the order. So the last used
item is only at the top, if there is no other search item that matches the query better.

Besides making the search generally faster to use, my hope is that this can also
reduce the need for manually weighting search items in some places. This is
because while the ordering might not be perfect the first time, it will always be
once the user selected the element that should be at the top once.

This patch includes:
* Support for taking recent searches into account in string searching.
* Keep track of a global list of recent searches.
* Store recent searches on disk similar to recently opened files.
* A new setting in the user preferences that allows disabling the functionality.
  This can be used if deterministic key strokes are required, e.g. for automated tests.

In the future this could be improved in different ways:
* Add some kind of separator in the search list to indicate which elements are at
  the top because they have been used recently.
* Store the recent search items per search, instead of in a global list. This way
  it could adapt to the user even better.

Pull Request: https://projects.blender.org/blender/blender/pulls/110828
2023-09-25 10:56:12 +02:00
Campbell Barton e38ff7c06d Cleanup: use C++ comments for disabled code 2023-09-25 17:06:04 +10:00
Campbell Barton 6c91e1c205 Cleanup: spelling in comments 2023-09-25 15:25:43 +10:00
Campbell Barton caef976ceb Cleanup: correct typo "hardeness" to "hardness" in DNA & variable names 2023-09-25 12:05:50 +10:00
Hans Goudey c6380d772c Fix: Debug build error after recent cleanup
Caused by 8954b70d49
2023-09-22 11:22:30 -04:00
Hans Goudey 2419acf756 Nodes: Move float values to "Value" node with link-drag-search
This was handled for other nodes in 9726e4a0ad, but the older
"Value" node stores its value differently, so that was left for later.

Pull Request: https://projects.blender.org/blender/blender/pulls/112722
2023-09-22 15:45:05 +02:00
Hans Goudey 8954b70d49 Cleanup: Small changes in node interface item addition
- Use `StringRef` over `StringRefNull`, since it handles `nullptr` in
  its constructor and gives more flexibility about the string's source.
- Change `const char *` to `StringRef` as well, for improved ergonomics
  and efficiency.
- Move `add_interface_socket_from_node` to a .cc file. It's not small
  or performance sensitive enough to be inlined.
- Avoid allocating empty strings for item descriptions.
- Allocate with `BLI_strdupn` to avoid unnecessary `strlen` calls.
- Move a bit more code into a proper namespace.

Pull Request: https://projects.blender.org/blender/blender/pulls/112721
2023-09-22 15:43:59 +02:00
Hans Goudey 8a9dad1f2c Cleanup: Remove unnecessary struct keyword from newly C++ headers
Also remove `void` in `(void)`.
2023-09-22 08:08:19 -04:00
Philipp Oeser 8094309474 Fix: Changing theme color for recent additions doesn't save
affected were:
- VSE Transition color
- Enum Highlighting color

which missed version bumps from 5f0a8759b0 / a7ad0ad8fb.

Similar to 179c419115.

Pull Request: https://projects.blender.org/blender/blender/pulls/112615
2023-09-22 12:13:32 +02:00
Campbell Barton 5fbcb4c27e Cleanup: remove spaces from commented arguments
Also use local enums for `MA_BM_*` in versioning code.
2023-09-22 12:21:18 +10:00
Hans Goudey 867f99c2af Cleanup: Move depsgraph headers to C++
Pull Request: https://projects.blender.org/blender/blender/pulls/110816
2023-09-22 03:18:17 +02:00
Campbell Barton 31aa6fa073 Cleanup: various non-functional C++ changes 2023-09-22 10:52:40 +10:00
Campbell Barton 6a8fc659ba Cleanup: spelling in comments 2023-09-22 10:02:05 +10:00
Hans Goudey ef5e57bbff Cleanup: Move softbody.c to C++
See #103343.

We had attempted to move the file to C++ twice before but found failing
tests each time. To find the code with changed behavior between C and
C++, I temporarily added a header declaring all the functions and moved
them one by one. The problem ended up being one function's use of `exp`
which used floats instead of doubles in C++.

Pull Request: https://projects.blender.org/blender/blender/pulls/112693
2023-09-22 00:34:17 +02:00
Sybren A. Stüvel f0c89afb76 Anim: move creation of default bone collection to the Shift+A operator
Instead of adding the default "Bones" bone collection to every Armature
data-block, only add it for Armatures that are added in the 3D View with
Shift+A > Armature.

This simplifies things like importers, which otherwise would have needed
to remove that default collection before creating the imported ones.

Additionally, this also ensures that the one bone you get by default is
actually assigned to the default bone collection.
2023-09-21 17:09:25 +02:00
Julian Eisel 998e8d0ef6 Asset shelf: Improved region height snapping behavior
Rather than always snapping the region size to the closest multiple of
the row height, remember the amount of rows displayed after the user
resized the region, and try to preserve that. This gives a lot more
predictable behavior, especially when the "Show Names" option is toggled
on and off, and the region resizes in response. With the old method the
amount of visible rows could change multiple times while toggling.

This also enables us to clamp the amount of rows (e.g. while the preview
size is increased and the region becomes too large for the area; or,
when a catalog tab is activated with fewer assets and thus fewer rows)
but still restore the amount of rows the user chose earlier, as soon as
possible.

Part of #107881.

Pull Request: https://projects.blender.org/blender/blender/pulls/112637
2023-09-21 15:08:26 +02:00
Jeroen Bakker 6d91d36161 GPU: Remove GPU_shader_storage_buffer_objects_support
Blender 4.0 requires OpenGL 4.3 which always support SSBO's.
Platforms that don't support enough SSBO bind points will be marked
as unsupported.

Users who start Blender on those platforms will be informed via a
dialog. This PR also updates the `--debug-gpu-force-workarounds`
to match our minimum requirements. Note that some bugs are still
there that should be solved in other PRs:

* Workbench only renders the object using a unit matrix this is because
  there is a bug in the workaround for shader_draw_parameters
* Navigating with middle mouse button is not working. Unsure what the
  cause is, but might be a missing feature check in the OpenGL backend.

Related to #112224

Pull Request: https://projects.blender.org/blender/blender/pulls/112572
2023-09-21 12:55:51 +02:00
Lukas Tönne b00c2f9ac4 Fix #112622: draw_color_simple is optional for custom nodes
Use magenta fallback color for sockets without a `draw_color_simple`
callback. This is not ideal, but without a context or node instance
the older `draw_color` callback can't be used.

Pull Request: https://projects.blender.org/blender/blender/pulls/112658
2023-09-21 11:25:55 +02:00
Jacques Lucke 6d75649076 Fix: assert when inserting simulation or repeat zone 2023-09-20 18:03:48 +02:00
Jacques Lucke 3eb7e453e4 Nodes: add internal node zone type
The goal is to reduce redundancy by abstracting over the different types of node
tree zones. This makes it easier to add new zone types and makes the intend of
code more clear. For example, now it is more obvious what code deals with zones
in general and what does simulation specific things.

Pull Request: https://projects.blender.org/blender/blender/pulls/112531
2023-09-20 14:40:56 +02:00
Hans Goudey 0fd0539f04 Cleanup: Rename grease pencil function to access layer at index
The plural was confusing when only one layer was returned.
2023-09-20 08:39:30 -04:00
Hans Goudey 774b9607c9 Cleanup: Resolve const correctness in grease pencil API
It was possible to access a mutable drawing from a const GreasePencil
object. This sort of mistake is possible because DNA requires using raw
pointers.
2023-09-20 08:28:08 -04:00
Campbell Barton fb81c37077 Cleanup: avoid redundant strlen calls 2023-09-20 12:11:33 +10:00
Hans Goudey a531d19b3d Cleanup: Group forward declarations at top of geometry set header 2023-09-19 13:49:04 -04:00
Iliya Katueshenock 6358c5f97c Cleanup: Support value of rotation socket
No functional changes.

Pull Request: https://projects.blender.org/blender/blender/pulls/112473
2023-09-19 19:42:55 +02:00
Julian Eisel 974d70918b RNA/BPY: Replace `asset_library_ref` with `asset_library_reference`
This is a compatibility breaking change to rename all usages of the name
`asset_library_ref` with `asset_library_reference`. Brecht recently
suggested that such abbreviations should be avoided in public API names.
2023-09-19 16:27:07 +02:00
Julian Eisel 733e4d827a Refactor: Use asset representation from context instead of asset handle
f6a6b27ac1 made the asset representation type available through context
wherever asset handle was previously. This moves us closer to replacing
the asset handle type.

Part of #102877 and #108806.
2023-09-19 15:43:56 +02:00
Julian Eisel f6a6b27ac1 Assets: Expose asset representation in context RNA/BPY
Makes the asset representation type available in RNA/BPY context
whenever the asset handle type is, so that it can be used instead. See
d04cd3f3e6. With this change we can now replace virtually all usages of
the asset handle type in Python with the asset representation. (Only for
the asset view template we require a collection property taking asset
handles still, for internal reasons.)

Idea is now to first get rid of all usages of asset handle in Python,
so that there's almost no need for further compatibility breaking
changes (unsure if the asset view template can be removed for 4.0
already though). Internal hacks related to it can be removed at any time
still.

Part of #102877 and #108806.
2023-09-19 14:40:01 +02:00
Jeroen Bakker 3a4c238d50 Command Line: Remove Disabling SSBO
Blender has the option to disable SSBO support. This was accessible
as a command line option `--debug-gpu-disable-ssbo`.

Blender 4.0 has a hard requirement for OpenGL 4.3 which includes
SSBO support by default.

This PR removes the command line option as it makes no sense to
have it anymore.

Related to #112224

Pull Request: https://projects.blender.org/blender/blender/pulls/112571
2023-09-19 14:22:32 +02:00
Lukas Tönne 78315faf8f Fix #112490: Always draw socket icons in "hidden" nodes
In #112326 the socket visibility functions were updated to take the
open/closed state of panels into account for visibility of the socket
icon. However, in "hidden" (collapsed) nodes the panels should be
ignored entirely, drawing all sockets on the root level. This requires
looking at the node flags to determine socket icon visibility, so a
simple method of `bNodeSocket` is not sufficient.

This patch moves the more complex visibility queries for sockets into
`bNode`, where both node and socket flags can be accessed. These should
be used for actual visibility rather than the plain flag accessors on
`bNodeSocket`.

Renamed `is_visible_or_panel_closed` back to just `is_visible`, the
other `is_visible` variant is now integrated in `bNode::is_socket_drawn`.

Pull Request: https://projects.blender.org/blender/blender/pulls/112520
2023-09-19 10:47:21 +02:00