Cleanup: Organize Sculpt Paint brush related variables

Moves related variables that are only used by the paint brush into the
existing `paint_brush` anonymous `struct` & removes the `hardness`
property from said `struct` as it is used by most brushes and not just
the paint brush.

Pull Request: https://projects.blender.org/blender/blender/pulls/126712
This commit is contained in:
Sean Kim
2024-08-27 03:38:24 +02:00
committed by Sean Kim
parent 2c2b6009c1
commit b2b1e8e7df
5 changed files with 45 additions and 43 deletions

View File

@@ -157,7 +157,7 @@ static void sample_node_surface_mesh(const Depsgraph &depsgraph,
const MutableSpan<float> distances = tls.distances;
calc_brush_distances(ss, positions, eBrushFalloffShape(brush.falloff_shape), distances);
filter_distances_with_radius(radius, distances, factors);
apply_hardness_to_distances(radius, cache.paint_brush.hardness, distances);
apply_hardness_to_distances(radius, cache.hardness, distances);
BKE_brush_calc_curve_factors(
eBrushCurvePreset(brush.curve_preset), brush.curve, distances, radius, factors);
@@ -200,7 +200,7 @@ static void sample_node_surface_grids(const Depsgraph &depsgraph,
const MutableSpan<float> distances = tls.distances;
calc_brush_distances(ss, positions, eBrushFalloffShape(brush.falloff_shape), distances);
filter_distances_with_radius(radius, distances, factors);
apply_hardness_to_distances(radius, cache.paint_brush.hardness, distances);
apply_hardness_to_distances(radius, cache.hardness, distances);
BKE_brush_calc_curve_factors(
eBrushCurvePreset(brush.curve_preset), brush.curve, distances, radius, factors);
@@ -245,7 +245,7 @@ static void sample_node_surface_bmesh(const Depsgraph &depsgraph,
const MutableSpan<float> distances = tls.distances;
calc_brush_distances(ss, positions, eBrushFalloffShape(brush.falloff_shape), distances);
filter_distances_with_radius(radius, distances, factors);
apply_hardness_to_distances(radius, cache.paint_brush.hardness, distances);
apply_hardness_to_distances(radius, cache.hardness, distances);
BKE_brush_calc_curve_factors(
eBrushCurvePreset(brush.curve_preset), brush.curve, distances, radius, factors);

View File

@@ -272,7 +272,7 @@ void apply_hardness_to_distances(float radius, float hardness, MutableSpan<float
inline void apply_hardness_to_distances(const StrokeCache &cache,
const MutableSpan<float> distances)
{
apply_hardness_to_distances(cache.radius, cache.paint_brush.hardness, distances);
apply_hardness_to_distances(cache.radius, cache.hardness, distances);
}
/**

View File

@@ -4474,11 +4474,11 @@ static void brush_delta_update(const Depsgraph &depsgraph,
static void cache_paint_invariants_update(StrokeCache &cache, const Brush &brush)
{
cache.paint_brush.hardness = brush.hardness;
cache.hardness = brush.hardness;
if (brush.paint_flags & BRUSH_PAINT_HARDNESS_PRESSURE) {
cache.paint_brush.hardness *= brush.paint_flags & BRUSH_PAINT_HARDNESS_PRESSURE_INVERT ?
1.0f - cache.pressure :
cache.pressure;
cache.hardness *= brush.paint_flags & BRUSH_PAINT_HARDNESS_PRESSURE_INVERT ?
1.0f - cache.pressure :
cache.pressure;
}
cache.paint_brush.flow = brush.flow;

View File

@@ -173,6 +173,7 @@ struct StrokeCache {
*/
bool invert;
float pressure;
float hardness;
/**
* Depending on the mode, can either be the raw brush strength, or a scaled (possibly negative)
* value.
@@ -189,13 +190,6 @@ struct StrokeCache {
/* Position of the mouse event in screen space, not modified by the stroke type. */
float2 mouse_event;
/**
* Used by the color attribute paint brush tool to store the brush color during a stroke and
* composite it over the original color.
*/
Array<float4> mix_colors;
Array<float4> prev_colors;
GArray<> prev_colors_vpaint;
/* Multires Displacement Smear. */
@@ -264,11 +258,21 @@ struct StrokeCache {
/* Paint Brush. */
struct {
float hardness;
float flow;
float4 wet_mix_prev_color;
float wet_mix;
float wet_persistence;
float density_seed;
float density;
/**
* Used by the color attribute paint brush tool to store the brush color during a stroke and
* composite it over the original color.
*/
Array<float4> mix_colors;
Array<float4> prev_colors;
} paint_brush;
/* Pose brush */
@@ -327,9 +331,6 @@ struct StrokeCache {
float4x4 stroke_local_mat;
float multiplane_scrape_angle;
float4 wet_mix_prev_color;
float density_seed;
rcti previous_r; /* previous redraw rectangle */
rcti current_r; /* current redraw rectangle */

View File

@@ -398,7 +398,8 @@ static void do_paint_brush_task(const Depsgraph &depsgraph,
const float density = ss.cache->paint_brush.density;
if (density < 1.0f) {
for (const int i : verts.index_range()) {
const float hash_noise = float(BLI_hash_int_01(ss.cache->density_seed * 1000 * verts[i]));
const float hash_noise = float(
BLI_hash_int_01(ss.cache->paint_brush.density_seed * 1000 * verts[i]));
if (hash_noise > density) {
const float noise = density * hash_noise;
factors[i] *= noise;
@@ -536,7 +537,7 @@ void do_paint_brush(const Depsgraph &depsgraph,
if (SCULPT_stroke_is_first_brush_step_of_symmetry_pass(*ss.cache)) {
if (SCULPT_stroke_is_first_brush_step(*ss.cache)) {
ss.cache->density_seed = float(BLI_hash_int_01(ss.cache->location[0] * 1000));
ss.cache->paint_brush.density_seed = float(BLI_hash_int_01(ss.cache->location[0] * 1000));
}
return;
}
@@ -631,18 +632,18 @@ void do_paint_brush(const Depsgraph &depsgraph,
wet_color = math::clamp(swptd.color / float(swptd.tot_samples), 0.0f, 1.0f);
if (ss.cache->first_time) {
ss.cache->wet_mix_prev_color = wet_color;
ss.cache->paint_brush.wet_mix_prev_color = wet_color;
}
blend_color_interpolate_float(wet_color,
wet_color,
ss.cache->wet_mix_prev_color,
ss.cache->paint_brush.wet_mix_prev_color,
ss.cache->paint_brush.wet_persistence);
ss.cache->wet_mix_prev_color = math::clamp(wet_color, 0.0f, 1.0f);
ss.cache->paint_brush.wet_mix_prev_color = math::clamp(wet_color, 0.0f, 1.0f);
}
}
if (ss.cache->mix_colors.is_empty()) {
ss.cache->mix_colors = Array<float4>(mesh.verts_num, float4(0));
if (ss.cache->paint_brush.mix_colors.is_empty()) {
ss.cache->paint_brush.mix_colors = Array<float4>(mesh.verts_num, float4(0));
}
threading::EnumerableThreadSpecific<ColorPaintLocalData> all_tls;
@@ -661,7 +662,7 @@ void do_paint_brush(const Depsgraph &depsgraph,
wet_color,
*nodes[i],
tls,
ss.cache->mix_colors,
ss.cache->paint_brush.mix_colors,
color_attribute);
}
});
@@ -796,7 +797,7 @@ static void do_smear_brush_task(const Depsgraph &depsgraph,
continue;
}
const float4 &neighbor_color = ss.cache->prev_colors[neighbor_neighbor];
const float4 &neighbor_color = ss.cache->paint_brush.prev_colors[neighbor_neighbor];
float color_interp = -math::dot(current_disp_norm, vertex_disp_norm);
/* Square directional weight to get a somewhat sharper result. */
@@ -813,7 +814,7 @@ static void do_smear_brush_task(const Depsgraph &depsgraph,
float4 col = color_vert_get(
faces, corner_verts, vert_to_face_map, color_attribute.span, color_attribute.domain, vert);
blend_color_interpolate_float(col, ss.cache->prev_colors[vert], accum, factors[i]);
blend_color_interpolate_float(col, ss.cache->paint_brush.prev_colors[vert], accum, factors[i]);
color_vert_set(faces,
corner_verts,
vert_to_face_map,
@@ -850,16 +851,16 @@ void do_smear_brush(const Depsgraph &depsgraph,
return;
}
if (ss.cache->prev_colors.is_empty()) {
ss.cache->prev_colors = Array<float4>(mesh.verts_num);
if (ss.cache->paint_brush.prev_colors.is_empty()) {
ss.cache->paint_brush.prev_colors = Array<float4>(mesh.verts_num);
threading::parallel_for(IndexRange(mesh.verts_num), 1024, [&](const IndexRange range) {
for (const int vert : range) {
ss.cache->prev_colors[vert] = color_vert_get(faces,
corner_verts,
vert_to_face_map,
color_attribute.span,
color_attribute.domain,
vert);
ss.cache->paint_brush.prev_colors[vert] = color_vert_get(faces,
corner_verts,
vert_to_face_map,
color_attribute.span,
color_attribute.domain,
vert);
}
});
}
@@ -892,12 +893,12 @@ void do_smear_brush(const Depsgraph &depsgraph,
threading::parallel_for(nodes.index_range(), 1, [&](const IndexRange range) {
for (const int i : range) {
for (const int vert : bke::pbvh::node_unique_verts(*nodes[i])) {
ss.cache->prev_colors[vert] = color_vert_get(faces,
corner_verts,
vert_to_face_map,
color_attribute.span,
color_attribute.domain,
vert);
ss.cache->paint_brush.prev_colors[vert] = color_vert_get(faces,
corner_verts,
vert_to_face_map,
color_attribute.span,
color_attribute.domain,
vert);
}
}
});