This design task describes the implementation and possible features that the PBVH_TEXTURE would provide.
Everything described here is something that could work “in theory”. I can’t guarantee that I will be able to implement all the necessary steps of this project or if all functionality described here is going to be possible.
The PBVH_TEXTURE is an attempt to modernize the current Blender texture painting tools as well as to provide new functionality that is currently not possible to code with the current texture painting code.
The same way we have PBVH_MESH, PBVH_BMESH and PBVH_GRIDS, the idea is to add a new type PBVH_TEXTURE. The PBVH_TEXTURE will build the tree out of the 3D coordinates of each texture pixel after being UV mapped in the model.
When iterating over vertices, the PBVH iterators should iterate over all pixels in that node instead. As they are already UV mapped and its position calculated in 3D space to build the tree, this vd iterator can also provide its 3D location, normal (the normal of the face in which they are contained), a static index (trivial to calculate on a image) and neighbors (easy to calculate in some cases, it may require doing some proximity searching across the seams when building the tree). Any of the data necessary to cover all PBVH functionality should be easy to add (the sculpt mask, for example), as we are just dealing with a static matrix of pixels.
Thanks to all the changes made in 2.81 with the sculpt API and refactor of the tools, it should be possible to fully implement this API and run the entire sculpt mode code to write data directly to textures.
- Unified Painting System: With the PBVH_TEXTURE and after merging the Sculpt Vertex Colors patch, Sculpt Mode, Texture paint and Vertex Paint will run on the exact same code, which means less code to maintain and all the new painting features will be available in the 3 modes (masking, symmetry, brush parameters...) with a single implementation.
- After merging Sculpt Vertex Colors, the new brush engine with all its improvements and brushes will be also compatible with Texture Paint. This will bring to texture paint all features users requested for a long time, like 3D spherical falloff, no projection artifacts, wet painting, the new cursor.
- The same paint brushes will be compatible with Vertex Paint and Texture Paint, and its behavior will be identical. This will also allow to share code in other areas of Blender, like the brushes previews or the brush management system.
Texture Displacement Sculpting
Probably the most important feature that the PBVH_TEXTURE will bring is the ability to use all the features from Sculpt Mode to sculpt displacement directly to displacement textures or normal maps.
For some workflows this is a huge improvement. Game artist that rely on high poly sculpts and baking tools to create details in assets for game engines won’t need any of that anymore. They will be able to use a fully feature sculpting system to add the detail to the textures of the model directly.
This is obviously going to fail and create a lot of artifacts if the sculpted deformation is too big, but that is not the initial idea (that is also going to fail if the the high res sculpt and the low res mesh shape differ too much). The idea is to avoid using high poly sculpts to add surface detail when it is not necessary, and for surface detail, this approach should work fine.
I can’t evaluate the performance of this sculpting mode, but if we add UDIM support to the PBVH_TEXTURE (should not be hard to do, specially if we don’t support faces across different UDIM tiles) and the performance is OK, it could potentially allow to sculpt surface detail on models with a much higher resolution than any other solution based on mesh geometry and vertex deformation.
To implement this, the idea is to add a second buffer that stores the vectors to get the “deformed” 3D coordinates, and its normals. When iterating over the vertices in PBVH_ITER_BEGIN, the vd.co will be calculated by using the original 3D position of the vertex + displacement vector stored in the buffer. It should be possible to write this information to the texture to get a displacement texture and it should also be possible to write the normals calculated when the PBVH_UpdateNormals flag is processed to get a normal map.
- I’m still not sure how this is going to work across seams. I think that if we add some extra padding pixels to the node which contains that face as if we were extending the face in 3D space it should be fine, but hard to know without trying it.
- I’m also not sure what kind of performance we can expect out of this, but even if performance is not the best, we can still try to code it to support some of its features, like sculpting information to the textures.
Sculpt Vertex Colors needs to be merged first to begin this project.
Milestone 1: Basic painting
After this milestone it should be possible to test painting in PBVH_TEXTURE and have an initial idea on how it will work (performance, texture painting artifacts...).
- Crete the code that builds the PBVH from the 3D coordinates of the pixels
- Add UVs and texture rendering support to the PBVH code in GPU_buffers
- Implement the PBVH_ITER_BEGIN iterator and the sculpt API
Milestone 2: Initial Sculpting Work
After this milestone, it should be possible to run all the sculpt tools using the PBVH_TEXTURE. Masking tools should work also for painting, but sculpting tools won’t produce any effect.
- Implement undo for PBVH_TEXTURE
- Add the mask datalayer to the PBVH_TEXTURE
- Implement the neighbor iterator in the sculpt API
Milestone 3: Texture Displacment Sculpting
After this milestone, it should be possible to create vector displacement textures and normal maps with sculpt mode
- Implement the deformed coordinates buffer and the normal map/vector displacement calculations
- Update the Sculpt API to read data from the coordinates buffer
- Add the Sculpt Mode UI to support textures
- Add normal map/displacement support to workbench (If possible, we can use EEVEE instead if that is hard to do)