Subdivision had its own store of shaders. Best to move them to
`draw_shader.cc` where all draw manager related shaders are stored.
Includes some small tweaks:
- Use enum class for shader types
- patch evaluation must now be retrieved via the
`DRW_shader_subdiv_get`. Previously there were 2 ways to retrieve
them, and one didn't support all the variations.
- Use strongly types when possible (`GPUVertCompType`).
Pull Request: https://projects.blender.org/blender/blender/pulls/134213
The cause was that the shader was expecting both `pos` and `nor`
attribute but only one would be extracted.
This is because the mesh has cage display on but the batch cache
wouldn't extract the `vbo.vnor`.
This patch just make sure the vertex normal just follow the same
condition as the other edit normals batches.
Avoid function call overhead and parallelize the creation of the edit
and sculpt mode lines index buffers. Also, remove an extra index that
was added for each curve when there are no cyclic curves.
Though ideally these index buffers would be generated on the GPU, this
simple change makes this part of the GPU data building almost 5x faster
(from 1.23 ms to 0.25 ms for curves with 80 thousand points).
Pull Request: https://projects.blender.org/blender/blender/pulls/133897
The Indices Overlay used a blue color without shadow to render the
indices in edit mode unlike the Attribute Viewer which uses white text
with shadow. So for consistency, the Indices Overlay has been changed
to use the same style.
Pull Request: https://projects.blender.org/blender/blender/pulls/133262
The core issue was that the geometry batch cache (e.g. `MeshBatchCache` or
`PointCloudBatchCache`) was dependent on the object. This is problematic when
the the same geometry is used with multiple different objects because the cache
can't be consistent with all of them.
Fortunately, the only thing that was retrieved from the object was the number of
material slots, so if that can be avoided we should be fine. We can't just use
the number of material slots stored on the geometry because that may have no
material slots but still has material indices which are overridden on the object
level.
The solution is to take make the number of materials for a geometry only
dependent on the actual `material_index` attribute and not on the number of
available slots. More specifically, we find the maximal referenced material
index and handle that many materials. This number does not depend on how many
material slots there are on the object, but it still allows the object to
override materials slots that the mesh references.
A downside is that the maximum material index has to be computed which often
requires an iteration over the mesh. Fortunately, we can cache that quite easily
and the computation can be done in parallel. Also we are probably able to
eagerly update the material index in many cases when it's set instead of
computing it lazily. That is not implemented in this patch though.
The largest part of the patch is making the maximal material index easily
available on all the geometry types. Besides that, the material API is slightly
replaced and the drawing code now makes use of the updated API.
Pull Request: https://projects.blender.org/blender/blender/pulls/133498
This add back the NDC offset that was present in the legacy overlay.
But instead of adding a new view for it, we add `ndc_offset_factor`
to `State` to simplify wire offseting
Instead of modifying the projection matrix, we compute the unit
offset and pass it to the shader which choose the appropriate
factor to apply to the vertex position.
The value is put inside `State` so that it can be referenced
easily by multiple overlays.
Later on (once we move the global UBO inside Overlay) we can
move this to a UBO.
This only implements it for wireframe and edit mesh vert and
edges.
Note: that there seems to be some code duplication with the
edit mesh vertex code. That's to be tackled in another commit.
Pull Request: https://projects.blender.org/blender/blender/pulls/133433
Especially through DRW_render.hh, there were a lot of unnecessary
includes almost everywhere in the module. This typically makes
dependencies less explicit and slows down compile times, so switch
to including what files actual use.
Pull Request: https://projects.blender.org/blender/blender/pulls/133450
Prevents creation of Bezier curve's `IndexMask` when it is not needed.
It was created on every request, even when `CurvesBatchCache` was valid.
Also prevents redundant initialization of `GeometryDeformation`.
Pull Request: https://projects.blender.org/blender/blender/pulls/133017
This creates more boilerplate code, but it's easier to extend,
it's follows the same structure as the mesh extraction, and
it's more aligned to planned future performance improvements.
Pull Request: https://projects.blender.org/blender/blender/pulls/132866
The material index in Grease Pencil attributes can be negative, since they are a
generic attribute. The shader, however, requires clamping of the material index
to avoid an invalid lookup. This was already happening for the material buffer
setup (`grease_pencil_object_cache_populate`), but not for the actual VBO.
Fixes#131670
Pull Request: https://projects.blender.org/blender/blender/pulls/132804
UnitSettings::scale_length was used to scale reported
values for operators (translate, shrink-fatten, voxel-size).
This isn't expected as the value isn't editable when the unit-system
is set to None.
Add BKE_unit_value_as_string_scaled utility function for clarity &
to ensure scaling is only applied when it should be.
When using clangd or running clang-tidy on headers there are
currently many errors. These are noisy in IDEs, make auto fixes
impossible, and break features like code completion, refactoring
and navigation.
This makes source/blender headers work by themselves, which is
generally the goal anyway. But #includes and forward declarations
were often incomplete.
* Add #includes and forward declarations
* Add IWYU pragma: export in a few places
* Remove some unused #includes (but there are many more)
* Tweak ShaderCreateInfo macros to work better with clangd
Some types of headers still have errors, these could be fixed or
worked around with more investigation. Mostly preprocessor
template headers like NOD_static_types.h.
Note that that disabling WITH_UNITY_BUILD is required for clangd to
work properly, otherwise compile_commands.json does not contain
the information for the relevant source files.
For more details see the developer docs:
https://developer.blender.org/docs/handbook/tooling/clangd/
Pull Request: https://projects.blender.org/blender/blender/pulls/132608
Mistak in 39f7c506b5.
The VBOs need to be allocated! And we can just use a single dummy
type as well, rather than using the type from the attribute request
which is meaningless in this case.
With the goal of removing the type and custom data domain from
the attribute requests, tweak the order of the calls to ensure that
each vertex buffer is allocated until after we know about the source
mesh data format. After that, it makes more sense to have the loop
over BVH nodes inside each extraction function.
Pull Request: https://projects.blender.org/blender/blender/pulls/132467
Geometry instances shouldn't be drawn with cage overlays or other
edit mode overlays since they don't necessarily correspond to original
data. In this case the draw manager thought they were in edit mode
because the object data is copied from the instance parent-- we need
_some_ object for rendering.
Pull Request: https://projects.blender.org/blender/blender/pulls/132081
Caused by 839108f623.
The edit mapping was invalid so we just created a dummy GPU
batch for the selection edit data. But it was invalid because we
weren't in edit mode. The fix just requires tweaking the checks
for this data that's also used outside of edit mode.
Previously, the number of material slots on the geometry (e.g. mesh) was the
ground truth. However, this had limitations in the case when the object had more
material slots than the evaluated geometry. All extra slots on the object were
ignored.
This patch changes the definition so that the number of materials used for
rendering is the maximum of the number of material slots on the geometry and on
the object. This also implies that one always needs a reference to an object
when determining that number, but that was fairly straight forward to achieve in
current code.
This patch also cleans up the material count handling a fair amount by using the
`BKE_object_material_*_eval` API more consistently instead of manually accessing
`totcol`. Cycles uses the the same API indirectly through RNA.
Pull Request: https://projects.blender.org/blender/blender/pulls/131869