[Bf-blender-cvs] [6121579f5c7] temp-T97352-3d-texturing-seam-bleeding-b2: First stroke, no crash, but incorrect results.

Jeroen Bakker noreply at git.blender.org
Fri Jun 10 08:59:25 CEST 2022


Commit: 6121579f5c797d6b3d3eaa00324c96bb4cf601f7
Author: Jeroen Bakker
Date:   Fri Jun 10 08:57:20 2022 +0200
Branches: temp-T97352-3d-texturing-seam-bleeding-b2
https://developer.blender.org/rB6121579f5c797d6b3d3eaa00324c96bb4cf601f7

First stroke, no crash, but incorrect results.

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

M	source/blender/blenkernel/BKE_pbvh_pixels.hh
M	source/blender/blenkernel/intern/pbvh_pixels.cc
M	source/blender/editors/sculpt_paint/sculpt_paint_image.cc

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

diff --git a/source/blender/blenkernel/BKE_pbvh_pixels.hh b/source/blender/blenkernel/BKE_pbvh_pixels.hh
index 3cb6151e076..3e37399630a 100644
--- a/source/blender/blenkernel/BKE_pbvh_pixels.hh
+++ b/source/blender/blenkernel/BKE_pbvh_pixels.hh
@@ -18,8 +18,47 @@
 
 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;
+  /* TODO: should also store the pos per vertex. (init_pixel_pos)*/
+
+ 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 +72,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 +109,7 @@ struct Triangles {
 
   uint64_t mem_size() const
   {
-    return paint_input.size() * sizeof(TrianglePaintInput);
+    return size() * sizeof(UVPrimitivePaintInput);
   }
 };
 
@@ -92,7 +124,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 +180,7 @@ struct NodeData {
 
   Vector<UDIMTilePixels> tiles;
   Vector<UDIMTileUndo> undo_regions;
-  Triangles triangles;
+  PaintUVPrimitives uv_primitives;
 
   NodeData()
   {
@@ -195,7 +227,7 @@ struct NodeData {
   void clear_data()
   {
     tiles.clear();
-    triangles.clear();
+    uv_primitives.clear();
   }
 
   static void free_func(void *instance)
@@ -207,9 +239,11 @@ struct NodeData {
 
 struct PBVHData {
   /* Per UVPRimitive contains the paint data. */
+  PaintGeometryPrimitives geom_primitives;
 
   void clear_data()
   {
+    geom_primitives.clear();
   }
 };
 
diff --git a/source/blender/blenkernel/intern/pbvh_pixels.cc b/source/blender/blenkernel/intern/pbvh_pixels.cc
index 377013527f8..32f5dc2d2f3 100644
--- a/source/blender/blenkernel/intern/pbvh_pixels.cc
+++ b/source/blender/blenkernel/intern/pbvh_pixels.cc
@@ -35,9 +35,8 @@ constexpr bool USE_WATERTIGHT_CHECK = true;
  * \{ */
 
 /** Build UV islands from PBVH primitives. */
-static uv_islands::UVIslands build_uv_islands(const PBVH &pbvh, const MLoopUV *mloopuv)
+static uv_islands::UVIslands build_uv_islands(uv_islands::MeshData &mesh_data)
 {
-  uv_islands::MeshData mesh_data(pbvh.looptri, pbvh.totprim, pbvh.totvert, pbvh.mloop, mloopuv);
   uv_islands::UVIslands islands(mesh_data);
   uv_islands::UVIslandsMask uv_masks(float2(0.0, 0.0), ushort2(256, 256));
   uv_masks.add(islands);
@@ -77,7 +76,7 @@ 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 int64_t uv_primitive_index,
                                        const float2 uvs[3],
                                        const int minx,
                                        const int miny,
@@ -87,7 +86,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;
 
@@ -115,12 +114,15 @@ 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,
+                                          mesh_primitive.vertices[1].vertex->v,
+                                          mesh_primitive.vertices[2].vertex->v));
   }
 }
 
@@ -154,50 +156,43 @@ static void do_encode_pixels(void *__restrict userdata,
     float2 tile_offset = float2(image_tile.get_tile_offset());
     UDIMTilePixels tile_data;
 
-    Triangles &triangles = node_data->triangles;
-    for (int triangle_index = 0; triangle_index < triangles.size(); triangle_index++) {
-      int mesh_prim_index = node->prim_indices[triangle_index];
+    for (int pbvh_node_prim_index = 0; pbvh_node_prim_index < node->totprim;
+         pbvh_node_prim_index++) {
+      int64_t geom_prim_index = node->prim_indices[pbvh_node_prim_index];
       for (const uv_islands::UVIsland &island : data->uv_islands->islands) {
         for (const uv_islands::UVPrimitive &uv_primitive : island.uv_primitives) {
-          if (uv_primitive.primitive->index == mesh_prim_index) {
-            float2 uvs[3] = {
-                uv_primitive.edges[0]->vertices[0]->uv - tile_offset,
-                uv_primitive.edges[1]->vertices[0]->uv - tile_offset,
-                uv_primitive.edges[2]->vertices[0]->uv - tile_offset,
-            };
-            const float minv = clamp_f(min_fff(uvs[0].y, uvs[1].y, uvs[2].y), 0.0f, 1.0f);
-            const int miny = floor(minv * image_buffer->y);
-            const float maxv = clamp_f(max_fff(uvs[0].y, uvs[1].y, uvs[2].y), 0.0f, 1.0f);
-            const int maxy = min_ii(ceil(maxv * image_buffer->y), image_buffer->y);
-            const float minu = clamp_f(min_fff(uvs[0].x, uvs[1].x, uvs[2].x), 0.0f, 1.0f);
-            const int minx = floor(minu * image_buffer->x);
-            const float maxu = clamp_f(max_fff(uvs[0].x, uvs[1].x, uvs[2].x), 0.0f, 1.0f);
-            const int maxx = min_ii(ceil(maxu * image_buffer->x), image_buffer->x);
+          if (uv_primitive.primitive->index != geom_prim_index) {
+            continue;
           }
+          float2 uvs[3] = {
+              uv_primitive.edges[0]->vertices[0]->uv - tile_offset,
+              uv_primitive.edges[1]->vertices[0]->uv - tile_offset,
+              uv_primitive.edges[2]->vertices[0]->uv - tile_offset,
+          };
+          const float minv = clamp_f(min_fff(uvs[0].y, uvs[1].y, uvs[2].y), 0.0f, 1.0f);
+          const int miny = floor(minv * image_buffer->y);
+          const float maxv = clamp_f(max_fff(uvs[0].y, uvs[1].y, uvs[2].y), 0.0f, 1.0f);
+          const int maxy = min_ii(ceil(maxv * image_buffer->y), image_buffer->y);
+          const float minu = clamp_f(min_fff(uvs[0].x, uvs[1].x, uvs[2].x), 0.0f, 1.0f);
+          const int minx = floor(minu * image_buffer->x);
+          const float maxu = clamp_f(max_fff(uvs[0].x, uvs[1].x, uvs[2].x), 0.0f, 1.0f);
+          const int maxx = min_ii(ceil(maxu * image_buffer->x), image_buffer->x);
+
+          /* TODO: Perform bounds check */
+          int64_t uv_prim_index = node_data->uv_primitives.size();
+          node_data->uv_primitives.append(geom_prim_index);
+          UVPrimitivePaintInput &paint_input = node_data->uv_primitives.last();
+
+          /* Calculate barycentric delta */
+          paint_input.delta_barycentric_coord_u = calc_barycentric_delta_x(
+              image_buffer, uvs, minx, miny);
+
+          /* Extract the pixels. */
+          extract_barycentric_pixels(
+              tile_data, image_buffer, uv_prim_index, uvs, minx, miny, maxx, maxy);
         }
       }
-      const MLoopTri *lt = &pbvh->looptri[node->prim_indices[triangle_index]];
-      float2 uvs[3] = {
-          float2(data->ldata_uv[lt->tri[0]].uv) - tile_offset,
-          float2(data->ldata_uv[lt->tri[1]].uv) - tile_offset,
-          float2(data->ldata_uv[lt->tri[2]].uv) - tile_offset,
-      };
-
-      const float minv = clamp_f(min_fff(uvs[0].y, uvs[1].y, uvs

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list