Commit Graph

125 Commits

Author SHA1 Message Date
Campbell Barton 14b2a35c8b Cleanup: use parenthesis for if statements in macros 2020-09-19 16:28:17 +10:00
Sebastian Parborg 2115232a16 Cleanup: Clang-Tidy readability-inconsistent-declaration-parameter-name fix
No functional changes
2020-09-04 21:04:16 +02:00
Jacques Lucke 91694b9b58 Code Style: use "#pragma once" in source directory
This replaces header include guards with `#pragma once`.
A couple of include guards are not removed yet (e.g. `__RNA_TYPES_H__`),
because they are used in other places.

This patch has been generated by P1561 followed by `make format`.

Differential Revision: https://developer.blender.org/D8466
2020-08-07 09:50:34 +02:00
Jacques Lucke 725973485a Clang Tidy: enable readability-non-const-parameter warning
Clang Tidy reported a couple of false positives. I disabled
those `NOLINTNEXTLINE`.

Differential Revision: https://developer.blender.org/D8199
2020-07-13 11:27:09 +02:00
Pablo Dobarro 78b629a98f Sculpt: Skip fully hidden nodes in sculpt tools
As tools iterators skip not visible vertices, fully hidden nodes can
also be skipped and considered as masked.

Reviewed By: sergey

Differential Revision: https://developer.blender.org/D8244
2020-07-09 17:51:09 +02:00
Pablo Dobarro f7bbc7cdbb Sculpt Vertex Colors: Initial implementation
Sculpt Vertex Colors is a painting system that runs inside sculpt mode, reusing all its tools and optimizations. This provides much better performance, easier to maintain code and more advanced features (new brush engine, filters, symmetry options, masks and face sets compatibility...). This is also the initial step for future features like vertex painting in Multires and brushes that can sculpt and paint at the same time.

This commit includes:
  - SCULPT_UNDO_COLOR for undo support in sculpt mode
  - SCULPT_UPDATE_COLOR and PBVH flags and rendering
  - Sculpt Color API functions
  - Sculpt capability for sculpt tools (only enabled in the Paint Brush for now)
  - Rendering support in workbench (default to Sculpt Vertex Colors except in Vertex Paint)
  - Conversion operator between MPropCol (Sculpt Vertex Colors) and MLoopCol (Vertex Paint)
  - Remesher reprojection in the Voxel Remehser
  - Paint Brush and Smear Brush with color smoothing in alt-smooth mode
  - Parameters for the new brush engine (density, opacity, flow, wet paint mixing, tip scale) implemented in Sculpt Vertex Colors
  - Color Filter
  - Color picker (uses S shortcut, replaces smooth)
  - Color selector in the top bar

Reviewed By: brecht

Maniphest Tasks: T72866

Differential Revision: https://developer.blender.org/D5975
2020-06-23 16:28:50 +02:00
Pablo Dobarro 85098bdb89 Fix T76776: Implement vertex_visibility_get for PBVH_GRIDS
This was missing from when Face Sets were enabled in Multires, so it was
always considering that all vertices in the grids are visible. This
should also fix other unreported bugs.

Reviewed By: sergey

Maniphest Tasks: T76776

Differential Revision: https://developer.blender.org/D7809
2020-06-02 20:52:46 +02:00
Pablo Dobarro 572c472754 Cleanup: Always use pbvh in PBVH BKE files
Reviewed By: sergey

Differential Revision: https://developer.blender.org/D7889
2020-06-02 19:40:08 +02:00
Philipp Oeser 325307d82b Merge branch 'blender-v2.83-release' 2020-05-19 13:59:39 +02:00
Campbell Barton b96ccb5126 Fix T76865: Vertex paint draws hidden but cannot be painted onto 2020-05-19 18:06:27 +10:00
Jeroen Bakker 236794d07a Merge branch 'blender-v2.83-release' 2020-05-14 14:30:34 +02:00
Jeroen Bakker 7d38f50367 Fix T75908: Sculpt GPU Batches + Render Artifacts
When sculpting the GPU batches are constructed with only the required data
for a single viewport. When that viewport changes shading or coloring mode (object
to vertex) batches might not hold all the needed information.

There is also a case when you have two 3d viewport one in object color
mode and the other in vertex color mode that the GPU batches were
updated without any vertex colors.

In order to fix these category of issues this patch would always
construct the full GPU batches for sculpting.

Reviewed By: Clément Foucault, Pablo Dobarro

Maniphest Tasks: T75908

Differential Revision: https://developer.blender.org/D7701
2020-05-14 11:58:33 +02:00
Campbell Barton d388c1c524 Cleanup: sort file lists 2020-05-03 13:45:40 +10:00
Brecht Van Lommel d8a3f3595a Task: Use TBB as Task Scheduler
This patch enables TBB as the default task scheduler. TBB stands for Threading Building Blocks and is developed by Intel. The library contains several threading patters. This patch maps blenders BLI_task_* function to their counterpart. After this patch we can add more patterns. A promising one is TBB:graph that can be used for depsgraph, draw manager and compositor.

Performance changes depends on the actual hardware. It was tested on different hardwares from laptops to workstations and we didn't detected any downgrade of the performance.
* Linux Xeon E5-2699 v4 got FPS boost from 12 to 17 using Spring's 04_010_A.anim.blend.
* AMD Ryzen Threadripper 2990WX 32-Core Animation playback goes from 9.5-10.5 FPS to 13.0-14.0 FPS on Agent 327 , 10_03_B.anim.blend.

Reviewed By: brecht, sergey

Differential Revision: https://developer.blender.org/D7475
2020-04-30 08:09:21 +02:00
Pablo Dobarro 47f46637be Sculpt: New Layer Brush
The Layer brush was in Blender before 2.81, when the sculpt API was
introduced. It had a huge amount of bugs and glitches which made it
almost unusable for anything but the most trivial cases. Also, it needed
some hacks in the code just to support the persistent base.

The brush was completely rewritten using the Sculpt API. It fulfills the
same use case as the old one, but it has:
- All previous artifacts fixed
- Simpler code
- Persistent base now works with multires thanks to the sculpt API
- Small cursor widget to preview the layer height
- More controllable and smoother strength and deformation
- More correct masking support
- More predictable invert support. When using persistent base, the brush invert mode resets to layer height 0, instead of jumping from +1 to -1. The brush can still be inverted in the brush direction property.

Reviewed By: jbakker

Differential Revision: https://developer.blender.org/D7147
2020-04-14 21:07:29 +02:00
Pablo Dobarro b8d9b5e331 Sculpt: Delay Viewport Updates
In Blender 2.81 we update and draw all nodes inside the view planes.
When navigating with a pen tablet after an operation that tags the whole
mesh to update (like undo or inverting the mask), this introduces some
lag as nodes are updating when they enter the view. The viewport is not
fully responsive again until all nodes have entered the view after the
operation.

This commit delays nodes updates until the view navigation stops, so the
viewport navigation is always fully responsive. This introduces some
artifacts while navigating,  so it can be disabled if you don't want to
see them.

I'm storing the update planes in the PBVH. This way I can add support
for some tools to update in real-time only the nodes inside this plane
while running the operator, like the mesh filter.

Reviewed By: jbakker

Differential Revision: https://developer.blender.org/D6269
2020-04-02 18:00:51 +02:00
Pablo Dobarro 009dde69cd Fix Face Sets painting and selection precision
This fixes the following issues:
- Previously, the face set from the active vertex was used directly. Vertices always return the most recently created face set, so in some cases there may be some face sets that were not possible to select as active. Now the active face set is set in the ray intersection, so it always matches the face under the cursor.
- When drawing face sets they were set per vertex, so it was not possible to paint one face at a time. Now face sets are painted per poly when using the brush on meshes, testing the distance to the center of each poly.
- The code for the active vertex on PBVH_GRIDS was not correct, so I also fixed that to test if everything was working correctly.
{F8441699}

Reviewed By: jbakker

Differential Revision: https://developer.blender.org/D7303
2020-04-02 15:43:37 +02:00
Pablo Dobarro da3cb514e5 Multires: Initial Face Sets support
This implements the Sculpt Mode API functions needed for Face Sets and
visibility management for PBVH_GRIDS. No major changes were needed in
the operators and the sculpt mode code. This implementation stores the
face sets in the base mesh, so faces created in higher subdivision
levels can't be modified individually. Also, we are not checking for
multiple face sets per vertex (that can be added in the future), so
relax tools don't work yet. The rest of the features (paint, undo,
visibility operators..) work as expected.

Reviewed By: brecht

Differential Revision: https://developer.blender.org/D7168
2020-04-01 01:07:47 +02:00
Pablo Dobarro 18e3615a68 Face Sets: Use white color for a default Face Set to enable the overlay
This introduces a variable to store a face set ID which is going to be
rendered white. When initializing a mesh or randomizing the colors, this
variable gets updated to always render a white face set. This way the
face set overlay can be enabled without adding colors to the mesh if
face sets are not in use. After creating the first face set, new colors
are generated randomly like usual.

The face set stored as default does not have any special meaning for
tools or brushes, it just affects the rendering color.

Reviewed By: brecht

Differential Revision: https://developer.blender.org/D7035
2020-03-09 20:11:18 +01:00
Pablo Dobarro 38d6533f21 Sculpt Face Sets
Face Sets are the new system to control the visibility state of the mesh in sculpt and paint modes. They are designed to work in modes where brushes are the primary way of interaction and they provide much more control when working with meshes with complex shapes and overlapping surfaces.

This initial commit includes:
- Sculpt Face Sets data structures and PBVH rendering.
- Face Set overlay and opacity controls.
- Sculpt Undo support.
- Remesher reprojection support. The visibility state of the mesh is also preserved when remeshing.
- Automasking and Mesh filter support.
- Mask expand operator mode to expand Face Sets (Shift + W) and flood fill areas by connectivity (press Ctrl while expanding).
- Sculpt Mode Face Sets and Visibility API.
- Sculpt Face Sets creation and visibility management operators.
- Operator to randomize the Face Sets colors.
- Draw Face Sets brush tool to create and edit the Face Sets. Drawing on the mesh creates a new Face Set. Pressing Ctrl before drawing modifies the Face Set under the brush at the beginning of the stroke.
- Updated keymap and menu to work with Face Sets from Sculpt Mode (H to toggle visibility, Alt + H to show all, Shit + H to hide).
- Pie menu on the W key with Face common Sets operations.

Know limitations:
- Multires support. The Face Sets and Visibility API needs to be implemented for Multires.

Reviewed By: jbakker, #user_interface, Severin

Differential Revision: https://developer.blender.org/D6070
2020-03-05 21:07:20 +01:00
Pablo Dobarro 793135e190 Fix wrong coordinates being read when using the sculpt API
The coordinates should be read from the PBVH when using deform modifiers.
This is needed for the cloth brush to work with subdivisions, as it reads the
vertex coordinates using this function when building and updating the
constraints.

Reviewed By: jbakker

Differential Revision: https://developer.blender.org/D6967
2020-02-28 16:53:34 +01:00
Pablo Dobarro f4411b58ad Fix T72721: Add visibility flags updates to the PBVH
Currently, there its a function that sets manually the fully_hidden flag
of the nodes from the visibility operators in paint_hide.c. The undo
code was not updating the flag, so the visibility state of the nodes was
incorrect after preforming undo operations. This sometimes was drawing
fully hidden nodes with empty buffers, causing artifacts in the
geometry.

I added a function to mark nodes which visibility state changed (similar
as we are updating the mask flags and the nodes bounding boxes). This
way, the tools, operators and undo code don't have to update the
visibility flags, making everything much simpler to understand and
maintain.

I did not remove the flag update code from the current visibility
operators in this patch, but after reimplementing them (and all the new
ones) in the new visibility system, all visibility updates should be
done using this method and the BKE_pbvh_node_fully_hidden_set function
should be removed.

Reviewed By: jbakker

Maniphest Tasks: T72721

Differential Revision: https://developer.blender.org/D6767
2020-02-25 19:07:44 +01:00
Campbell Barton 1ef6be3686 Cleanup: redundant struct declarations 2019-12-17 10:15:22 +11:00
Campbell Barton f4d7d5e75d Cleanup: sort struct declarations 2019-12-17 10:08:47 +11:00
Campbell Barton e9d7fddeb4 Fix dyntopo sculpt not setting vertex indices dirty
This is an old bug exposed by new cursor drawing
which uses vertex indices.
2019-11-08 12:13:23 +11:00
Brecht Van Lommel 6c302d6529 Sculpt: use TBB instead of BLI_task for multithreading
This solves performance issues on some computers where there is significant
threading overhead. Rather than doing the complicated work of optimizing our
own task scheduler, use TBB which appears to work well. The downside is that
we have another thread pool, but it is already there when using OpenVDB voxel
remesh.

For future releases we can switch to using TBB to replace our task scheduler
implementation entirely, and use the same thread pool for BLI_task, Cycles,
Mantaflow, etc.

Differential Revision: https://developer.blender.org/D6030
2019-10-10 17:36:12 +02:00
Pablo Dobarro d95bb087d0 Sculpt: Fix wireframe drawing
With this commit sculpt mode draws the real mesh wireframe instead of the
triangulated version by ignoring non real edges when building the PBVH GPU buffers

Reviewed By: brecht

Differential Revision: https://developer.blender.org/D6032
2019-10-09 21:23:11 +02:00
Brecht Van Lommel 2090b3e5ac Cleanup: internal sculpt refactoring related to multires, no user visible changes 2019-10-01 16:10:38 +02:00
Brecht Van Lommel 6b3887da4d Cleanup: slightly more efficient access to PBVH multires grid key 2019-10-01 16:10:38 +02:00
Pablo Dobarro e8f6f70846 PBVH: PBVH_FullyMasked and PBVH_FullyUnmasked flags
This commit introduces flags to tag the PBVH nodes as fully masked or unmasked. This is used in do_brush_actions to filter fully masked nodes during a stroke. Other tools can also be updated to use this flags.
Sculpt updates now require a flag to update the mask or the vertex coordinates.

Reviewed By: brecht

Differential Revision: https://developer.blender.org/D5935
2019-09-30 15:58:03 +02:00
Brecht Van Lommel 9b0fd5ef2a Sculpt: only update draw buffers for visible nodes during paint stroke
Also applies to some other sculpt tools like filter and mask expand.

The full update happens after the paint stroke is finished, so it does not
happen on view navigation, which would cause a delay.

Ref T70295

Differential Revision: https://developer.blender.org/D5922
2019-09-29 16:22:09 +02:00
Brecht Van Lommel f6fc863acd Sculpt: multithread GPU draw buffer filling for workbench
This improves performance of some sculpt tools, particularly those that modify
many vertices like filter and mask tools, or use brushes with large radius.

For mask expand it can make updates up to 2x faster on heavy meshes, but for
most tools it's more on the order of 1-1.1x. There are bigger bottlenecks to
solve, like normal updates.

Ref T70295

Differential Revision: https://developer.blender.org/D5926
2019-09-29 15:28:15 +02:00
Brecht Van Lommel 8b00a73620 Cleanup: move sculpt parallel range threading test into function
Easier to experiment with different settings this way.
2019-09-29 15:27:37 +02:00
Brecht Van Lommel 770e91703d Fix part of T70295: sculpt drawing not clipping PBVH behind the camera
Use all 6 clipping planes for drawing.
2019-09-27 14:59:41 +02:00
Campbell Barton fa7ee622f0 Cleanup: includes in headers
Forward declare structs where possible.
2019-09-07 23:17:40 +10:00
Pablo Dobarro e0c792135a Sculpt: New brush cursor, active vertex and normal radius
This commit includes the new brush cursor, active vertex updates and the normal radius brush property for all sculpt brushes.
  -The new brush cursor previews the real stroke radius over the mesh and the sampled sculpt normal.
  -The active vertex is used in sculpt tools and brushes as a starting point for an operation, similar to a preselection. It is also mirrored following the enabled symmetry options to preview the stroke symmetry.
  -The normal radius brush property limits the radius that is going to be used to sample the sculpt normal and area center. It controls how closely the cursor follows the surface and it improves the behavior of most brushes, making them suitable for hard surface sculpting.

Reviewed By: campbellbarton, brecht

Differential Revision: https://developer.blender.org/D3594
2019-08-30 16:46:20 +02:00
Campbell Barton 6eadd40597 Cleanup: redundant struct declarations 2019-08-25 16:45:47 +10:00
Campbell Barton 189aa32a3a Cleanup: vertex coordinate access, naming & minor changes
This also splits vertex access and allocation so it's possible
to copy coordinates into an existing array without allocating it.
2019-08-22 06:48:10 +10:00
Campbell Barton 50fdbf3ec0 Cleanup: use const arguments for vertex coords 2019-08-21 11:58:41 +10:00
Pablo Dobarro 037cf920b4 Sculpt: mesh abstraction API
These functions make possible porting the tools from the sculpt branch, making them compatible with PBVH_FACES and PBVH_BMESH without duplicating the code. They can also help to simplify some existing code.

These functions should not be used when working with PBVH_GRIDS data in SculptSession. PBVH_GRIDS needs to be removed from the sculpt code and converted to PBVH_FACES to be compatible with this API.

Reviewed By: brecht

Differential Revision: https://developer.blender.org/D5352
2019-08-14 22:59:31 +02:00
Your Name f08662d3ed Sculpting: Remove Show Diffuse Color Option
This should have been removed in 2.80 as the functionality was removed.
This feature now does not do anything and can be removed.

Differential Revision: https://developer.blender.org/D5411
2019-08-04 11:53:48 -04:00
Campbell Barton 651e574153 Cleanup: unused var, sort structs 2019-06-28 10:07:21 +10:00
Sergey Sharybin 6b63765f1c Fix compilation error after recent changes 2019-06-17 15:13:35 +02:00
mano-wii e03b717687 Fix T65620: Sculpting brush size jumping.
The PBVHs raycast function calls `isect_ray_tri_epsilon_v3` with epsilon `0.1` which is inaccurate and may result in the problem presented in T65620.
The solution is to use `isect_ray_tri_watertight_v3` instead `isect_ray_tri_epsilon_v3`.
This can positively affect other areas as well.

Reviewers: brecht, campbellbarton

Differential Revision: https://developer.blender.org/D5083
2019-06-17 09:16:13 -03:00
Brecht Van Lommel f87bba0368 Fix T62282: multires sculpting does not update smooth normals
It may be good to move the normals update out of the drawing code. But it was
already there for the non-multires sculpt cases, and does not have an obvious
place since we bypass the depsgraph and want to avoid the cost of updating the
normals multiple times when multiple events are handled before a redraw.
2019-05-31 17:17:03 +02:00
Campbell Barton 4887b771f9 Cleanup: sort struct declarations 2019-05-14 20:21:22 +10:00
Clément Foucault b2f1a65874 Sculpt: Refactor draw manager sculpt drawing mechanism
Workbench/Eevee now displays multiple multi-materials correctly.

Iterate over pbvh nodes when doing object iteration. This makes the
rendering process more streamlined and allow for using different materials.

This change will make possible to:
- Add culling pass of each pbvh leaf node. (speedup if zoomed on a small
area)
- Reduce number of lead node iteration.
- Reduce code complexity
2019-05-04 14:11:04 +02:00
Campbell Barton 909665a0d4 ClangFormat: run with ReflowComments on source/
Prepare for enabling ReflowComments.
2019-05-01 11:13:14 +10:00
Jeroen Bakker ee701baff8 Workbench: Support Active Vertex Color
Currently it is not possible to view the vertex colors of an object. To
optimize the workflow, workbench will need to support Vertex Colors.

The Vertex Colors is a new option in `shading->color_type`. When objects
do not have vertex color, the objects will be rendered with the
`V3D_SHADING_OBJECT_COLOR`.

In order to support vertex colors in workbench the current texture/solid
shading structure is migrated to a primary shaders and fallback shaders.

Fix: T57000

Reviewers: brecht, fclem

Differential Revision: https://developer.blender.org/D4694
2019-04-23 12:05:33 +02:00
Campbell Barton e12c08e8d1 ClangFormat: apply to source, most of intern
Apply clang format as proposed in T53211.

For details on usage and instructions for migrating branches
without conflicts, see:

https://wiki.blender.org/wiki/Tools/ClangFormat
2019-04-17 06:21:24 +02:00