diff options
author | Jeroen Bakker <jbakker> | 2022-04-15 17:39:50 +0300 |
---|---|---|
committer | Jeroen Bakker <jeroen@blender.org> | 2022-04-15 17:40:01 +0300 |
commit | e96a809a68ef40225d5eddfd790644538e171a8d (patch) | |
tree | 1c679db4cda3d0ea7d6189e63dbfce020f57abf6 /source/blender/blenkernel/intern/pbvh.c | |
parent | 25196f8a369c354bf870b6144e3f43aa0a1d38e0 (diff) |
PBVH Pixel extractor.
This patch contains an initial pixel extractor for PBVH and an initial paint brush implementation.
PBVH is an accelleration structure blender uses internally to speed up 3d painting operations.
At this moment it is extensively used by sculpt, vertex painting and weight painting.
For the 3d texturing brush we will be using the PBVH for texture painting.
Currently PBVH is organized to work on geometry (vertices, polygons and triangles).
For texture painting this should be extended it to use pixels.
{F12995467}
Screen recording has been done on a Mac Mini with a 6 core 3.3 GHZ Intel processor.
# Scope
This patch only contains an extending uv seams to fix uv seams. This is not actually we want, but was easy to add
to make the brush usable.
Pixels are places in the PBVH_Leaf nodes. We want to introduce a special node for pixels, but that will be done
in a separate patch to keep the code review small. This reduces the painting performance when using
low and medium poly assets.
In workbench textures aren't forced to be shown. For now use Material/Rendered view.
# Rasterization process
The rasterization process will generate the pixel information for a leaf node. In the future those
leaf nodes will be split up into multiple leaf nodes to increase the performance when there
isn't enough geometry. For this patch this was left out of scope.
In order to do so every polygon should be uniquely assigned to a leaf node.
For each leaf node
for each polygon
If polygon not assigned
assign polygon to node.
Polygons are to complicated to be used directly we have to split the polygons into triangles.
For each leaf node
for each polygon
extract triangles from polygon.
The list of triangles can be stored inside the leaf node. The list of polygons aren't needed anymore.
Each triangle has:
poly_index.
vert_indices
delta barycentric coordinate between x steps.
Each triangle is rasterized in rows. Sequential pixels (in uv space) are stored in a single structure.
image position
barycentric coordinate of the first pixel
number of pixels
triangle index inside the leaf node.
During the performed experiments we used a fairly simple rasterization process by
finding the UV bounds of an triangle and calculate the barycentric coordinates per
pixel inside the bounds. Even for complex models and huge images this process is
normally finished within 0.5 second. It could be that we want to change this algorithm
to reduce hickups when nodes are initialized during a stroke.
Reviewed By: brecht
Maniphest Tasks: T96710
Differential Revision: https://developer.blender.org/D14504
Diffstat (limited to 'source/blender/blenkernel/intern/pbvh.c')
-rw-r--r-- | source/blender/blenkernel/intern/pbvh.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c index 5d307697208..e91f360ef22 100644 --- a/source/blender/blenkernel/intern/pbvh.c +++ b/source/blender/blenkernel/intern/pbvh.c @@ -686,6 +686,8 @@ void BKE_pbvh_free(PBVH *pbvh) if (node->bm_other_verts) { BLI_gset_free(node->bm_other_verts, NULL); } + + pbvh_pixels_free(node); } } @@ -1769,7 +1771,7 @@ BMesh *BKE_pbvh_get_bmesh(PBVH *pbvh) void BKE_pbvh_node_mark_update(PBVHNode *node) { node->flag |= PBVH_UpdateNormals | PBVH_UpdateBB | PBVH_UpdateOriginalBB | - PBVH_UpdateDrawBuffers | PBVH_UpdateRedraw; + PBVH_UpdateDrawBuffers | PBVH_UpdateRedraw | PBVH_RebuildPixels; } void BKE_pbvh_node_mark_update_mask(PBVHNode *node) @@ -1782,6 +1784,16 @@ void BKE_pbvh_node_mark_update_color(PBVHNode *node) node->flag |= PBVH_UpdateColor | PBVH_UpdateDrawBuffers | PBVH_UpdateRedraw; } +void BKE_pbvh_mark_rebuild_pixels(PBVH *pbvh) +{ + for (int n = 0; n < pbvh->totnode; n++) { + PBVHNode *node = &pbvh->nodes[n]; + if (node->flag & PBVH_Leaf) { + node->flag |= PBVH_RebuildPixels; + } + } +} + void BKE_pbvh_node_mark_update_visibility(PBVHNode *node) { node->flag |= PBVH_UpdateVisibility | PBVH_RebuildDrawBuffers | PBVH_UpdateDrawBuffers | |