Texture Painting: Fix Seam Bleeding of Non-Manifold Sections of Mesh #105336

Merged
Jeroen Bakker merged 6 commits from Jeroen-Bakker/blender:3dtexturing-fix-seam-bleeding-non-manifold into main 2023-03-09 16:11:14 +01:00
Member

Fix seam bleeding of non-manifold sections of the mesh, by copying pixels
that are covered by the brush stroke.

As manifold parts are already handled, the pixel copying solution can be
very straight forward.

  • Pixels are copied from the same tile. So we don't need a mechanism that
    copies and merges pixels from other tiles.
  • Pixels are copied from the closest pixel that is being painted on. We
    don't need to consider that that pixel can be in different areas of the
    tile.

When we copy a pixel, we find the closest pixel in UV space that is being
directly influenced by a paint brush. We also look for the second closest
pixel, which is still a neighbor from the closest pixel. We can mix both
pixels together and store it in the destination. A mix factor is calculated
using the closest non manifold edge as a guidance.

The result of this step is a list of copy and mix commands that can be
executed to fix the seam bleeding for non-manifold sections of the mesh.

Destination Source 1 Source 2 Mix factor
1780,1811 1780,1810 1779,1810 0.000000
1781,1811 1781,1810 1782,1811 0.168627
1828,1811 1828,1810 1827,1811 0.156863
1829,1811 1829,1810 1828,1810 0.188235
1830,1811 1830,1810 1829,1810 0.188235
1831,1811 1831,1810 1830,1810 0.188235
1832,1811 1832,1810 1831,1810 0.188235
1833,1811 1832,1810 1832,1810 0.000000

In the end we go over this list mix the sources and store the result at
the destination.

tile_buffer[destination] = mix(tile_buffer[source_1],
                               tile_buffer[source_2],
                               mix_factor);

Encoding
When using a large textures or large seam margins this table can grow
large and reduce performance as data retrieval is slower, than the
operations it has to perform. To improve the performance we encode the
table so less data retrieval needs to be done.

  • first DeltaCopyPixelCommand is delta encoded from
    CopyPixelGroup#start_destination and start_source_1. The others
    are delta encoded from the previous DeltaCopyPixelCommand.
  • For performance reasons PixelCopyGroup#pixels are ordered from
    destination (left to right) for each row a new group would be created
    as the delta encoding most likely doesn't fit. When pixels cannot be
    delta encoded a new group will also be created.

Compression rate
When using Suzanne the compression rate is around 36% when using a seam
margin of 4 pixels. The compression rate may vary depending on seam
margin and model. For Suzanne the compression rate was around 36% for
various resolutions.

Resolution Margin Decoded size Encoded size Compression
2048x2048 4 px 353.052 128.101 36%
4096x4096 4 px 700.140 255.137 36%
8192x8192 4 px 1.419.320 513.802 36%
2048x2048 8 px 721.084 193.629 26%
4096x4096 8 px 1.444.968 388.110 26%
Fix seam bleeding of non-manifold sections of the mesh, by copying pixels that are covered by the brush stroke. As manifold parts are already handled, the pixel copying solution can be very straight forward. * Pixels are copied from the same tile. So we don't need a mechanism that copies and merges pixels from other tiles. * Pixels are copied from the closest pixel that is being painted on. We don't need to consider that that pixel can be in different areas of the tile. When we copy a pixel, we find the closest pixel in UV space that is being directly influenced by a paint brush. We also look for the second closest pixel, which is still a neighbor from the closest pixel. We can mix both pixels together and store it in the destination. A mix factor is calculated using the closest non manifold edge as a guidance. The result of this step is a list of copy and mix commands that can be executed to fix the seam bleeding for non-manifold sections of the mesh. | Destination | Source 1 | Source 2 | Mix factor | | ----------- | -------- | -------- | ---------- | | 1780,1811 | 1780,1810| 1779,1810| 0.000000 | | 1781,1811 | 1781,1810| 1782,1811| 0.168627 | | 1828,1811 | 1828,1810| 1827,1811| 0.156863 | | 1829,1811 | 1829,1810| 1828,1810| 0.188235 | | 1830,1811 | 1830,1810| 1829,1810| 0.188235 | | 1831,1811 | 1831,1810| 1830,1810| 0.188235 | | 1832,1811 | 1832,1810| 1831,1810| 0.188235 | | 1833,1811 | 1832,1810| 1832,1810| 0.000000 | In the end we go over this list mix the sources and store the result at the destination. ``` tile_buffer[destination] = mix(tile_buffer[source_1], tile_buffer[source_2], mix_factor); ``` **Encoding** When using a large textures or large seam margins this table can grow large and reduce performance as data retrieval is slower, than the operations it has to perform. To improve the performance we encode the table so less data retrieval needs to be done. * first `DeltaCopyPixelCommand` is delta encoded from `CopyPixelGroup#start_destination` and `start_source_1`. The others are delta encoded from the previous `DeltaCopyPixelCommand`. * For performance reasons PixelCopyGroup#pixels are ordered from destination (left to right) for each row a new group would be created as the delta encoding most likely doesn't fit. When pixels cannot be delta encoded a new group will also be created. **Compression rate** When using Suzanne the compression rate is around 36% when using a seam margin of 4 pixels. The compression rate may vary depending on seam margin and model. For Suzanne the compression rate was around 36% for various resolutions. | Resolution | Margin | Decoded size | Encoded size | Compression | | ---------- | ------ | ------------ | ------------ | ----------- | | 2048x2048 | 4 px | 353.052 | 128.101 | 36% | | 4096x4096 | 4 px | 700.140 | 255.137 | 36% | | 8192x8192 | 4 px | 1.419.320 | 513.802 | 36% | | 2048x2048 | 8 px | 721.084 | 193.629 | 26% | | 4096x4096 | 8 px | 1.444.968 | 388.110 | 26% |
Jeroen Bakker added 1 commit 2023-03-01 10:37:09 +01:00
Jeroen Bakker added the
Module
Sculpt, Paint & Texture
label 2023-03-01 10:40:54 +01:00
Jeroen Bakker added this to the 3.6 LTS milestone 2023-03-01 10:40:58 +01:00
Jeroen Bakker added this to the Sculpt, Paint & Texture project 2023-03-01 10:41:06 +01:00
Jeroen Bakker self-assigned this 2023-03-01 10:41:14 +01:00
Jeroen Bakker added 1 commit 2023-03-01 10:43:06 +01:00
Jeroen Bakker reviewed 2023-03-01 10:52:37 +01:00
@ -248,0 +261,4 @@
/** \name Fix non-manifold edge bleeding.
* \{ */
// TODO: move to image wrappers?
Author
Member

These TODO's should be fixed or removed.

These TODO's should be fixed or removed.
Jeroen-Bakker marked this conversation as resolved
Hans Goudey changed title from Texture Painting: Fix Seam Bleeding of Non-Manifold Sections of Mesh. to Texture Painting: Fix Seam Bleeding of Non-Manifold Sections of Mesh 2023-03-01 18:05:54 +01:00
Jeroen Bakker added 2 commits 2023-03-09 15:39:59 +01:00
Jeroen Bakker added 1 commit 2023-03-09 15:42:42 +01:00
Jeroen Bakker added 1 commit 2023-03-09 15:47:20 +01:00
Jeroen Bakker merged commit b0037c5c6b into main 2023-03-09 16:11:14 +01:00
Jeroen Bakker deleted branch 3dtexturing-fix-seam-bleeding-non-manifold 2023-03-09 16:11:15 +01:00
Julien Kaspar removed this from the Sculpt, Paint & Texture project 2023-04-18 14:44:46 +02:00
Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#105336
No description provided.