forked from blender/blender
Cleanup: Reduce use and scope of templates in vertex paint #2
@ -2981,6 +2981,7 @@ static void do_vpaint_brush_blur_loops(bContext *C,
|
||||
|
||||
to_static_color_type(vpd->type, [&](auto dummy) {
|
||||
using Color = decltype(dummy);
|
||||
// using Traits =
|
||||
using Blend = typename Traits::BlendType;
|
||||
/* Get the average poly color */
|
||||
Color color_final(0, 0, 0, 0);
|
||||
@ -3028,37 +3029,7 @@ static void do_vpaint_brush_blur_loops(bContext *C,
|
||||
}
|
||||
Color color_orig(0, 0, 0, 0); /* unused when array is nullptr */
|
||||
|
||||
if (previous_color != nullptr) {
|
||||
/* Get the previous loop color */
|
||||
if (isZero(previous_color[l_index])) {
|
||||
previous_color[l_index] = lcol[l_index];
|
||||
}
|
||||
}
|
||||
|
||||
if (total_hit_loops == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Use rgb^2 color averaging. */
|
||||
Color *col = &;
|
||||
|
||||
color_final.r = Traits::round(sqrtf(Traits::divide_round(blend[0], total_hit_loops)));
|
||||
color_final.g = Traits::round(sqrtf(Traits::divide_round(blend[1], total_hit_loops)));
|
||||
color_final.b = Traits::round(sqrtf(Traits::divide_round(blend[2], total_hit_loops)));
|
||||
color_final.a = Traits::round(sqrtf(Traits::divide_round(blend[3], total_hit_loops)));
|
||||
|
||||
/* For each poly owning this vert,
|
||||
* paint each loop belonging to this vert. */
|
||||
for (const int j : gmap->vert_to_poly[v_index].index_range()) {
|
||||
const int p_index = gmap->vert_to_poly[v_index][j];
|
||||
const int l_index = gmap->vert_to_loop[v_index][j];
|
||||
BLI_assert(ss->corner_verts[l_index] == v_index);
|
||||
if (use_face_sel && !select_poly[p_index]) {
|
||||
continue;
|
||||
}
|
||||
Color color_orig(0, 0, 0, 0); /* unused when array is nullptr */
|
||||
|
||||
if (previous_color != nullptr) {
|
||||
if (!previous_color.is_empty()) {
|
||||
/* Get the previous loop color */
|
||||
if (isZero(previous_color[l_index])) {
|
||||
previous_color[l_index] = lcol[l_index];
|
||||
@ -3069,12 +3040,8 @@ static void do_vpaint_brush_blur_loops(bContext *C,
|
||||
brush_alpha_pressure * grid_alpha;
|
||||
/* Mix the new color with the original
|
||||
* based on the brush strength and the curve. */
|
||||
lcol[l_index] = vpaint_blend<Color, Traits>(vp,
|
||||
lcol[l_index],
|
||||
color_orig,
|
||||
*col,
|
||||
final_alpha,
|
||||
Traits::range * brush_strength);
|
||||
lcol[l_index] = vpaint_blend<Color, Traits>(
|
||||
vp, lcol[l_index], color_orig, *col, final_alpha, Traits::range * brush_strength);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -3144,15 +3111,13 @@ static void do_vpaint_brush_blur_verts(bContext *C,
|
||||
}
|
||||
|
||||
float brush_strength = cache->bstrength;
|
||||
const float angle_cos = (use_normal && vd.no) ?
|
||||
dot_v3v3(sculpt_normal_frontface, vd.no) :
|
||||
const float angle_cos = (use_normal && vd.no) ? dot_v3v3(sculpt_normal_frontface, vd.no) :
|
||||
1.0f;
|
||||
if (!test_brush_angle_falloff(
|
||||
*brush, vpd->normal_angle_precalc, angle_cos, &brush_strength)) {
|
||||
continue;
|
||||
}
|
||||
const float brush_fade = BKE_brush_curve_strength(
|
||||
brush, sqrtf(test.dist), cache->radius);
|
||||
const float brush_fade = BKE_brush_curve_strength(brush, sqrtf(test.dist), cache->radius);
|
||||
|
||||
/* Get the average poly color */
|
||||
to_static_color_type(vpd->type, [&](auto dummy) {
|
||||
@ -3199,7 +3164,7 @@ static void do_vpaint_brush_blur_verts(bContext *C,
|
||||
}
|
||||
Color color_orig(0, 0, 0, 0); /* unused when array is nullptr */
|
||||
|
||||
if (previous_color != nullptr) {
|
||||
if (!previous_color.is_empty()) {
|
||||
/* Get the previous loop color */
|
||||
if (isZero(previous_color[v_index])) {
|
||||
previous_color[v_index] = lcol[v_index];
|
||||
@ -3210,12 +3175,8 @@ static void do_vpaint_brush_blur_verts(bContext *C,
|
||||
brush_alpha_pressure * grid_alpha;
|
||||
/* Mix the new color with the original
|
||||
* based on the brush strength and the curve. */
|
||||
lcol[v_index] = vpaint_blend<Color, Traits>(vp,
|
||||
lcol[v_index],
|
||||
color_orig,
|
||||
*col,
|
||||
final_alpha,
|
||||
Traits::range * brush_strength);
|
||||
lcol[v_index] = vpaint_blend<Color, Traits>(
|
||||
vp, lcol[v_index], color_orig, *col, final_alpha, Traits::range * brush_strength);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -3278,7 +3239,6 @@ static void do_vpaint_brush_smear(bContext *C,
|
||||
|
||||
blender::threading::parallel_for(nodes.index_range(), 1LL, [&](IndexRange range) {
|
||||
for (int n : range) {
|
||||
|
||||
/* For each vertex */
|
||||
PBVHVertexIter vd;
|
||||
BKE_pbvh_vertex_iter_begin (ss->pbvh, nodes[n], vd, PBVH_ITER_UNIQUE) {
|
||||
@ -3301,15 +3261,13 @@ static void do_vpaint_brush_smear(bContext *C,
|
||||
/* Calculate the dot prod. between ray norm on surf and current vert
|
||||
* (ie splash prevention factor), and only paint front facing verts. */
|
||||
float brush_strength = cache->bstrength;
|
||||
const float angle_cos = (use_normal && vd.no) ?
|
||||
dot_v3v3(sculpt_normal_frontface, vd.no) :
|
||||
const float angle_cos = (use_normal && vd.no) ? dot_v3v3(sculpt_normal_frontface, vd.no) :
|
||||
1.0f;
|
||||
if (!test_brush_angle_falloff(
|
||||
*brush, vpd->normal_angle_precalc, angle_cos, &brush_strength)) {
|
||||
continue;
|
||||
}
|
||||
const float brush_fade = BKE_brush_curve_strength(
|
||||
brush, sqrtf(test.dist), cache->radius);
|
||||
const float brush_fade = BKE_brush_curve_strength(brush, sqrtf(test.dist), cache->radius);
|
||||
|
||||
bool do_color = false;
|
||||
/* Minimum dot product between brush direction and current
|
||||
@ -3442,13 +3400,12 @@ static void calculate_average_color(VPaintData *vpd,
|
||||
using Color = decltype(dummy);
|
||||
using Blend = typename Traits::BlendType;
|
||||
|
||||
VPaintAverageAccum<Blend> *accum = (VPaintAverageAccum<Blend> *)MEM_mallocN(
|
||||
sizeof(*accum) * nodes.size(), __func__);
|
||||
Array<VPaintAverageAccum<Blend>> accum(nodes.size());
|
||||
blender::threading::parallel_for(nodes.index_range(), 1LL, [&](IndexRange range) {
|
||||
for (int n : range) {
|
||||
VPaintAverageAccum<Blend> *accum2 = accum + n;
|
||||
accum2->len = 0;
|
||||
memset(accum2->value, 0, sizeof(accum2->value));
|
||||
VPaintAverageAccum<Blend> &accum2 = accum[n];
|
||||
accum2.len = 0;
|
||||
memset(accum2.value, 0, sizeof(accum2.value));
|
||||
|
||||
/* For each vertex */
|
||||
PBVHVertexIter vd;
|
||||
@ -3467,7 +3424,7 @@ static void calculate_average_color(VPaintData *vpd,
|
||||
continue;
|
||||
}
|
||||
|
||||
accum2->len += gmap->vert_to_poly[v_index].size();
|
||||
accum2.len += gmap->vert_to_poly[v_index].size();
|
||||
/* if a vertex is within the brush region, then add its color to the blend. */
|
||||
for (int j = 0; j < gmap->vert_to_poly[v_index].size(); j++) {
|
||||
int elem_index;
|
||||
@ -3482,9 +3439,9 @@ static void calculate_average_color(VPaintData *vpd,
|
||||
Color *col = lcol + elem_index;
|
||||
|
||||
/* Color is squared to compensate the `sqrt` color encoding. */
|
||||
accum2->value[0] += col->r * col->r;
|
||||
accum2->value[1] += col->g * col->g;
|
||||
accum2->value[2] += col->b * col->b;
|
||||
accum2.value[0] += col->r * col->r;
|
||||
accum2.value[1] += col->g * col->g;
|
||||
accum2.value[2] += col->b * col->b;
|
||||
}
|
||||
}
|
||||
BKE_pbvh_vertex_iter_end;
|
||||
@ -3563,6 +3520,8 @@ static void vpaint_do_draw(bContext *C,
|
||||
const float *sculpt_normal_frontface = SCULPT_brush_frontface_normal_from_falloff_shape(
|
||||
ss, brush->falloff_shape);
|
||||
|
||||
const ColorPaint4f paintcol = vpd->paintcol;
|
||||
|
||||
GMutableSpan previous_color = ss->cache->prev_colors_vpaint;
|
||||
|
||||
const blender::VArray<bool> select_vert = *me->attributes().lookup_or_default<bool>(
|
||||
@ -3572,8 +3531,6 @@ static void vpaint_do_draw(bContext *C,
|
||||
|
||||
blender::threading::parallel_for(nodes.index_range(), 1LL, [&](IndexRange range) {
|
||||
for (int n : range) {
|
||||
ColorPaint4f paintcol = vpd->paintcol;
|
||||
|
||||
/* For each vertex */
|
||||
PBVHVertexIter vd;
|
||||
BKE_pbvh_vertex_iter_begin (ss->pbvh, nodes[n], vd, PBVH_ITER_UNIQUE) {
|
||||
@ -3596,15 +3553,13 @@ static void vpaint_do_draw(bContext *C,
|
||||
/* Calc the dot prod. between ray norm on surf and current vert
|
||||
* (ie splash prevention factor), and only paint front facing verts. */
|
||||
float brush_strength = cache->bstrength;
|
||||
const float angle_cos = (use_normal && vd.no) ?
|
||||
dot_v3v3(sculpt_normal_frontface, vd.no) :
|
||||
const float angle_cos = (use_normal && vd.no) ? dot_v3v3(sculpt_normal_frontface, vd.no) :
|
||||
1.0f;
|
||||
if (!test_brush_angle_falloff(
|
||||
*brush, vpd->normal_angle_precalc, angle_cos, &brush_strength)) {
|
||||
continue;
|
||||
}
|
||||
const float brush_fade = BKE_brush_curve_strength(
|
||||
brush, sqrtf(test.dist), cache->radius);
|
||||
const float brush_fade = BKE_brush_curve_strength(brush, sqrtf(test.dist), cache->radius);
|
||||
|
||||
to_static_color_type(vpd->type, [&](auto dummy) {
|
||||
using Color = decltype(dummy);
|
||||
@ -3623,7 +3578,7 @@ static void vpaint_do_draw(bContext *C,
|
||||
if (vpd->domain == ATTR_DOMAIN_POINT) {
|
||||
int v_index = vd.index;
|
||||
|
||||
if (previous_color != nullptr) {
|
||||
if (!previous_color.is_empty()) {
|
||||
/* Get the previous loop color */
|
||||
if (isZero(previous_color[v_index])) {
|
||||
previous_color[v_index] = lcol[v_index];
|
||||
@ -3651,15 +3606,15 @@ static void vpaint_do_draw(bContext *C,
|
||||
}
|
||||
Color color_orig = Color(0, 0, 0, 0); /* unused when array is nullptr */
|
||||
|
||||
if (previous_color != nullptr) {
|
||||
if (!previous_color.is_empty()) {
|
||||
/* Get the previous loop color */
|
||||
if (isZero(previous_color[l_index])) {
|
||||
previous_color[l_index] = lcol[l_index];
|
||||
}
|
||||
color_orig = previous_color[l_index];
|
||||
}
|
||||
const float final_alpha = Traits::frange * brush_fade * brush_strength *
|
||||
tex_alpha * brush_alpha_pressure * grid_alpha;
|
||||
const float final_alpha = Traits::frange * brush_fade * brush_strength * tex_alpha *
|
||||
brush_alpha_pressure * grid_alpha;
|
||||
|
||||
/* Mix the new color with the original based on final_alpha. */
|
||||
lcol[l_index] = vpaint_blend<Color, Traits>(vp,
|
||||
@ -4122,8 +4077,7 @@ bool BKE_object_attributes_active_color_fill(Object *ob,
|
||||
const float fill_color[4],
|
||||
bool only_selected)
|
||||
{
|
||||
return paint_object_attributes_active_color_fill_ex(
|
||||
ob, ColorPaint4f(fill_color), only_selected);
|
||||
return paint_object_attributes_active_color_fill_ex(ob, ColorPaint4f(fill_color), only_selected);
|
||||
}
|
||||
|
||||
static int vertex_color_set_exec(bContext *C, wmOperator * /*op*/)
|
||||
@ -4155,4 +4109,4 @@ void PAINT_OT_vertex_color_set(wmOperatorType *ot)
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
}
|
||||
|
||||
/** \} */
|
||||
/** \} */
|
||||
|
Loading…
Reference in New Issue
Block a user