GPv3: Opacity modifier #116946
|
@ -79,14 +79,6 @@ static void foreach_ID_link(ModifierData *md, Object *ob, IDWalkFunc walk, void
|
|||
greasepencil::foreach_influence_ID_link(&omd->influence, ob, walk, user_data);
|
||||
}
|
||||
|
||||
/* XXX Placeholder for vertex groupn weights. */
|
||||
static VArray<float> get_grease_pencil_modifier_vertex_weights(
|
||||
const bke::CurvesGeometry &curves, const GreasePencilModifierInfluenceData &influence_data)
|
||||
{
|
||||
const bool use_vertex_group = (influence_data.vertex_group_name[0] != '\0');
|
||||
return VArray<float>::ForSingle(use_vertex_group ? 0.0f : 1.0f, curves.point_num);
|
||||
}
|
||||
|
||||
static void modify_stroke_color(const GreasePencilOpacityModifierData &omd,
|
||||
bke::CurvesGeometry &curves,
|
||||
LukasTonne marked this conversation as resolved
|
||||
const IndexMask &curves_mask)
|
||||
|
@ -97,12 +89,12 @@ static void modify_stroke_color(const GreasePencilOpacityModifierData &omd,
|
|||
GREASE_PENCIL_INFLUENCE_INVERT_VERTEX_GROUP);
|
||||
const bool use_curve = (omd.influence.flag & GREASE_PENCIL_INFLUENCE_USE_CUSTOM_CURVE);
|
||||
const OffsetIndices<int> points_by_curve = curves.points_by_curve();
|
||||
const VArray<float> vgroup_weights = get_grease_pencil_modifier_vertex_weights(curves,
|
||||
omd.influence);
|
||||
|
||||
bke::MutableAttributeAccessor attributes = curves.attributes_for_write();
|
||||
bke::SpanAttributeWriter<float> opacities = attributes.lookup_or_add_for_write_span<float>(
|
||||
"opacity", bke::AttrDomain::Point);
|
||||
const bke::AttributeReader<float> vgroup_weights = attributes.lookup_or_default<float>(
|
||||
omd.influence.vertex_group_name, bke::AttrDomain::Point, 1.0f);
|
||||
LukasTonne marked this conversation as resolved
Outdated
Hans Goudey
commented
Use the * operator overload to just store the VArray directly here Use the * operator overload to just store the VArray directly here
|
||||
|
||||
for (const int64_t i : curves_mask.index_range()) {
|
||||
const int64_t curve_i = curves_mask[i];
|
||||
|
@ -121,14 +113,14 @@ static void modify_stroke_color(const GreasePencilOpacityModifierData &omd,
|
|||
}
|
||||
else if (use_weight_as_factor) {
|
||||
/* Use vertex group weights as opacity factors. */
|
||||
const float vgroup_weight = vgroup_weights[point_i];
|
||||
const float vgroup_weight = vgroup_weights.varray[point_i];
|
||||
const float point_factor = vgroup_weight;
|
||||
opacities.span[point_i] = std::clamp(
|
||||
omd.color_factor * curve_factor * point_factor, 0.0f, 1.0f);
|
||||
}
|
||||
else {
|
||||
/* Use vertex group weights as influence factors. */
|
||||
const float vgroup_weight = vgroup_weights[point_i];
|
||||
const float vgroup_weight = vgroup_weights.varray[point_i];
|
||||
const float vgroup_influence = invert_vertex_group ? 1.0f - vgroup_weight : vgroup_weight;
|
||||
opacities.span[point_i] = std::clamp(
|
||||
LukasTonne marked this conversation as resolved
Outdated
Pratik Borhade
commented
remove this and pass remove this and pass `vgroup_weight` to clamp fn? 😅
Lukas Tönne
commented
Haha yeah, this is the result of me trying to make sense of the logic of the old modifier. Haha yeah, this is the result of me trying to make sense of the logic of the old modifier.
|
||||
opacities.span[point_i] + omd.color_factor * curve_factor * vgroup_influence - 1.0f,
|
||||
|
@ -149,13 +141,13 @@ static void modify_fill_color(const GreasePencilOpacityModifierData &omd,
|
|||
const bool invert_vertex_group = (omd.influence.flag &
|
||||
GREASE_PENCIL_INFLUENCE_INVERT_VERTEX_GROUP);
|
||||
const OffsetIndices<int> points_by_curve = curves.points_by_curve();
|
||||
const VArray<float> vgroup_weights = get_grease_pencil_modifier_vertex_weights(curves,
|
||||
omd.influence);
|
||||
|
||||
bke::MutableAttributeAccessor attributes = curves.attributes_for_write();
|
||||
/* Fill color opacity per stroke. */
|
||||
bke::SpanAttributeWriter<float> fill_opacities = attributes.lookup_or_add_for_write_span<float>(
|
||||
"fill_opacity", bke::AttrDomain::Curve);
|
||||
bke::AttributeReader<float> vgroup_weights = attributes.lookup_or_default<float>(
|
||||
omd.influence.vertex_group_name, bke::AttrDomain::Point, 1.0f);
|
||||
|
||||
for (const int64_t i : curves_mask.index_range()) {
|
||||
const int64_t curve_i = curves_mask[i];
|
||||
|
@ -163,8 +155,9 @@ static void modify_fill_color(const GreasePencilOpacityModifierData &omd,
|
|||
if (use_vgroup_opacity) {
|
||||
/* Use the first stroke point as vertex weight. */
|
||||
const IndexRange points_range = points_by_curve[curve_i];
|
||||
const float stroke_weight = points_range.is_empty() ? 1.0f :
|
||||
vgroup_weights[points_range.first()];
|
||||
const float stroke_weight = points_range.is_empty() ?
|
||||
1.0f :
|
||||
vgroup_weights.varray[points_range.first()];
|
||||
const float stroke_influence = invert_vertex_group ? 1.0f - stroke_weight : stroke_weight;
|
||||
|
||||
fill_opacities.span[curve_i] = std::clamp(stroke_influence, 0.0f, 1.0f);
|
||||
|
|
Loading…
Reference in New Issue
You should just be able to retrieve the vertex group as an attribute
Took some explaining from @filedescriptor how this works (maybe a good topic for technical docs?). As far as i understand the
VArray
wrapper for thecurves->deform_verts()
is ok here, since we're only using a single vertex group. For something like the armature modifier i'd guess we still want to use theMDeformVert
directly.Right, exactly