diff options
author | Hans Goudey <h.goudey@me.com> | 2022-05-23 10:44:12 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2022-05-23 10:44:12 +0300 |
commit | 8f3847aef3f21d9c2cc549c783ea2ce708ec3161 (patch) | |
tree | c5da9af3865a4d90c1466c47e0f3787edb2e4d3a /source/blender/editors/sculpt_paint/curves_sculpt_snake_hook.cc | |
parent | f93b2371942b3da34a9e827b163e2324e254c625 (diff) |
Fix: Sample pressure properly for 3D curves sculpt brushes
For the "Sphere" 3D brushes, the depth and radius are only sampled at
the beginning of the stroke. This didn't work when tablet pressure is
used as a factor for the brush radius. Now the 3D brush depth is found
with the max radius (as if the pressure was 1.0), but the pressure
factor is used afterwards.
Restructuring the way the brush executors stored the radius made
the change a bit clearer, which is where most of the diff comes from.
Differential Revision: https://developer.blender.org/D15002
Diffstat (limited to 'source/blender/editors/sculpt_paint/curves_sculpt_snake_hook.cc')
-rw-r--r-- | source/blender/editors/sculpt_paint/curves_sculpt_snake_hook.cc | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/source/blender/editors/sculpt_paint/curves_sculpt_snake_hook.cc b/source/blender/editors/sculpt_paint/curves_sculpt_snake_hook.cc index 4095c9427e1..bcdeaaeabf2 100644 --- a/source/blender/editors/sculpt_paint/curves_sculpt_snake_hook.cc +++ b/source/blender/editors/sculpt_paint/curves_sculpt_snake_hook.cc @@ -80,8 +80,10 @@ struct SnakeHookOperatorExecutor { const CurvesSculpt *curves_sculpt_ = nullptr; const Brush *brush_ = nullptr; - float brush_radius_re_; + float brush_radius_base_re_; + float brush_radius_factor_; float brush_strength_; + eBrushFalloffShape falloff_shape_; Object *object_ = nullptr; @@ -112,8 +114,11 @@ struct SnakeHookOperatorExecutor { curves_sculpt_ = scene_->toolsettings->curves_sculpt; brush_ = BKE_paint_brush_for_read(&curves_sculpt_->paint); - brush_radius_re_ = brush_radius_get(*scene_, *brush_, stroke_extension); + + brush_radius_base_re_ = BKE_brush_size_get(scene_, brush_); + brush_radius_factor_ = brush_radius_factor(*brush_, stroke_extension); brush_strength_ = brush_strength_get(*scene_, *brush_, stroke_extension); + falloff_shape_ = static_cast<eBrushFalloffShape>(brush_->falloff_shape); curves_to_world_mat_ = object_->obmat; @@ -132,7 +137,7 @@ struct SnakeHookOperatorExecutor { if (stroke_extension.is_first) { if (falloff_shape_ == PAINT_FALLOFF_SHAPE_SPHERE) { std::optional<CurvesBrush3D> brush_3d = sample_curves_3d_brush( - *depsgraph_, *region_, *v3d_, *rv3d_, *object_, brush_pos_re_, brush_radius_re_); + *depsgraph_, *region_, *v3d_, *rv3d_, *object_, brush_pos_re_, brush_radius_base_re_); if (brush_3d.has_value()) { self_->brush_3d_ = *brush_3d; } @@ -174,6 +179,9 @@ struct SnakeHookOperatorExecutor { float4x4 projection; ED_view3d_ob_project_mat_get(rv3d_, object_, projection.values); + const float brush_radius_re = brush_radius_base_re_ * brush_radius_factor_; + const float brush_radius_sq_re = pow2f(brush_radius_re); + threading::parallel_for(curves_->curves_range(), 256, [&](const IndexRange curves_range) { for (const int curve_i : curves_range) { const IndexRange points = curves_->points_for_curve(curve_i); @@ -183,13 +191,14 @@ struct SnakeHookOperatorExecutor { float2 old_pos_re; ED_view3d_project_float_v2_m4(region_, old_pos_cu, old_pos_re, projection.values); - const float distance_to_brush_re = math::distance(old_pos_re, brush_pos_prev_re_); - if (distance_to_brush_re > brush_radius_re_) { + const float distance_to_brush_sq_re = math::distance_squared(old_pos_re, + brush_pos_prev_re_); + if (distance_to_brush_sq_re > brush_radius_sq_re) { continue; } const float radius_falloff = BKE_brush_curve_strength( - brush_, distance_to_brush_re, brush_radius_re_); + brush_, std::sqrt(distance_to_brush_sq_re), brush_radius_re); const float weight = brush_strength_ * radius_falloff; const float2 new_position_re = old_pos_re + brush_pos_diff_re_ * weight; @@ -222,7 +231,7 @@ struct SnakeHookOperatorExecutor { const float3 brush_start_cu = world_to_curves_mat_ * brush_start_wo; const float3 brush_end_cu = world_to_curves_mat_ * brush_end_wo; - const float brush_radius_cu = self_->brush_3d_.radius_cu; + const float brush_radius_cu = self_->brush_3d_.radius_cu * brush_radius_factor_; const Vector<float4x4> symmetry_brush_transforms = get_symmetry_brush_transforms( eCurvesSymmetryType(curves_id_->symmetry)); |