Fix T72092: Clay Strips Brush stroke crash with Brush Detail Size

Some other areas in the brush code outside sculpt mode assume that
pressure is multiplied directly on top of the initial size. This patch
calculates the pixel radius correctly using the brush size from sculpt
mode to get the dyntopo detail size.
When the new brush input system is in place, all these values will come
directly from the brush input code with all the custom curves applied
per brush, so all paint modes will have a correct brush behavior and all
this sculpt mode specific code won't be necessary.

Reviewed By: jbakker

Maniphest Tasks: T72092

Differential Revision: https://developer.blender.org/D6339
This commit is contained in:
Pablo Dobarro 2019-12-01 20:29:11 +01:00
parent 40e2f4469a
commit 448669a630
Notes: blender-bot 2023-02-14 05:41:57 +01:00
Referenced by issue #72092, Clay Strips Brush stroke crash Blender 2.82
4 changed files with 11 additions and 7 deletions

View File

@ -335,6 +335,7 @@ static bool paint_brush_update(bContext *C,
ups->size_pressure_value = stroke->cached_size_pressure;
ups->pixel_radius = BKE_brush_size_get(scene, brush);
ups->initial_pixel_radius = BKE_brush_size_get(scene, brush);
if (BKE_brush_use_size_pressure(brush) && paint_supports_dynamic_size(brush, mode)) {
ups->pixel_radius *= stroke->cached_size_pressure;

View File

@ -6730,11 +6730,12 @@ static void sculpt_update_cache_variants(bContext *C, Sculpt *sd, Object *ob, Po
if (BKE_brush_use_size_pressure(brush) &&
paint_supports_dynamic_size(brush, PAINT_MODE_SCULPT)) {
cache->radius = sculpt_brush_dynamic_size_get(brush, cache, cache->initial_radius);
cache->dyntopo_radius = cache->initial_radius * cache->pressure;
cache->dyntopo_pixel_radius = sculpt_brush_dynamic_size_get(
brush, cache, ups->initial_pixel_radius);
}
else {
cache->radius = cache->initial_radius;
cache->dyntopo_radius = cache->initial_radius;
cache->dyntopo_pixel_radius = ups->initial_pixel_radius;
}
cache->radius_squared = cache->radius * cache->radius;
@ -7345,12 +7346,11 @@ static void sculpt_stroke_update_step(bContext *C,
BKE_pbvh_bmesh_detail_size_set(ss->pbvh, object_space_constant_detail);
}
else if (sd->flags & SCULPT_DYNTOPO_DETAIL_BRUSH) {
BKE_pbvh_bmesh_detail_size_set(ss->pbvh,
ss->cache->dyntopo_radius * sd->detail_percent / 100.0f);
BKE_pbvh_bmesh_detail_size_set(ss->pbvh, ss->cache->radius * sd->detail_percent / 100.0f);
}
else {
BKE_pbvh_bmesh_detail_size_set(ss->pbvh,
(ss->cache->dyntopo_radius / (float)ups->pixel_radius) *
(ss->cache->radius / ss->cache->dyntopo_pixel_radius) *
(float)(sd->detail_size * U.pixelsize) / 0.4f);
}

View File

@ -319,8 +319,8 @@ typedef struct StrokeCache {
float location[3];
float last_location[3];
/* This radius variable is not affected by pressure curves */
float dyntopo_radius;
/* Original pixel radius with the pressure curve applied for dyntopo detail size */
float dyntopo_pixel_radius;
bool is_last_valid;

View File

@ -1277,6 +1277,9 @@ typedef struct UnifiedPaintSettings {
/* radius of brush, premultiplied with pressure.
* In case of anchored brushes contains the anchored radius */
float pixel_radius;
float initial_pixel_radius;
char _pad[4];
/* drawing pressure */
float size_pressure_value;