Add support for pixels in PBVH #96710

Closed
opened 2022-03-22 16:09:49 +01:00 by Jeroen Bakker · 4 comments
Member

PBVH is an accelleration structure blender uses internally to speed up 3d painting operations.
At this moment it is extensively used by sculpt, vertex painting and weight painting.

For the 3d texturing brush we will be using the PBVH for texture painting.
Currently PBVH is organized to work on geometry (vertices, polygons and triangles).
For texture painting this should be extended to use pixels.

Next to PBVH_Leaf there will be an additional node type (PBVH_Pixels)

  • PBVH_Pixels is always a subnode of PBVH_Leaf or the PBVH_Leaf node in case the leaf doesn't need to split.

Rasterization process

The rasterization process will generate the PBVH_Pixels for a leaf node. In order to do so every polygon should be uniquely assigned to a leaf node.

For each leaf node
   for each polygon
     If polygon not assigned
       assign polygon to node.

Polygons are too complicated to be used directly we have to split the polygons into triangles.

For each leaf node
  for each polygon
    extract triangles from polygon.

The list of triangles can be stored inside the leaf node. The list of polygons aren't needed anymore.
Each triangle has:

  • poly_index.
  • vert_indices
  • delta barycentric coordinate between x steps.
  • factor (factor propogated from automasking/front faces/... functionality, to quickly detect if this triangle actually has influence to the end result).

Each triangle can be rasterized and each row of pixels can be stored in a structure containing

  • image position
  • barycentric coordinate of the first pixel
  • number of pixels
  • triangle index inside the leaf node.

Data can be encoded to reduce memory needs.

  • Only need to store 2 barycentric components. The third can be calculated from the 2 stored.

Depending on the number of pixels the node will be split.

There are several ways when the pixels should be recalculated:

  • Image resolution changes.
  • UDIM tiles changes
  • UVMap changes
  • Geometry changes
  • ...

Pixels are ordered by UDIM tiles, image buffer y coordinate, image buffer x coordinate. The range of a pixels per UDIM tile are stored along side the pixels.

Rasterization

During the performed experiments we use a fairly simple rasterization process by finding the UV bounds of an triangle and calculate the barycentric coordinates per pixel inside the bounds.
Even for complex models and huge images this process is normally finished within 0.5 second. It could be that we want to change this algorithm to reduce hickups when nodes are initialized during a stroke.

Testing

For testing purposes an initial implementation of a texturing paint brush will be implemented. This will only be available via an experimental feature flag.

Compression

If needed the list of pixels can be compressed as they are always accessed sequential. We should only do this if there is actually a memory issue we want to solve. For compression
we can think of variable size delta compression. Due to the ordering the image positions could be stored into 4-8 bits for a lot of cases.

PBVH is an accelleration structure blender uses internally to speed up 3d painting operations. At this moment it is extensively used by sculpt, vertex painting and weight painting. For the 3d texturing brush we will be using the PBVH for texture painting. Currently PBVH is organized to work on geometry (vertices, polygons and triangles). For texture painting this should be extended to use pixels. Next to `PBVH_Leaf` there will be an additional node type (`PBVH_Pixels`) * `PBVH_Pixels` is always a subnode of `PBVH_Leaf` or the PBVH_Leaf node in case the leaf doesn't need to split. ## Rasterization process The rasterization process will generate the PBVH_Pixels for a leaf node. In order to do so every polygon should be uniquely assigned to a leaf node. ``` For each leaf node for each polygon If polygon not assigned assign polygon to node. ``` Polygons are too complicated to be used directly we have to split the polygons into triangles. ``` For each leaf node for each polygon extract triangles from polygon. ``` The list of triangles can be stored inside the leaf node. The list of polygons aren't needed anymore. Each triangle has: * poly_index. * vert_indices * delta barycentric coordinate between x steps. * factor (factor propogated from automasking/front faces/... functionality, to quickly detect if this triangle actually has influence to the end result). Each triangle can be rasterized and each row of pixels can be stored in a structure containing * image position * barycentric coordinate of the first pixel * number of pixels * triangle index inside the leaf node. Data can be encoded to reduce memory needs. * Only need to store 2 barycentric components. The third can be calculated from the 2 stored. Depending on the number of pixels the node will be split. There are several ways when the pixels should be recalculated: * Image resolution changes. * UDIM tiles changes * UVMap changes * Geometry changes * ... Pixels are ordered by UDIM tiles, image buffer y coordinate, image buffer x coordinate. The range of a pixels per UDIM tile are stored along side the pixels. # Rasterization During the performed experiments we use a fairly simple rasterization process by finding the UV bounds of an triangle and calculate the barycentric coordinates per pixel inside the bounds. Even for complex models and huge images this process is normally finished within 0.5 second. It could be that we want to change this algorithm to reduce hickups when nodes are initialized during a stroke. # Testing For testing purposes an initial implementation of a texturing paint brush will be implemented. This will only be available via an experimental feature flag. # Compression If needed the list of pixels can be compressed as they are always accessed sequential. We should only do this if there is actually a memory issue we want to solve. For compression we can think of variable size delta compression. Due to the ordering the image positions could be stored into 4-8 bits for a lot of cases.
Author
Member

Changed status from 'Needs Triage' to: 'Confirmed'

Changed status from 'Needs Triage' to: 'Confirmed'
Author
Member

Added subscriber: @Jeroen-Bakker

Added subscriber: @Jeroen-Bakker
Jeroen Bakker self-assigned this 2022-04-08 16:17:35 +02:00

This issue was referenced by e96a809a68

This issue was referenced by e96a809a68ef40225d5eddfd790644538e171a8d
Author
Member

Changed status from 'Confirmed' to: 'Resolved'

Changed status from 'Confirmed' to: 'Resolved'
Sign in to join this conversation.
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
2 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#96710
No description provided.