[Bf-blender-cvs] [e88d1467f98] temp-pbvh-seam-texturing-tweaks: Initial patch from Jeroen

Hans Goudey noreply at git.blender.org
Wed Sep 28 05:04:26 CEST 2022


Commit: e88d1467f98cdd57c69f470840e71fde78c8b9eb
Author: Hans Goudey
Date:   Tue Sep 27 15:36:55 2022 -0500
Branches: temp-pbvh-seam-texturing-tweaks
https://developer.blender.org/rBe88d1467f98cdd57c69f470840e71fde78c8b9eb

Initial patch from Jeroen

===================================================================

M	source/blender/blenkernel/BKE_pbvh.h
M	source/blender/blenkernel/BKE_pbvh_pixels.hh
M	source/blender/blenkernel/CMakeLists.txt
M	source/blender/blenkernel/intern/paint_canvas.cc
M	source/blender/blenkernel/intern/pbvh.c
M	source/blender/blenkernel/intern/pbvh_intern.h
M	source/blender/blenkernel/intern/pbvh_pixels.cc
A	source/blender/blenkernel/intern/pbvh_uv_islands.cc
A	source/blender/blenkernel/intern/pbvh_uv_islands.hh
M	source/blender/blenlib/BLI_vector.hh
A	source/blender/blenlib/BLI_vector_list.hh
M	source/blender/blenlib/CMakeLists.txt
M	source/blender/blenloader/intern/versioning_300.cc
M	source/blender/editors/sculpt_paint/sculpt_paint_image.cc
M	source/blender/editors/space_image/image_buttons.c
M	source/blender/makesdna/DNA_image_defaults.h
M	source/blender/makesdna/DNA_image_types.h
M	source/blender/makesrna/intern/rna_image.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_pbvh.h b/source/blender/blenkernel/BKE_pbvh.h
index ff2140732cc..09a2187f586 100644
--- a/source/blender/blenkernel/BKE_pbvh.h
+++ b/source/blender/blenkernel/BKE_pbvh.h
@@ -89,6 +89,15 @@ typedef struct {
   float (*color)[4];
 } PBVHColorBufferNode;
 
+typedef struct PBVHPixels {
+  /**
+   * Contains data constant for each UVPrimitive.
+   *
+   * #blender::bke::pbvh::pixels::PBVHData
+   */
+  void *data;
+} PBVHPixels;
+
 typedef struct PBVHPixelsNode {
   /**
    * Contains triangle/pixel data used during texture painting.
diff --git a/source/blender/blenkernel/BKE_pbvh_pixels.hh b/source/blender/blenkernel/BKE_pbvh_pixels.hh
index ad8eca2b36f..5fc648af3f1 100644
--- a/source/blender/blenkernel/BKE_pbvh_pixels.hh
+++ b/source/blender/blenkernel/BKE_pbvh_pixels.hh
@@ -18,8 +18,46 @@
 
 namespace blender::bke::pbvh::pixels {
 
-struct TrianglePaintInput {
-  int3 vert_indices;
+/**
+ * Data shared between pixels that belong to the same triangle.
+ *
+ * Data is stored as a list of structs, grouped by usage to improve performance (improves CPU
+ * cache prefetching).
+ */
+struct PaintGeometryPrimitives {
+  /** Data accessed by the inner loop of the painting brush. */
+  Vector<int3> vert_indices;
+
+ public:
+  void append(const int3 vert_indices)
+  {
+    this->vert_indices.append(vert_indices);
+  }
+
+  const int3 &get_vert_indices(const int index) const
+  {
+    return vert_indices[index];
+  }
+
+  void clear()
+  {
+    vert_indices.clear();
+  }
+
+  uint64_t size() const
+  {
+    return vert_indices.size();
+  }
+
+  uint64_t mem_size() const
+  {
+    return size() * sizeof(int3);
+  }
+};
+
+struct UVPrimitivePaintInput {
+  /** Corresponding index into PaintGeometryPrimitives */
+  int64_t geometry_primitive_index;
   /**
    * Delta barycentric coordinates between 2 neighboring UV's in the U direction.
    *
@@ -33,34 +71,27 @@ struct TrianglePaintInput {
    * delta_barycentric_coord_u is initialized in a later stage as it requires image tile
    * dimensions.
    */
-  TrianglePaintInput(const int3 vert_indices)
-      : vert_indices(vert_indices), delta_barycentric_coord_u(0.0f, 0.0f)
+  UVPrimitivePaintInput(int64_t geometry_primitive_index)
+      : geometry_primitive_index(geometry_primitive_index), delta_barycentric_coord_u(0.0f, 0.0f)
   {
   }
 };
 
-/**
- * Data shared between pixels that belong to the same triangle.
- *
- * Data is stored as a list of structs, grouped by usage to improve performance (improves CPU
- * cache prefetching).
- */
-struct Triangles {
+struct PaintUVPrimitives {
   /** Data accessed by the inner loop of the painting brush. */
-  Vector<TrianglePaintInput> paint_input;
+  Vector<UVPrimitivePaintInput> paint_input;
 
- public:
-  void append(const int3 vert_indices)
+  void append(int64_t geometry_primitive_index)
   {
-    this->paint_input.append(TrianglePaintInput(vert_indices));
+    this->paint_input.append(UVPrimitivePaintInput(geometry_primitive_index));
   }
 
-  TrianglePaintInput &get_paint_input(const int index)
+  UVPrimitivePaintInput &last()
   {
-    return paint_input[index];
+    return paint_input.last();
   }
 
-  const TrianglePaintInput &get_paint_input(const int index) const
+  const UVPrimitivePaintInput &get_paint_input(uint64_t index) const
   {
     return paint_input[index];
   }
@@ -77,7 +108,7 @@ struct Triangles {
 
   uint64_t mem_size() const
   {
-    return paint_input.size() * sizeof(TrianglePaintInput);
+    return size() * sizeof(UVPrimitivePaintInput);
   }
 };
 
@@ -92,7 +123,7 @@ struct PackedPixelRow {
   /** Number of sequential pixels encoded in this package. */
   ushort num_pixels;
   /** Reference to the pbvh triangle index. */
-  ushort triangle_index;
+  ushort uv_primitive_index;
 };
 
 /**
@@ -148,7 +179,7 @@ struct NodeData {
 
   Vector<UDIMTilePixels> tiles;
   Vector<UDIMTileUndo> undo_regions;
-  Triangles triangles;
+  PaintUVPrimitives uv_primitives;
 
   NodeData()
   {
@@ -201,7 +232,7 @@ struct NodeData {
   void clear_data()
   {
     tiles.clear();
-    triangles.clear();
+    uv_primitives.clear();
   }
 
   static void free_func(void *instance)
@@ -211,7 +242,18 @@ struct NodeData {
   }
 };
 
+struct PBVHData {
+  /* Per UVPRimitive contains the paint data. */
+  PaintGeometryPrimitives geom_primitives;
+
+  void clear_data()
+  {
+    geom_primitives.clear();
+  }
+};
+
 NodeData &BKE_pbvh_pixels_node_data_get(PBVHNode &node);
 void BKE_pbvh_pixels_mark_image_dirty(PBVHNode &node, Image &image, ImageUser &image_user);
+PBVHData &BKE_pbvh_pixels_data_get(PBVH &pbvh);
 
 }  // namespace blender::bke::pbvh::pixels
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index 877407a644c..e4bc70987d0 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -251,6 +251,7 @@ set(SRC
   intern/pbvh.cc
   intern/pbvh_bmesh.c
   intern/pbvh_pixels.cc
+  intern/pbvh_uv_islands.cc
   intern/pointcache.c
   intern/pointcloud.cc
   intern/preferences.c
diff --git a/source/blender/blenkernel/intern/paint_canvas.cc b/source/blender/blenkernel/intern/paint_canvas.cc
index b72418d88c0..497d98dcab3 100644
--- a/source/blender/blenkernel/intern/paint_canvas.cc
+++ b/source/blender/blenkernel/intern/paint_canvas.cc
@@ -113,6 +113,7 @@ char *BKE_paint_canvas_key_get(struct PaintModeSettings *settings, struct Object
   Image *image;
   ImageUser *image_user;
   if (BKE_paint_canvas_image_get(settings, ob, &image, &image_user)) {
+    ss << ",SEAM_DIST:" << image->seamfix_iter;
     ImageUser tile_user = *image_user;
     LISTBASE_FOREACH (ImageTile *, image_tile, &image->tiles) {
       tile_user.tile = image_tile->tile_number;
diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c
index 1d65e958e1c..ee337e32c24 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -667,7 +667,7 @@ void BKE_pbvh_free(PBVH *pbvh)
         BLI_gset_free(node->bm_other_verts, NULL);
       }
 
-      pbvh_pixels_free(node);
+      pbvh_node_pixels_free(node);
     }
   }
 
@@ -697,6 +697,8 @@ void BKE_pbvh_free(PBVH *pbvh)
     GPU_pbvh_free_format(pbvh->vbo_id);
   }
 
+  pbvh_pixels_free(pbvh);
+
   MEM_freeN(pbvh);
 }
 
diff --git a/source/blender/blenkernel/intern/pbvh_intern.h b/source/blender/blenkernel/intern/pbvh_intern.h
index 8ab56839f9c..4888f2658c3 100644
--- a/source/blender/blenkernel/intern/pbvh_intern.h
+++ b/source/blender/blenkernel/intern/pbvh_intern.h
@@ -214,6 +214,8 @@ struct PBVH {
   bool draw_cache_invalid;
 
   struct PBVHGPUFormat *vbo_id;
+
+  PBVHPixels pixels;
 };
 
 /* pbvh.c */
@@ -286,7 +288,8 @@ void pbvh_bmesh_normals_update(PBVHNode **nodes, int totnode);
 
 /* pbvh_pixels.hh */
 
-void pbvh_pixels_free(PBVHNode *node);
+void pbvh_node_pixels_free(PBVHNode *node);
+void pbvh_pixels_free(PBVH *pbvh);
 void pbvh_pixels_free_brush_test(PBVHNode *node);
 void pbvh_free_draw_buffers(PBVH *pbvh, PBVHNode *node);
 
diff --git a/source/blender/blenkernel/intern/pbvh_pixels.cc b/source/blender/blenkernel/intern/pbvh_pixels.cc
index f733f3145ec..2f65f6b02ab 100644
--- a/source/blender/blenkernel/intern/pbvh_pixels.cc
+++ b/source/blender/blenkernel/intern/pbvh_pixels.cc
@@ -20,6 +20,7 @@
 #include "bmesh.h"
 
 #include "pbvh_intern.h"
+#include "pbvh_uv_islands.hh"
 
 namespace blender::bke::pbvh::pixels {
 
@@ -57,8 +58,11 @@ static float2 calc_barycentric_delta_x(const ImBuf *image_buffer,
 
 static void extract_barycentric_pixels(UDIMTilePixels &tile_data,
                                        const ImBuf *image_buffer,
-                                       const int triangle_index,
+                                       const uv_islands::UVIslandsMask &uv_mask,
+                                       const int64_t uv_island_index,
+                                       const int64_t uv_primitive_index,
                                        const float2 uvs[3],
+                                       const float2 tile_offset,
                                        const int minx,
                                        const int miny,
                                        const int maxx,
@@ -67,7 +71,7 @@ static void extract_barycentric_pixels(UDIMTilePixels &tile_data,
   for (int y = miny; y < maxy; y++) {
     bool start_detected = false;
     PackedPixelRow pixel_row;
-    pixel_row.triangle_index = triangle_index;
+    pixel_row.uv_primitive_index = uv_primitive_index;
     pixel_row.num_pixels = 0;
     int x;
 
@@ -77,12 +81,13 @@ static void extract_barycentric_pixels(UDIMTilePixels &tile_data,
       barycentric_weights_v2(uvs[0], uvs[1], uvs[2], uv, barycentric_weights);
 
       const bool is_inside = barycentric_inside_triangle_v2(barycentric_weights);
-      if (!start_detected && is_inside) {
+      const bool is_masked = uv_mask.is_masked(uv_island_index, uv + tile_offset);
+      if (!start_detected && is_inside && is_masked) {
         start_detected = true;
         pixel_row.start_image_coordinate = ushort2(x, y);
         pixel_row.start_barycentric_coord = float2(barycentric_weights.x, barycentric_weights.y);
       }
-      else if (start_detected && !is_inside) {
+      else if (start_detected && (!is_inside || !is_masked)) {
         break;
       }
     }
@@ -95,21 +100,57 @@ static void extract_barycentric_pixels(UDIMTilePixels &tile_data,
   }
 }
 
-static void init_triangles(PBVH *pbvh, PBVHNode *node, NodeData *node_data, const MLoop *mloop)
+/** Update the geometry primitives of the pbvh. */
+static void update_geom_primitives(PBVH &pbvh, const uv_islands::MeshData &mesh_data)
 {
-  for (int i = 0; i < node->totprim; i++) {
-    const MLoopTri *lt = &pbvh->looptri[node->prim_indices[i]];
-    node_data->triangles.append(
-        int3(mloop[lt->tri[0]].v, mloop[lt->tri[1]].v, mloop[lt->tri[2]].v));
+  PBVHData &pbvh_data = BKE_pbvh_pixels_data_get(pbvh);
+  pbvh_data.clear_data();
+  for (const uv_islands::MeshPrimitive &mesh_primitive : mesh_data.primitives) {
+    pbvh_data.geom_primitives.append(int3(mesh_primitive.vertices[0].vertex->v,
+                                         

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list