Fix #135313: Grease Pencil: Layer adjustments get applied repeatedly during playback

The issue was that during playback, the evaluated Grease Pencil ID
is not being copied again for re-evaluation. This meant that the
adjustments get re-applied over and over again.

Ideally, we would restore the drawing pointers before modifiying them
again, but this is a bit trickier to implement.

To fix this issue for now, we do the layer adjustments during object
data evaluation. Using the geometry set for modifier evaluation
means that we copy the data and apply the adjustments for every
object.

In the future this can be optimized to only happen once per
Grease Pencil ID (in `BKE_grease_pencil_eval_geometry`).

Pull Request: https://projects.blender.org/blender/blender/pulls/135387
This commit is contained in:
Falk David
2025-03-03 14:09:06 +01:00
committed by Falk David
parent 60e4b0e5d0
commit c24b540400

View File

@@ -2240,13 +2240,6 @@ void BKE_grease_pencil_eval_geometry(Depsgraph *depsgraph, GreasePencil *grease_
grease_pencil->runtime->eval_frame = int(DEG_get_ctime(depsgraph));
/* This will remove layers that aren't visible. */
grease_pencil_evaluate_layers(*grease_pencil);
/* The layer adjustments for tinting and radii offsets are applied before modifier evaluation.
* This ensures that the evaluated geometry contains the modifications. In the future, it would
* be better to move these into modifiers. For now, these are hardcoded. */
const bke::AttributeAccessor layer_attributes = grease_pencil->attributes();
if (layer_attributes.contains("tint_color") || layer_attributes.contains("radius_offset")) {
grease_pencil_do_layer_adjustments(*grease_pencil);
}
}
void BKE_object_eval_grease_pencil(Depsgraph *depsgraph, Scene *scene, Object *object)
@@ -2259,6 +2252,13 @@ void BKE_object_eval_grease_pencil(Depsgraph *depsgraph, Scene *scene, Object *o
GreasePencil *grease_pencil = static_cast<GreasePencil *>(object->data);
GeometrySet geometry_set = GeometrySet::from_grease_pencil(grease_pencil,
GeometryOwnershipType::ReadOnly);
/* The layer adjustments for tinting and radii offsets are applied before modifier evaluation.
* This ensures that the evaluated geometry contains the modifications. In the future, it would
* be better to move these into modifiers. For now, these are hardcoded. */
const bke::AttributeAccessor layer_attributes = grease_pencil->attributes();
if (layer_attributes.contains("tint_color") || layer_attributes.contains("radius_offset")) {
grease_pencil_do_layer_adjustments(*geometry_set.get_grease_pencil_for_write());
}
/* Only add the edit hint component in modes where users can potentially interact with deformed
* drawings. */
if (ELEM(object->mode,