Commit Graph

3674 Commits

Author SHA1 Message Date
Harley Acheson
92e0545e9f UI: Remove BLF_draw_default_shadowed
With Aras's recent changes in #121383, our text shader now supports
outline shadows, which gives a result that has more contrast than can
be achieved with BLF_draw_default_shadowed. This removes that function.

Pull Request: https://projects.blender.org/blender/blender/pulls/121676
2024-05-13 22:32:59 +02:00
Clément Foucault
b76960673f Fix: DRW: Thread safety in pointcloud IBO builder
`GPU_indexbuf_add_tri_verts` is not threadsafe.
Use direct memory access.

Also cleanup to increase code clarity.
2024-05-11 15:40:44 +02:00
Clément Foucault
73a496121b DRW: PointCloud: Multithread index buffer creation 2024-05-11 14:00:28 +02:00
Clément Foucault
41b0e11839 DRW: Reduce number of bits used to store shape indice
Fix #108901
2024-05-11 14:00:28 +02:00
Aras Pranckevicius
3582e52f9c UI: Improved overlay text contrast with new outline text decoration
Overlay texts were previously drawn with two sets of shadows:
- 3px blur,
- 5px blur, slightly offset

But since the shadow color was always set to black, it was still
causing legibility issues when the text itself was dark (set
via theme for example).

This PR adds a new "outline" BLF text decoration, and uses that
for the overlays. And it picks text/outline color depending
on the "background" color of the view.

Details:

- Instead of "shadow level" integer where the only valid options
  are 0, 3 or 5, have a FontShadowType enum.
- Add a new FontShadowType::Outline enum entry, that does a 1px
  outline by doing a 3x3 dilation in the font shader.
- BLF_draw_default_shadowed is changed to do outline, instead of
  drawing the shadow twice.
- In the font shader, instead of encoding shadow type in signs of
  the glyph_size, pass that as a "flags" vertex attribute. Put
  font texture channel count into the same flags, so that the
  vertex size stays the same.
- Well actually, vertex size becomes smaller by 4 bytes, since turns
  out glyph_mode vertex attribute was not used for anything at all.

Images in the PR.

Co-authored-by: Harley Acheson <harley.acheson@gmail.com>
Pull Request: https://projects.blender.org/blender/blender/pulls/121383
2024-05-10 21:06:44 +02:00
Clément Foucault
07e78f613b DRW: Avoid rendering objects with invalid bounds in disabled views
Fix #114752
2024-05-10 13:03:05 +02:00
Clément Foucault
b02ccbca9b DRW: Fix drw_print on metal
Metal doesn't use the same Y direction for the
point coordinate. Since this is only used for this
shader, do a local fix.
2024-05-09 12:46:29 +02:00
Falk David
737572ed88 Cleanup: GPv3: Use GreasePencil::layer function instead of GreasePencil::layers
This also ensures that there is an assert that checks
for valid indices before accessing the span of layers.
2024-05-08 12:35:06 +02:00
Hans Goudey
c4051c3216 Fix #121347: GPU subdivision loose edges hidden with no non-loose edges
There was an incorrect early return in 1b7e67a851.
2024-05-07 14:07:30 -04:00
Hans Goudey
1210a53c6d Fix #121503: Loose edges lines index buffer crash
The array used to not set the data for an edge multiple times
was the wrong size.
2024-05-07 13:18:52 -04:00
Iliya Katueshenock
4e3af58885 Cleanup: Avoid unnecessary copies of VArray
Cleanup to avoid unnecessary copies of VArray. This
requires ref-qualifier overloads of dereference operator
of attribute reader and some move operators and constructor
overloads in the code.

Pull Request: https://projects.blender.org/blender/blender/pulls/118437
2024-05-07 04:02:17 +02:00
Campbell Barton
9918488bb1 Cleanup: use uppercase tags, following own style guide 2024-05-03 11:33:21 +10:00
Hans Goudey
bc5f5d9a6c Cleanup: Use reference and rename mesh buffer list variable 2024-04-30 14:23:13 -04:00
Hans Goudey
6c2593cc13 Fix: EEVEE render crash after recent mesh index buffer commit
Caused by 1b7e67a851.
The GPU subdivision extraction was missing the check for whether
neither lines nor lines_loose was requested.
2024-04-30 14:18:28 -04:00
Miguel Pozo
a8f8745dcb Draw: Add default material fallback detection
Detect passes that are functionally equivalent to the default Material
ones to skip their compilation.

Pull Request: https://projects.blender.org/blender/blender/pulls/121137
2024-04-30 19:44:06 +02:00
Hans Goudey
f4bf30c224 Cleanup: Tweak comment and indentation in mesh IBO extraction 2024-04-30 13:03:26 -04:00
Hans Goudey
7799c04cf6 Cleanup: Use const BMesh pointer 2024-04-30 13:03:26 -04:00
Hans Goudey
19cdef03e2 BLI: Add IndexMask::from_bools_inverse utility 2024-04-30 13:03:26 -04:00
Hans Goudey
71df15de04 Fix #121265: Normals of faceless vertices are not displayed
Caused by bace4c9a29 which only
extracted normals at face corners. Solve by also extracting loose edge and
loose vertex normals. And change the BMesh extraction to not use the
face iteration of the MeshExtract system, just because that's simpler.
2024-04-30 13:03:26 -04:00
Hans Goudey
1b7e67a851 Mesh: Lines index buffer creation improvement
Implements another phase of #116901, this time for the `lines` and
`lines_loose` index buffers that store indices for wireframe drawing.
The key improvement is removing loose edge's dependency on the main
edge index buffer. That means for the majority of meshes with no loose
edges, edge index extraction can be completely skipped. Even when there
are loose edges, only the loose edges need to be extracted with
wireframe turned off.

Besides that improvement, there are more changes to use data-oriented
code with visible hot loops instead of the virtual function call design
used for the existing mesh extractor system. For this step I completely
replaced the `extract_lines` object, which is in line with the general
plan for this area.

Additionally, hidden edge filtering is done ahead of time using several
`IndexMask` operations. This means only indices for visible edges need
to be uploaded to the GPU, and no restart index stripping needs to be
performed on macOS.

On my usual test file with 1.9 million vertices, I observed an
improvement from 26 to 33 FPS with wireframe off, and from 9.15 to 9.5
FPS with wireframe on.

Pull Request: https://projects.blender.org/blender/blender/pulls/120720
2024-04-30 15:54:50 +02:00
Hans Goudey
76a151b9d6 Refactor: Store PBVH in unique_ptr
This requires adding a destructor and deleting move and copy assignment
for SculptSession, because (for now at least) we want to keep the PBVH
as an opaque type (though with one exception for including pbvh_intern.hh
in paint.cc for the SculptSession destructor).

Pull Request: https://projects.blender.org/blender/blender/pulls/121227
2024-04-29 22:21:24 +02:00
Hans Goudey
7c56e16e44 Cleanup: Use references for sculpt PBVH variables 2024-04-29 22:21:23 +02:00
Clément Foucault
e401d996aa Fix: EEVEE-Next: Wrong LOD tagging for punctual shadow maps
The root issue is that `shadow_punctual_footprint_ratio` was not
fed with Z distance but by radial distances to camera and
light.

This commit cleans up this computation by only precomputing the
film pixel radius on CPU. This allow the LOD computation to be
more local and easier to read.

Fix #119725

Pull Request: https://projects.blender.org/blender/blender/pulls/121167
2024-04-29 15:19:49 +02:00
Clément Foucault
4d10bbe733 Fix: EEVEE-Next: Missing smoke volumes
Caused by mistake in b8e17cf531.
2024-04-26 13:13:27 +02:00
Falk David
c2504eb779 Cleanup: Use legacy radius conversion factor constant
This moves the seemingly arbitrary value of  "1 / 2000"
into a constant variable
(`bke::greasepencil::LEGACY_RADIUS_CONVERSION_FACTOR`)
so that it can be used in all the places where
legacy "thickness" values need to be converted.
This also expands the explanation of the factor a bit, so it's
clearer why it is needed.
2024-04-26 12:48:26 +02:00
Clément Foucault
b8e17cf531 Fix: EEVEE-Next: Missing fluid volume domain rendering
This was an oversight in the implementation of the new
volume drw API. Now fill up dummy attributes and allow
rendering of the fluid domains.
2024-04-24 17:06:55 +02:00
Sietse Brouwer
7b3e063704 GPv3: Overlay for Weight Paint mode
This PR implements the viewport overlay for Weight Paint mode in GPv3.

In Weight Paint mode the stroke points are colored depending on their
weights in the active vertex group.

Pull Request: https://projects.blender.org/blender/blender/pulls/118273
2024-04-23 18:23:38 +02:00
Clément Foucault
8d740b6ea3 Cleanup: DRW: Remove unused legacy function 2024-04-22 23:23:04 +02:00
Hans Goudey
cb639d5d1d Cleanup: Rename "is_mode_active" to "edit_mode_active"
"is_mode_active" doesn't really make sense because some mode
is always active technically. This always referred to edit mode anyway.
2024-04-22 15:31:55 -04:00
Clément Foucault
3182ce2393 DRW: Add asserts for nullptr binding
These will crash at submission time anyway and will
be hard to track back to the actual resource causing
the issue. Better fail earlier.
2024-04-22 15:26:48 +02:00
Jeroen Bakker
0c2085a316 GPU: Remove GPU_compute_shader_support
Compute shaders are required since 4.0. There was one occasion where
an older AMD driver failed and support was turned off. This driver
is now marked unsupported.

This PR includes:
- removing the check in viewport compositing
- remove properties from system info
- always construct draw manager.
- remove unused pass logic in draw hair/curves
- add deprecation warning when accessed from python

Pull Request: https://projects.blender.org/blender/blender/pulls/120909
2024-04-22 13:28:10 +02:00
Jacques Lucke
1ad633187e Fix #120805: crash when using multiple curves attributes in shader
Currently, `cache.eval_cache.final.attributes_buf[i] != nullptr` is used as
high level check to see if attributes need to be recomputed. However, this
buffer was not freed when a related buffer was freed that has to be
recomputed.
2024-04-22 09:39:30 +02:00
Hans Goudey
11f0d88d13 Subdiv: Move most blenkernel subdiv code to C++ namespace
Move most code to `blender::bke::subdiv`. That helps organization
and makes using C++ in subdiv code easier, which will be useful for
removing the unnecessary opensubdiv C-API wrapper.
2024-04-19 09:03:31 -04:00
Hans Goudey
d95b1f120b Mesh: Store BMEditMesh in shared pointer
The main motivation for this is that it's part of a fix for #113377,
where I want to propagate the edit mesh pointers through copied
meshes in modifiers and geometry nodes, instead of just setting the
edit mesh pointer at the end of the modifier stack. That would have
two main benefits:
1. We avoid the need to write to the evaluated mesh, after evaluation
  which means it can be shared directly among evaluated objects.
2. When an object's mesh is completely replaced by the mesh from another
   object during evaluation (with the object info node), the final edit
   mesh pointer will not be "wrong", allowing us to skip index-mapped
   GPU data extraction.

Beyond that, using a shared pointer just makes things more automatic.
Handling of edit mesh data is already complicated enough, this way some
of the worry and complexity can be handled by RAII.

One thing to keep in mind is that the edit mesh's BMesh is still freed
manually with `EDBM_mesh_free_data` when leaving edit mode. I figured
that was a more conservative approach for now. Maybe eventually that
could be handled automatically with RAII too.

Pull Request: https://projects.blender.org/blender/blender/pulls/120276
2024-04-18 13:52:20 +02:00
Clément Foucault
f2ae04db10 GPU: Implement missing UBO/SSBO bind tracking
This PR adds a context function to consider all
buffer bindings obsolete. This is in order to
track missing binds and invalid lingering states
accross `draw::Pass`es.

The functions `GPU_storagebuf_debug_unbind_all`
and `GPU_uniformbuf_debug_unbind_all` do nothing
more than resetting the internal debug slot bits
to zero. This is what OpenGL backend does as it
doesn't track the bindings themselves.

Other backends might have other way to detect
missing bindings. If not they should be
implemented separately anyway.

I renamed the function to `debug_unbind_all` to
denote that it actually does something related to
debugging.

This also add SSBO binding check for OpenGL as it
was also missing.

#### Future

This error checking logic is pretty much backend
agnostic. While it would be nice to move it at
`gpu::Context` level, we don't have the resources
for that now.

Pull Request: https://projects.blender.org/blender/blender/pulls/120716
2024-04-17 11:06:39 +02:00
Campbell Barton
f8197098c6 Cleanup: spelling in comments 2024-04-17 14:18:33 +10:00
Clément Foucault
5b1f5a5aa7 Cleanup: DRW: Remove uneeded dependency of debug shaders on draw_view
This fix a missing bind error for the debug draw
and print shaders.
2024-04-16 19:47:39 +02:00
Miguel Pozo
cec57e9138 Fix: Draw: EEVEE-Next shadow flickering and other uninitialized bounds fixes
Always check if the DrawManager ObjectBounds are valid.
Initialized invalid bounds to NaN in debug builds for easier debugging.

Pull Request: https://projects.blender.org/blender/blender/pulls/120591
2024-04-16 17:19:13 +02:00
Germano Cavalcante
5b7bc88571 Revert "Refactor: Select Engine: Draw actual indices instead of 'Original Indices'"
This reverts commit 157c4cfbc1.

Functions like `DRW_select_buffer_bitmap_from_circle` and
`DRW_select_buffer_bitmap_from_poly` need to be adapted too.
2024-04-16 10:22:52 -03:00
Germano Cavalcante
157c4cfbc1 Refactor: Select Engine: Draw actual indices instead of 'Original Indices'
The selection engine renders `uint` texture where each element of the
geometry is represented as an index.

When the geometry have modifiers, the original index was used for the
texture.

However this is not necessary for the select engine to work. The real
mesh indexes can be used in the texture and, only at the end, the
original index can be retrieved on the CPU itself.

Advantages of this approach:
- Optimizes the code to generate selection buffers.
- Makes the select id texture more informative as it identifies the
  real elements instead of the original ones.

Pull Request: https://projects.blender.org/blender/blender/pulls/119977
2024-04-16 14:58:01 +02:00
Campbell Barton
49bf7ebbdd Cleanup: use const args & variables, remove redundant checks
- Declare const variables & arguments.
- Remove redundant null checks.
- Remove break after return.
- Replace suspicious "&" with "&&".
2024-04-15 09:50:47 +10:00
Hans Goudey
5c10f9fcb3 Fix #120549: Broken triangles in viewport with multiple materials
Error in 0f46e02310

The maximum index in the triangles index buffer was set incorrectly,
causing the GPU code to switch to using 16 bit integers when it shouldn't.
2024-04-12 12:38:25 -04:00
Falk David
f9499d71f0 Fix: GPv3: Use fill opacities in batch cache
The `fill_opacity` attribute was used (e.g. by the opacity modifier)
but not added in the batch cache for rendering.
This fixes the issue.
2024-04-12 17:42:42 +02:00
Falk David
196954dc66 Fix #120559: GPv3: Rendering issue if single point curve is set to cyclic
Caused by ca0b02aa96.
The `points.size() > 1` was added because we can't access
`lengths[points.size() - 1]` if the curve has a single point.
The fix just makes sure we default to a `u` value of `0.0f`
for single point cyclic curves.

Pull Request: https://projects.blender.org/blender/blender/pulls/120565
2024-04-12 13:19:53 +02:00
Jeroen Bakker
9c1cba528b OpenGL: Remove Apple specific workarounds
This PR removes apple specific OpenGL workarounds. OpenGL on Apple isn't supported
so they can be removed.

Pull Request: https://projects.blender.org/blender/blender/pulls/120522
2024-04-11 17:25:21 +02:00
Hans Goudey
0f46e02310 Mesh: Draw triangle index buffer creation improvements
This PR is another step in the refactor described by #116901.
This change applies to the triangle index buffer. The main improvement
is the ability to recognize when the mesh corner triangles index array
can be uploaded directly (when there is a single material and no hidden
faces). In that case the index data should be copied directly to the
GPU rather than to a temporary array owned by the IBO first. Though
that isn't implemented yet since it will be handled by the GPU module
later, the code is now structured to make that change simple from the
data extraction perspective.

Other than that, the main change is to not use the extractor iterator
framework anymore, and to set index data directly instead of using GPU
API functions. Though we're mainly bottlenecked by memory-bandwidth
anyway, it's nice to avoid function call overhead.

We also now avoid creating the array of sorted triangle indices when
there is a single material and no hidden faces. And we don't use
restart indices for the single-material case anymore. For Metal that's
nice because we can avoid `strip_restart_indices`.

I didn't notice significant performance improvements in my test files
beyond a few percent here and there. With a hacked implementation of
the copy-directly-to-the-gpu optimization, I did see more consistent
improvements though.

Pull Request: https://projects.blender.org/blender/blender/pulls/119130
2024-04-11 04:49:27 +02:00
Hans Goudey
48f77b6c24 Fix #120313: Paint mode vertex selection overlay skips vertices
Before bace4c9a29, the selection was uploaded twice: both face
and vertex selection. Afterwards only the face selection was uploaded,
but the vertex selection is necessary for the paint mode vertex overlay.
Now choose between uploading the vertex or face attribute based on the
paint overlay flags.
2024-04-10 14:22:42 -04:00
Campbell Barton
74a65d77cc Cleanup: spelling in comments 2024-04-10 12:28:33 +10:00
Falk David
eec9c50580 Fix #120436: "Show Fill Color" setting not working
The flag was completly unused in the code.
Now this flag does what it says: While drawing,
the fill color is (almost) not visible.

Pull Request: https://projects.blender.org/blender/blender/pulls/120438
2024-04-09 17:59:20 +02:00
Falk David
d7230516c1 Cleanup: GPv3: Add drawing API for fill color
This adds two functions to the `Drawing` class: `fill_colors()`
and `fill_colors_for_write()`.
In places where the attribute API was used directly, these
functions are now used instead.

This is part of #119080. The point is that developers
shouldn't need to remember the name, type, default value,
and domain of built-in attributes (e.g. used by the renderer).

Pull Request: https://projects.blender.org/blender/blender/pulls/120296
2024-04-05 15:28:28 +02:00