Page MenuHome

WeightPainting: Drawing
ClosedPublic

Authored by Alexander Gavrilov (angavrilov) on Sep 4 2018, 3:46 PM.

Details

Summary

This is a first patch of two. The first patch will do the weight painting. When that is committed we will do the edit lattice in a second patch.

Moved the weightpaint drawing to the fragment shader. The shader uses a texture that uses the U.cobo custom color band, or internal color band.

New weight paint shader

Diff Detail

Repository
rB Blender
Branch
temp-angavrilov-D3675-wp-shader (branched from blender2.8)
Build Status
Buildable 2114
Build 2114: arc lint + arc unit

Event Timeline

Implementation looks fine but i'm not sure doing the color ramp sampling in the fragment shader is better, because it adds too many color change and can make the user think there is more vertices weighted differently.

I would sample the weight in the vertex shader, convert to linear (for interpolation), then convert back to sRGB in the fragment shader.

source/blender/draw/intern/draw_cache_impl_mesh.c
1158

Why ? default weight is 0 and it's a calloc.

source/blender/draw/modes/paint_weight_mode.c
100

no need for uper case prefix if function is static

107

Bracket style

Checked, +1 to @Clément Foucault (fclem)'s comments.

Interpolating the color band looks nice, perhaps we can get feedback from a rigger here if they think it's useful.

Since it adds color detail where there is no geometry.

Otherwise patch LGTM.

source/blender/draw/modes/paint_weight_mode.c
121

I'm not sure about putting it here. I would prefer to have a ramp texture common to all viewports. There is already a globals_ramp in draw_common.c.

Jeroen Bakker (jbakker) marked 3 inline comments as done.
  • D3675: Weightpaint drawing
Alexander Gavrilov (angavrilov) added inline comments.
source/blender/draw/intern/draw_cache_impl_mesh.c
1136

Why is the code using defvert_find_weight instead of properly reproducing calc_weightpaint_vert_color? This is completely missing support for multipaint and alert color.

To elaborate: alert color is a feature to show points that have weight of exactly 0 (either for the group, or for all groups) in a different color, normally black. Most of the time this is useful for easily detecting mistakes in painting, like an unintended light touch with a brush to a different part of the object, or unclean boundary.

However, for multipaint this is absolutely essential, because it cannot paint at all on vertices where the collective weight is exactly zero. Plus, of course, for multipaint you have to display the collective weight of all selected groups, because that is what it operates on.

Clément Foucault (fclem) requested changes to this revision.Sep 11 2018, 2:50 PM

I think @Alexander Gavrilov (angavrilov) have a point. We should support these corner cases because they are important to the workflow.

Maybe use a special weight value in the VBO and a special case color in the vertex shader.

This revision now requires changes to proceed.Sep 11 2018, 2:50 PM

If I recall, there is a setting somewhere to set the alert color, so it probably should use that. There definitely is an option in the Options menu that selects the operation mode for the alert.

Regarding alert color implementation, a special value like -1 can indeed be used in VBO (provided true weights are clamped to the correct 0-1 range), but the vertex shader should split it into two values: true weight, and alpha-like alert status, and interpolate those. Otherwise you would risk either weird interpolation between a non-zero and alert weight, or being unable to see the alert color if a null vertex is completely surrounded by weighted ones. I.e. alert color is one case where the approach of computing color in the vertex shader and then interpolating seems to be obviously better, and it should be emulated even by the weight in the fragment shader approach.

Regarding multipaint, if something is not clear about how it works, I may be able to help, since rewriting it into something that is actually usable was my first major patch for blender.

Rebased on top of recent changes and added alert color support.

Alexander Gavrilov (angavrilov) marked an inline comment as done.Sep 25 2018, 9:47 PM

Since I introduced changes conflicting with this patch, I decided to update it myself.

source/blender/draw/intern/draw_common.c
945

This color ramp matches the original code, but when it is being continuously interpolated through like in this new drawing approach, it becomes obvious that the color progression is actually not very smooth. For instance the yellow band looks quite sharp and narrow, while green is wide and gradual. I wonder if it is possible to tweak it to achieve a more even flow of colors.

source/blender/draw/modes/paint_weight_mode.c
182

There is very likely a better place to put this color buffer and its initialization code, but I don't know where it is.

Rebased again and added a gamma correction hack to even out the color ramp bands.

Comparison of color ramps. New colors are more dull because of the prior change to multiply and the fact that a truly white material seems to be impossible.

OldNew with wider yellow & cyan

Moved colors to the globals UBO.

Alexander Gavrilov (angavrilov) marked 2 inline comments as done.EditedSep 27 2018, 11:03 AM
OldGamma 1.5Gamma 2.0

And an example of a more complex mesh and weight arrangement than a cube:

This revision is now accepted and ready to land.Sep 27 2018, 4:01 PM
This revision was automatically updated to reflect the committed changes.