[Bf-blender-cvs] [9ce9cf5a315] temp-T97352-3d-texturing-seam-bleeding: Make seamfix distance as a user controlled setting per image.

Jeroen Bakker noreply at git.blender.org
Mon May 2 14:33:58 CEST 2022


Commit: 9ce9cf5a31519d149a00a21891e3dbd575d0cdfd
Author: Jeroen Bakker
Date:   Mon May 2 14:33:52 2022 +0200
Branches: temp-T97352-3d-texturing-seam-bleeding
https://developer.blender.org/rB9ce9cf5a31519d149a00a21891e3dbd575d0cdfd

Make seamfix distance as a user controlled setting per image.

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

M	source/blender/blenkernel/intern/paint_canvas.cc
M	source/blender/blenkernel/intern/pbvh_pixels_seams.cc
M	source/blender/blenloader/intern/versioning_300.c
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/intern/paint_canvas.cc b/source/blender/blenkernel/intern/paint_canvas.cc
index b72418d88c0..f06b5222cd2 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_distance;
     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_pixels_seams.cc b/source/blender/blenkernel/intern/pbvh_pixels_seams.cc
index c2d68a3a380..c598a10f17c 100644
--- a/source/blender/blenkernel/intern/pbvh_pixels_seams.cc
+++ b/source/blender/blenkernel/intern/pbvh_pixels_seams.cc
@@ -18,9 +18,6 @@
 
 namespace blender::bke::pbvh::pixels {
 
-/* Distance between a pixel and its edge that will be fixed. Value is in pixels space. */
-constexpr float SEAMFIX_EDGE_DISTANCE = 3.5f;
-
 struct EdgeLoop {
   /** Loop indexes that form an edge. */
   int l[2];
@@ -377,7 +374,8 @@ static void build_fixes(PBVH &pbvh,
                         const MLoopUV &luv_a_2,
                         const MLoopUV &luv_b_1,
                         const MLoopUV &luv_b_2,
-                        const float scale_factor)
+                        const float scale_factor,
+                        const float seamfix_distance)
 {
   if (uvbounds.xmax < 0 || uvbounds.ymax < 0 || uvbounds.xmin > bitmap.resolution.x ||
       uvbounds.ymin > bitmap.resolution.y) {
@@ -412,7 +410,7 @@ static void build_fixes(PBVH &pbvh,
 
       /* Distance to the edge in pixel space. */
       float distance_to_edge = len_v2v2(closest_coord, uv_coord);
-      if (distance_to_edge > SEAMFIX_EDGE_DISTANCE) {
+      if (distance_to_edge > seamfix_distance) {
         continue;
       }
 
@@ -445,7 +443,8 @@ static void build_fixes(PBVH &pbvh,
 static void build_fixes(PBVH &pbvh,
                         const Vector<std::pair<EdgeLoop, EdgeLoop>> &connected,
                         Bitmaps &bitmaps,
-                        const MLoopUV *ldata_uv)
+                        const MLoopUV *ldata_uv,
+                        const float seamfix_distance)
 {
   for (const std::pair<EdgeLoop, EdgeLoop> &pair : connected) {
     // determine bounding rect in uv space + margin of 1;
@@ -477,8 +476,16 @@ static void build_fixes(PBVH &pbvh,
                             bitmap.resolution[1] +
                         MARGIN;
 
-      build_fixes(
-          pbvh, bitmaps, bitmap, uvbounds_i, luv_a_1, luv_a_2, luv_b_1, luv_b_2, scale_factor);
+      build_fixes(pbvh,
+                  bitmaps,
+                  bitmap,
+                  uvbounds_i,
+                  luv_a_1,
+                  luv_a_2,
+                  luv_b_1,
+                  luv_b_2,
+                  scale_factor,
+                  seamfix_distance);
     }
   }
 }
@@ -490,8 +497,12 @@ static void build_fixes(PBVH &pbvh,
 /** \name Build fixes for unconnected edges.
  * \{ */
 
-static void build_fixes(
-    PBVH &pbvh, Bitmap &bitmap, const rcti &uvbounds, const MLoopUV &luv_1, const MLoopUV &luv_2)
+static void build_fixes(PBVH &pbvh,
+                        Bitmap &bitmap,
+                        const rcti &uvbounds,
+                        const MLoopUV &luv_1,
+                        const MLoopUV &luv_2,
+                        const float seamfix_distance)
 {
   if (uvbounds.xmax < 0 || uvbounds.ymax < 0 || uvbounds.xmin > bitmap.resolution.x ||
       uvbounds.ymin > bitmap.resolution.y) {
@@ -523,7 +534,7 @@ static void build_fixes(
       float2 closest_coord(closest_point.x * bitmap.resolution.x,
                            closest_point.y * bitmap.resolution.y);
       float distance_to_edge = len_v2v2(uv_coord, closest_coord);
-      if (distance_to_edge > SEAMFIX_EDGE_DISTANCE) {
+      if (distance_to_edge > seamfix_distance) {
         continue;
       }
 
@@ -550,7 +561,8 @@ static void build_fixes(
 static void build_fixes(PBVH &pbvh,
                         const Vector<EdgeLoop> &unconnected,
                         Bitmaps &bitmaps,
-                        const MLoopUV *ldata_uv)
+                        const MLoopUV *ldata_uv,
+                        const float seamfix_distance)
 {
   for (const EdgeLoop &unconnected_loop : unconnected) {
     // determine bounding rect in uv space + margin of 1;
@@ -577,7 +589,7 @@ static void build_fixes(PBVH &pbvh,
                             bitmap.resolution[1] +
                         MARGIN;
 
-      build_fixes(pbvh, bitmap, uvbounds_i, luv_1, luv_2);
+      build_fixes(pbvh, bitmap, uvbounds_i, luv_1, luv_2, seamfix_distance);
     }
   }
 }
@@ -599,8 +611,8 @@ void BKE_pbvh_pixels_rebuild_seams(
 
   pbvh_pixels_clear_seams(pbvh);
   /* Fix connected edges before unconnected to improve quality. */
-  build_fixes(*pbvh, connected, bitmaps, ldata_uv);
-  build_fixes(*pbvh, unconnected, bitmaps, ldata_uv);
+  build_fixes(*pbvh, connected, bitmaps, ldata_uv, image->seamfix_distance);
+  build_fixes(*pbvh, unconnected, bitmaps, ldata_uv, image->seamfix_distance);
 }
 
 void BKE_pbvh_pixels_fix_seams(PBVHNode *node, Image *image, ImageUser *image_user)
diff --git a/source/blender/blenloader/intern/versioning_300.c b/source/blender/blenloader/intern/versioning_300.c
index e6a214452fe..57c8411dfe7 100644
--- a/source/blender/blenloader/intern/versioning_300.c
+++ b/source/blender/blenloader/intern/versioning_300.c
@@ -2772,5 +2772,11 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
    */
   {
     /* Keep this block, even when empty. */
+
+    if (!DNA_struct_elem_find(fd->filesdna, "Image", "float", "seamfix_distance")) {
+      LISTBASE_FOREACH (Image *, image, &bmain->images) {
+        image->seamfix_distance = 2.5f;
+      }
+    }
   }
 }
diff --git a/source/blender/editors/space_image/image_buttons.c b/source/blender/editors/space_image/image_buttons.c
index 208928afc1f..0bdbc1be75e 100644
--- a/source/blender/editors/space_image/image_buttons.c
+++ b/source/blender/editors/space_image/image_buttons.c
@@ -948,6 +948,7 @@ void uiTemplateImage(uiLayout *layout,
       }
 
       uiItemR(col, &imaptr, "use_view_as_render", 0, NULL, ICON_NONE);
+      uiItemR(col, &imaptr, "seamfix_distance", 0, NULL, ICON_NONE);
     }
   }
 
diff --git a/source/blender/makesdna/DNA_image_defaults.h b/source/blender/makesdna/DNA_image_defaults.h
index 52df8c869cf..c8fbcf487c8 100644
--- a/source/blender/makesdna/DNA_image_defaults.h
+++ b/source/blender/makesdna/DNA_image_defaults.h
@@ -24,6 +24,7 @@
     .gpuframenr = INT_MAX, \
     .gpu_pass = SHRT_MAX, \
     .gpu_layer = SHRT_MAX, \
+    .seamfix_distance = 2.5f, \
   }
 
 /** \} */
diff --git a/source/blender/makesdna/DNA_image_types.h b/source/blender/makesdna/DNA_image_types.h
index 4e66e2446f0..2f2f0e2dceb 100644
--- a/source/blender/makesdna/DNA_image_types.h
+++ b/source/blender/makesdna/DNA_image_types.h
@@ -170,7 +170,9 @@ typedef struct Image {
   short gpu_pass;
   short gpu_layer;
   short gpu_view;
-  char _pad2[4];
+
+  /* Thickness of the UV seam fix area in distance between pixels and edges in pixel space. */
+  float seamfix_distance;
 
   /** Deprecated. */
   struct PackedFile *packedfile DNA_DEPRECATED;
diff --git a/source/blender/makesrna/intern/rna_image.c b/source/blender/makesrna/intern/rna_image.c
index 3a93a44e0d1..2c2832e63da 100644
--- a/source/blender/makesrna/intern/rna_image.c
+++ b/source/blender/makesrna/intern/rna_image.c
@@ -1141,6 +1141,11 @@ static void rna_def_image(BlenderRNA *brna)
                            "Use 16 bits per channel to lower the memory usage during rendering");
   RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, "rna_Image_gpu_texture_update");
 
+  prop = RNA_def_property(srna, "seamfix_distance", PROP_FLOAT, PROP_PIXEL);
+  RNA_def_property_ui_text(
+      prop, "Seam-fix Distance", "Pixels closer to edge will be considered during UV seam fixing");
+  RNA_def_property_ui_range(prop, 0.0, FLT_MAX, 1, 1);
+
   /* multiview */
   prop = RNA_def_property(srna, "views_format", PROP_ENUM, PROP_NONE);
   RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);



More information about the Bf-blender-cvs mailing list