Fix #117338: Texture paint sampling broken with modifiers #120259

Merged
Hans Goudey merged 4 commits from HooglyBoogly/blender:fix-texture-paint-sample into main 2024-04-05 14:17:53 +02:00
Member

e64b3c8212 worked to complete a transition started during 2.8
development to avoid dynamically re-evaluating objects outside of the
dependency graph's control. However, that behavior was used to make
sure the original index mapping was available for the texture paint
sample operator.

Conceptually, sampling a texture on an arbitrary evaluated mesh should
not require original indices at all. All we need to know is the UV map
value under the mouse. This commit changes from using GPU index textures
to a BVH tree raycast. This significantly simplifies the code and makes
it work with GPU subdivision too. Though it may be slower to build the
BVH tree, that should be okay because it's cached and only needs to be
built once, and that's something we're want to optimize anyway.

Removing the reliance on original indices also means we could paint
textures on completely procedurally generated meshes, which may be
an interesting feature in the future.

e64b3c821252fc8707b4 worked to complete a transition started during 2.8 development to avoid dynamically re-evaluating objects outside of the dependency graph's control. However, that behavior was used to make sure the original index mapping was available for the texture paint sample operator. Conceptually, sampling a texture on an arbitrary evaluated mesh should not require original indices at all. All we need to know is the UV map value under the mouse. This commit changes from using GPU index textures to a BVH tree raycast. This significantly simplifies the code and makes it work with GPU subdivision too. Though it may be slower to build the BVH tree, that should be okay because it's cached and only needs to be built once, and that's something we're want to optimize anyway. Removing the reliance on original indices also means we could paint textures on completely procedurally generated meshes, which may be an interesting feature in the future.
Hans Goudey added 1 commit 2024-04-04 17:15:46 +02:00
buildbot/vexp-code-patch-lint Build done. Details
buildbot/vexp-code-patch-linux-x86_64 Build done. Details
buildbot/vexp-code-patch-darwin-x86_64 Build done. Details
buildbot/vexp-code-patch-windows-amd64 Build done. Details
buildbot/vexp-code-patch-darwin-arm64 Build done. Details
buildbot/vexp-code-patch-coordinator Build done. Details
6bde217966
Fix #117338: Texture paint sampling broken with modifiers
e64b3c8212 worked to complete a transition started during 2.8
development to avoid dynamically re-evaluating objects outside of the
dependency graph's control. However, that behavior was used to make
sure the original index mapping was available for the texture paint
sample operator.

Conceptually, sampling a texture on an arbitrary evaluated mesh should
not require original indices at all though. All we need to know is the
UV map value under the mouse. This commit changes from using GPU index
textures to a BVH tree raycast. This significantly simplifies the code
and makes it work with GPU subdivision too. Though it may be slower to
build the BVH tree, that should be okay because it's cached and only
needs to be built once, and that's something we're looking to optimize
in the future anyway.

Removing the reliance on original indices also means we could paint
textures on completely procedurally generated meshes, which may be
an interesting feature in the future.
Author
Member

@blender-bot build

@blender-bot build
Hans Goudey requested review from Sergey Sharybin 2024-04-04 17:16:37 +02:00
Author
Member

Some performance numbers with a 6 million face mesh (AFAIK that's a very high resolution for texture painting workflows):

  • For the first sampling operation, creating the BVH tree took 1.2s.
  • The whole sample function only takes a few ms more than that
  • Every subsequent sample operation takes less than a millisecond

For a 400k face mesh, creating the BVH tree took 57ms.

The BVH tree build time is a bit longer than I'd like. However, this method doesn't require reevaluating the object to add the original index layer. Considering that could be arbitrarily slow, overall I like this tradeoff. Especially given the possibility of texture painting on procedural objects without original indices in the future. Switching to a different BVH tree implementation (as investigated in #108148) would significantly improve the BVH tree build performance too.


I also realized a change like #119977 might be used to solve this too. But it doesn't remove the complexity of finding the UV within the sampled face. So I still think the approach in this PR is preferable.

Some performance numbers with a 6 million face mesh (AFAIK that's a very high resolution for texture painting workflows): - For the first sampling operation, creating the BVH tree took 1.2s. - The whole sample function only takes a few ms more than that - Every subsequent sample operation takes less than a millisecond For a 400k face mesh, creating the BVH tree took 57ms. The BVH tree build time is a bit longer than I'd like. However, this method doesn't require reevaluating the object to add the original index layer. Considering that could be arbitrarily slow, overall I like this tradeoff. Especially given the possibility of texture painting on procedural objects without original indices in the future. Switching to a different BVH tree implementation (as investigated in #108148) would significantly improve the BVH tree build performance too. --- I also realized a change like #119977 might be used to solve this too. But it doesn't remove the complexity of finding the UV within the sampled face. So I still think the approach in this PR is preferable.
Hans Goudey added 1 commit 2024-04-04 18:51:42 +02:00
Sergey Sharybin approved these changes 2024-04-05 13:01:15 +02:00
Sergey Sharybin left a comment
Owner

It seems to work quite well, and did not see anything obvious in the functional part of the code. There is some weird comment, which i think could just be removed now.

I could not test GPU subdivision case, as I do not think it is supported on macOS.

As for the approach, I think it is clearer if we stick to a CPU only solution, rather than mixing the old approach with some computationally intense parts done on CPU and some other stuff done on GPU.

Marking as a green, so that it can go in as soon as the inlined comment is looked into and possibly addressed.

It seems to work quite well, and did not see anything obvious in the functional part of the code. There is some weird comment, which i think could just be removed now. I could not test GPU subdivision case, as I do not think it is supported on macOS. As for the approach, I think it is clearer if we stick to a CPU only solution, rather than mixing the old approach with some computationally intense parts done on CPU and some other stuff done on GPU. Marking as a green, so that it can go in as soon as the inlined comment is looked into and possibly addressed.
@ -293,4 +216,4 @@
const int *material_indices = (const int *)CustomData_get_layer_named(
&mesh_eval->face_data, CD_PROP_INT32, "material_index");
/* test all faces in the derivedmesh with the original index of the picked face */

The comment is out=of-date now, and could be removed?

The comment is out=of-date now, and could be removed?
HooglyBoogly marked this conversation as resolved
Hans Goudey added 2 commits 2024-04-05 14:15:25 +02:00
Hans Goudey merged commit 3ed4e51437 into main 2024-04-05 14:17:53 +02:00
Hans Goudey deleted branch fix-texture-paint-sample 2024-04-05 14:17:55 +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
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#120259
No description provided.