Page MenuHome

PBVH: Fix UV Seams
AbandonedPublic

Authored by Jeroen Bakker (jbakker) on Apr 20 2022, 1:24 PM.

Details

Summary
NOTE: This patch will be abandoned as the solution had easy reproducable artifacts. It is kept temporarily as reference.

The main idea behind is to have a list of pixels that will be copied to pixels near uv seams in order to fix bleeding artifacts.

Extraction

For each uv edge we check if the edge has a connecting edge in uv space, these edges don't need to be fixed.
If there isn't a connecting edge in uv space there can be 2 situations.

  1. It has a connecting edge in 3d space.
  2. It doesn't have any connection in 3d space.

When it has a connecting edge in 3d space we project the image coordinate onto the other uv face and find the nearest pixel.
When it doesn't have a connecting edge in 3d space we clamp it to the nearest pixel in uv space (without projection).

Application

When applying the fixes the nodes that have been used during drawing will copy their list of source pixels to their
known destination.

Video

Green are pixels that can be painted on, red pixels indicate pixels that will be fixed. Grey pixels are left untouched.

TODO

  • Add support for tiled images.
  • Add partial updating.
  • Remove usage of BMesh.

Diff Detail

Repository
rB Blender
Branch
temp-T97352-3d-texturing-seam-bleeding
Build Status
Buildable 21746
Build 21746: arc lint + arc unit

Event Timeline

Jeroen Bakker (jbakker) retitled this revision from PBVH Pixel extractor. to PBVH: Fix UV Seams.Apr 20 2022, 1:26 PM
Jeroen Bakker (jbakker) edited the summary of this revision. (Show Details)
Jeroen Bakker (jbakker) edited the summary of this revision. (Show Details)
  • Merge branch 'master' into temp-T97352-3d-texturing-seam-bleeding
Jeroen Bakker (jbakker) edited the summary of this revision. (Show Details)Apr 20 2022, 2:08 PM
Jeroen Bakker (jbakker) edited the summary of this revision. (Show Details)Apr 20 2022, 2:18 PM
Jeroen Bakker (jbakker) edited the summary of this revision. (Show Details)Apr 20 2022, 5:21 PM
  • Merge branch 'master' into temp-T97352-3d-texturing-seam-bleeding
  • Determine region to update from changed pixels.
  • Better Seam fix detection
  • Remove BMesh.
Jeroen Bakker (jbakker) edited the summary of this revision. (Show Details)Apr 22 2022, 1:53 PM
Jeroen Bakker (jbakker) edited the summary of this revision. (Show Details)Apr 22 2022, 2:26 PM
  • Rename ldata_uvs to ldata_uv
  • Use constant for distance.
  • UDIM support.
  • Revert workbench change.
  • Remove fixd todo.
Jeroen Bakker (jbakker) requested review of this revision.Apr 22 2022, 4:06 PM

This patch is ready for initial review.

Jeroen Bakker (jbakker) edited the summary of this revision. (Show Details)Apr 22 2022, 4:06 PM
source/blender/blenkernel/intern/pbvh_pixels_seams.cc
242

Use other name

328

Add early exit

476

Add early exit

I tested out the patch and in most cases it works great. When painting more intricate areas with a bigger brush radius I noticed some issues though.
This can be seen when painting for example the ear of of the monkey object with a big brush radius and a sharp falloff to see more of a gradient:

On the bottom horizontal seam there are artefacts which can then also be seen on the mesh, since they start directly on the seam.

When painting with a texture these can also appear easily:


For this example I used a texture with teh area plane mapping and with rake enabled. But even with tiled mapping these artefacts are likely to appear.

Brecht Van Lommel (brecht) requested changes to this revision.Apr 25 2022, 4:36 PM

This seems generally fine, but I also encountered artifacts testing this.

source/blender/blenkernel/BKE_pbvh_pixels.hh
136

I'm not sure if this causes any clear artifacts currently, but we may need to not copy one pixel, but interpolate between (up to) 4 filled pixels for more accurate results.

source/blender/blenkernel/intern/pbvh_pixels_seams.cc
23

This will need to become a setting.

The easiest place to put this would be in the mode settings, though I think really the correct place for this is on the Image datablock. That way it's per image and can also be used for baking later.

There are cases where you might want to set this to very high values, for final maps it can even make most sense to fill in all pixels. Otherwise if for example there are a lot of unfilled black pixels, objects can turn darker in the distance.

50

Is there some constant for this that is used in other places of the UV editing code?

I also remember this being set to zero at some point, but not sure.

This revision now requires changes to proceed.Apr 25 2022, 4:36 PM

Think the solution should check the winding order of the triangle it projects on. Based on the winding order differences it should switch the order to project to the right location.
Will try to reproduce and see how to detect the winding order.

@Brecht Van Lommel (brecht) for averaging upto 4 pixels my first attempt would be to store the source coordinate as float and use linear interpolation with a mask. This might introduce artifacts when projecting near edges. If this isn't working we might need a way to source the color from pixels that might not be neighbors.

Other thing I am considering (separate patch) to determine the 3d position from the center uv coordinate. Currently it is the bottom left. This this would reduce some smaller artifacts as well.

Jeroen Bakker (jbakker) marked 2 inline comments as done.
  • Remove limit check in uv space.
  • Separate projection code.
  • Fix some artifacts by checking the winding order.
  • Renamed watertight to image_tile_user.
  • Add early exits to skip bitmaps.
  • Make seamfix distance as a user controlled setting per image.
source/blender/blenkernel/BKE_pbvh_pixels.hh
136

I haven't done this. First we should see if the current changes are better when so, we could improve further by implementing some blending and masking.

source/blender/blenkernel/intern/pbvh_pixels_seams.cc
23

I will add it as a setting in the image datablock. I think the number of pixels is easier to understand for users. In the future we might want to add an override setting for tiles, but not sure these are actually needed.

For now I won't do the fill all pixels as that might require leaping over multiple edges. I can imagine we could also use a specialized expand operation to fill in the black pixels to overcome this.

50

There used to be a function that could handle a limit offset in UV. but that isn't used anymore I could only find a definition of it.

I'm ok to remove this and to keep in sync with UV code as it would fail when working with extreme dense uvs.

source/blender/blenkernel/intern/pbvh_pixels_seams.cc
50

Seems this is an ongoing discussion in T81065: Applying Subdivision/Multires Modifier De-merges UV's.

The current situation seems to be to expect exact equality, and if that changes we'd need to modify this new code to match.

  • Merge branch 'master' into temp-T97352-3d-texturing-seam-bleeding
  • Use source blending with a mask.
  • Merge branch 'master' into temp-T97352-3d-texturing-seam-bleeding
  • Merge branch 'master' into temp-T97352-3d-texturing-seam-bleeding
  • Improve quality seam fixing (step distance)
  • Remove debug code.
Jeroen Bakker (jbakker) planned changes to this revision.May 13 2022, 4:56 PM

Ok, what we found out so far is that the seam bleeding is only working on float textures. I seemed to have forgotten to support the byte textures currently.
Also there are some nasty artifacts that needs to be solved. We might have an approach, but would require more time to spend on a technical 'design'

Jeroen Bakker (jbakker) edited the summary of this revision. (Show Details)May 17 2022, 8:01 AM

New implementation is further than this one. Time to abandon it