Vector displacement for the sculpting draw brush #104481

Merged
Jeroen Bakker merged 18 commits from robin.hohni/blender:sculpt-vector-displacement into main 2023-02-14 15:29:40 +01:00
Contributor

Sculpt: Added vector displacement for the sculpting draw brush (area plane mapping only for now)

Vector displacement maps (VDM) provide a way to create complex displacements that can have overhangs in one brush dab.
This is unlike standard displacement with height maps that only displace in the normal direction.
Forms like ears, curled horns, etc can be created in one click if VMDs are used.
There is a checkbox on the draw brush in the texture settings "Vector Displacement" that enables/disables this feature.

Technical description: The RGB channels of a texture in a brush stroke are read and interpreted as individual vectors, that are used to offset vertices.
As of now, this is only working for the draw brush using the area plane mapping. Symmetry and radial symmetry are working.


vector displacement applied with symmetry
(vector displacement applied with symmetry)

There are two files attached: The first one a demo scene with a prepared VDM brush. The second is a setup to bake vector displacement maps from a plane, since Blender doesn't support VDM baking directly.

A few things to consider when making VD-Maps:

  • UVs need to stay intact for the bake mesh (e.g. voxel remeshing can't be used to create VD Meshes)
  • When exporting a VD Map it should be in the file format OpenEXR (for positive and negative floating point values).
  • Export resolution can be 512x512 or lower (EXR files can get very large, but VDM brushes don't need a high resolution)

And when using them:

  • Inside Blender clamping needs to be unchecked on the texture
  • The brush falloff should be set to constant (or nearly constant)

This patch was inspired by this right-click-select proposal Thanks for the post!

(Moved this patch to here.)

Sculpt: Added vector displacement for the sculpting draw brush (area plane mapping only for now) Vector displacement maps (VDM) provide a way to create complex displacements that can have overhangs in one brush dab. This is unlike standard displacement with height maps that only displace in the normal direction. Forms like ears, curled horns, etc can be created in one click if VMDs are used. There is a checkbox on the draw brush in the texture settings "Vector Displacement" that enables/disables this feature. Technical description: The RGB channels of a texture in a brush stroke are read and interpreted as individual vectors, that are used to offset vertices. As of now, this is only working for the draw brush using the area plane mapping. Symmetry and radial symmetry are working. --------------------------------------------------------------------------------------- ![vector displacement applied with symmetry](https://archive.blender.org/developer/file/14183/14183285/blender_TkZIuJChIz.gif) (vector displacement applied with symmetry) There are two files attached: The first one a demo scene with a prepared VDM brush. The second is a setup to bake vector displacement maps from a plane, since Blender doesn't support VDM baking directly. A few things to consider when making VD-Maps: * UVs need to stay intact for the bake mesh (e.g. voxel remeshing can't be used to create VD Meshes) * When exporting a VD Map it should be in the file format OpenEXR (for positive and negative floating point values). * Export resolution can be 512x512 or lower (EXR files can get very large, but VDM brushes don't need a high resolution) And when using them: * Inside Blender clamping needs to be unchecked on the texture * The brush falloff should be set to constant (or nearly constant) --- This patch was inspired by this [right-click-select proposal](https://blender.community/c/rightclickselect/WqWx/) Thanks for the post! (Moved [this patch](https://archive.blender.org/developer/D17080) to here.)
Robin Hohnsbeen added 12 commits 2023-02-08 19:45:54 +01:00
ce08bff6f0 Sculpt: Added vector displacement for sculpting draw brush (area plane method only for now)
Vector displacement maps (VDM) provide a way to create complex displacements that can have overhangs in one brush dab.
This is unlike standard displacement with height maps that only displace in normal direction.
Forms like ears, curled horns, etc can be created in one click if VMDs are used.

This patch reads the RGB channels of a texture in a brush stroke and interprets them as individual vectors, that are used for the vertex offset.
As of now, this is only working for the draw brush using the area plane method. Symmetry and radial symmetry is working.
02b958e9af Sculpt: Store inverse of brush_local_mat beforehand so it won't be calculated for every displaced vertex
Brush_local_mat_inv is needed to transform vectors of a vertex displacement map back to object space.
01c579db54 Sculpt: Added vector displacement for sculpting draw brush (area plane method only for now)
Vector displacement maps (VDM) provide a way to create complex displacements that can have overhangs in one brush dab.
This is unlike standard displacement with height maps that only displace in normal direction.
Forms like ears, curled horns, etc can be created in one click if VMDs are used.

This patch reads the RGB channels of a texture in a brush stroke and interprets them as individual vectors, that are used for the vertex offset.
As of now, this is only working for the draw brush using the area plane method. Symmetry and radial symmetry is working.

Sculpt: Store inverse of brush_local_mat beforehand so it won't be calculated for every displaced vertex

Brush_local_mat_inv is needed to transform vectors of a vertex displacement map back to object space.

Sculpt: Added hint in tooltip that vector displacement works only with area plane mapping

Differential Revision: https://developer.blender.org/D17080
Author
Contributor

Marked as WIP since I need to address a few things:

  • a bug when using inversion on the brush
  • problems when changing the size of the vdm
Marked as WIP since I need to address a few things: * a bug when using inversion on the brush * problems when changing the size of the vdm
Robin Hohnsbeen closed this pull request 2023-02-08 19:55:48 +01:00
Robin Hohnsbeen reopened this pull request 2023-02-08 19:55:55 +01:00
Robin Hohnsbeen requested review from Jeroen Bakker 2023-02-08 19:56:40 +01:00
Robin Hohnsbeen requested review from Julien Kaspar 2023-02-08 19:56:51 +01:00
Robin Hohnsbeen changed title from WIP: sculpt-vector-displacement to WIP: Vector displacement for the sculpting draw brush 2023-02-08 19:57:33 +01:00
Jeroen Bakker reviewed 2023-02-08 20:37:50 +01:00
Jeroen Bakker left a comment
Member

Code wise seems fine. I still need to investigate the Apple issue.

Code wise seems fine. I still need to investigate the Apple issue.
@ -1144,0 +1146,4 @@
col.active = tex_slot.map_mode == 'AREA_PLANE'
col.prop(brush, "use_color_as_displacement", text="Vector Displacement")
Member

Python has some rules about the number of lines between statements. Here it is max 1.

Python has some rules about the number of lines between statements. Here it is max 1.
Jeroen-Bakker marked this conversation as resolved
Julien Kaspar added the
Module
Sculpt, Paint & Texture
label 2023-02-09 10:47:21 +01:00
Julien Kaspar added the
Type
Patch
label 2023-02-09 10:48:41 +01:00
Robin Hohnsbeen added 1 commit 2023-02-09 21:58:43 +01:00
Jeroen Bakker reviewed 2023-02-10 08:02:09 +01:00
@ -2902,0 +2902,4 @@
prop = RNA_def_property(srna, "use_color_as_displacement", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag2", BRUSH_USE_COLOR_AS_DISPLACEMENT);
RNA_def_property_ui_text(prop, "Vector Displacement",
"Handles each pixel color as individual vector for displacement. Works only with area plane mapping");
Member

Can you ensure that you use the correct code formatting. You can install clang-format or run make format in the source folder.

Can you ensure that you use the correct code formatting. You can install clang-format or run `make format` in the source folder.
robin.hohni marked this conversation as resolved
Robin Hohnsbeen added 1 commit 2023-02-10 20:13:30 +01:00
Robin Hohnsbeen added 1 commit 2023-02-10 20:30:42 +01:00
121cca227e Merge branch 'main' into sculpt-vector-displacement
# Conflicts:
#	source/blender/editors/sculpt_paint/sculpt_intern.hh
Robin Hohnsbeen added 1 commit 2023-02-10 20:46:05 +01:00
Author
Contributor

Fixed the brush inversion and size of vdm texture works as expected

Fixed the brush inversion and size of vdm texture works as expected
Robin Hohnsbeen added 1 commit 2023-02-10 20:57:41 +01:00
Robin Hohnsbeen changed title from WIP: Vector displacement for the sculpting draw brush to Vector displacement for the sculpting draw brush 2023-02-10 20:57:48 +01:00
Author
Contributor

Removed the WIP status since the patch seems good from my end as a first working version of VDM sculpting

Removed the WIP status since the patch seems good from my end as a first working version of VDM sculpting
Julien Kaspar approved these changes 2023-02-11 12:48:12 +01:00
Julien Kaspar left a comment
Member

All my notes are addressed. I couldn't find any more relevant issues for this PR.

All my notes are addressed. I couldn't find any more relevant issues for this PR.
Jeroen Bakker requested changes 2023-02-13 08:30:18 +01:00
Jeroen Bakker left a comment
Member

Just a small improvement, the rest seems fine so should be able to be added this week.

Just a small improvement, the rest seems fine so should be able to be added this week.
@ -2656,0 +2723,4 @@
rgba[1] *= -1;
}
rgba[0] *= 1.0f /
Member

For readability would suggest to first square the size, and then do the inf check using math::safe_divide. Seems we currently don't have a safe divide in math for 2 vector types.

rgba[i] *= math::safe_divide(1.0f, POW2(brush->mtex.size[i])); perhaps?

For readability would suggest to first square the size, and then do the inf check using `math::safe_divide`. Seems we currently don't have a safe divide in math for 2 vector types. `rgba[i] *= math::safe_divide(1.0f, POW2(brush->mtex.size[i]));` perhaps?
Author
Contributor

Thanks for the hint! Made a commit :)

Thanks for the hint! Made a commit :)
robin.hohni marked this conversation as resolved
Brecht Van Lommel added this to the Sculpt, Paint & Texture project 2023-02-13 09:21:25 +01:00
Robin Hohnsbeen added 1 commit 2023-02-13 09:36:14 +01:00
Jeroen Bakker approved these changes 2023-02-13 09:47:01 +01:00
Member

We had a short chat with @brecht to see if there are reasons to post-pone this patch.

  • This patch can land in Blender 3.5.
  • The clamping for new texture data-blocks will be turned off. It was unknown if texture painting or color attribute painting already took care of clamping. This is the case so we expect no issues by changing the default.
  • Other workflow improvements can be prioritized for the 3.6 and further.

Thanks for your work and patience.

We had a short chat with @brecht to see if there are reasons to post-pone this patch. * This patch can land in Blender 3.5. * The clamping for new texture data-blocks will be turned off. It was unknown if texture painting or color attribute painting already took care of clamping. This is the case so we expect no issues by changing the default. * Other workflow improvements can be prioritized for the 3.6 and further. Thanks for your work and patience.
Jeroen Bakker merged commit 39f63c8c08 into main 2023-02-14 15:29:40 +01:00
First-time contributor

Hello! Faced the problem of baking the VDM card. I follow all the instructions, but my texture when sculpting does not match the result.

The screenshot shows your brush and next to it is my sculpting and the result of baking and applying.

Hello! Faced the problem of baking the VDM card. I follow all the instructions, but my texture when sculpting does not match the result. The screenshot shows your brush and next to it is my sculpting and the result of baking and applying.
414 KiB
Member

@vkragize, please use appropriate channels for support. For now it seems you're looking for support how to use the VDM bake node tree, what isn't code related. If it is a bug inside Blender code base please add a bug report.

@vkragize, please use appropriate channels for support. For now it seems you're looking for support how to use the VDM bake node tree, what isn't code related. If it is a bug inside Blender code base please add a bug report.
Julien Kaspar removed this from the Sculpt, Paint & Texture project 2023-04-11 11:38:02 +02:00
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
4 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#104481
No description provided.