GPv3: Render evaluated geometry

This allows Grease Pencil to render all the different curve types.
The PR changes the batch cache creation to use the evaluated points.

Pull Request: https://projects.blender.org/blender/blender/pulls/122985
This commit is contained in:
Casey Bianco-Davis
2024-07-22 11:10:07 +02:00
committed by Falk David
parent a0799ac295
commit 73338c1553
4 changed files with 35 additions and 13 deletions

View File

@@ -377,9 +377,9 @@ Span<uint3> Drawing::triangles() const
};
this->runtime->triangles_cache.ensure([&](Vector<uint3> &r_data) {
const CurvesGeometry &curves = this->strokes();
const Span<float3> positions = curves.positions();
const Span<float3> positions = curves.evaluated_positions();
const Span<float3> normals = this->curve_plane_normals();
const OffsetIndices<int> points_by_curve = curves.points_by_curve();
const OffsetIndices<int> points_by_curve = curves.evaluated_points_by_curve();
int total_triangles = 0;
Array<int> tris_offests(curves.curves_num());

View File

@@ -716,7 +716,7 @@ static GPENCIL_tObject *grease_pencil_object_cache_populate(GPENCIL_PrivateData
const Layer &layer = *layers[info.layer_index];
const bke::CurvesGeometry &curves = info.drawing.strokes();
const OffsetIndices<int> points_by_curve = curves.points_by_curve();
const OffsetIndices<int> points_by_curve = curves.evaluated_points_by_curve();
const bke::AttributeAccessor attributes = curves.attributes();
const VArray<bool> cyclic = *attributes.lookup_or_default<bool>(
"cyclic", bke::AttrDomain::Curve, false);

View File

@@ -313,7 +313,7 @@ static void OVERLAY_outline_grease_pencil(OVERLAY_PrivateData *pd, Scene *scene,
DRW_shgroup_buffer_texture(grp, "gp_col_tx", color_tx);
const bke::CurvesGeometry &curves = info.drawing.strokes();
const OffsetIndices<int> points_by_curve = curves.points_by_curve();
const OffsetIndices<int> points_by_curve = curves.evaluated_points_by_curve();
const bke::AttributeAccessor attributes = curves.attributes();
const VArray<int> stroke_materials = *attributes.lookup_or_default<int>(
"material_index", bke::AttrDomain::Curve, 0);

View File

@@ -1034,6 +1034,18 @@ static void grease_pencil_edit_batch_ensure(Object &object,
cache->is_dirty = false;
}
template<typename T>
static VArray<T> attribute_interpolate(const VArray<T> &input, const bke::CurvesGeometry &curves)
{
if (curves.is_single_type(CURVE_TYPE_POLY)) {
return input;
}
Array<T> out(curves.evaluated_points_num());
curves.interpolate_to_evaluated(VArraySpan(input), out.as_mutable_span());
return VArray<T>::ForContainer(std::move(out));
};
static void grease_pencil_geom_batch_ensure(Object &object,
const GreasePencil &grease_pencil,
const Scene &scene)
@@ -1064,7 +1076,7 @@ static void grease_pencil_geom_batch_ensure(Object &object,
Vector<Array<int>> tris_start_offsets_per_visible_drawing;
for (const ed::greasepencil::DrawingInfo &info : drawings) {
const bke::CurvesGeometry &curves = info.drawing.strokes();
const OffsetIndices<int> points_by_curve = curves.points_by_curve();
const OffsetIndices<int> points_by_curve = curves.evaluated_points_by_curve();
const VArray<bool> cyclic = curves.cyclic();
IndexMaskMemory memory;
const IndexMask visible_strokes = ed::greasepencil::retrieve_visible_strokes(
@@ -1138,16 +1150,26 @@ static void grease_pencil_geom_batch_ensure(Object &object,
const float4x4 layer_space_to_object_space = layer.to_object_space(object);
const float4x4 object_space_to_layer_space = math::invert(layer_space_to_object_space);
const bke::CurvesGeometry &curves = info.drawing.strokes();
if (curves.evaluated_points_num() == 0) {
continue;
}
const bke::AttributeAccessor attributes = curves.attributes();
const OffsetIndices<int> points_by_curve = curves.points_by_curve();
const Span<float3> positions = curves.positions();
const OffsetIndices<int> points_by_curve = curves.evaluated_points_by_curve();
const Span<float3> positions = curves.evaluated_positions();
const VArray<bool> cyclic = curves.cyclic();
const VArray<float> radii = info.drawing.radii();
const VArray<float> opacities = info.drawing.opacities();
const VArray<ColorGeometry4f> vertex_colors = *attributes.lookup_or_default<ColorGeometry4f>(
"vertex_color", bke::AttrDomain::Point, ColorGeometry4f(0.0f, 0.0f, 0.0f, 0.0f));
const VArray<float> rotations = *attributes.lookup_or_default<float>(
"rotation", bke::AttrDomain::Point, 0.0f);
curves.ensure_can_interpolate_to_evaluated();
const VArray<float> radii = attribute_interpolate<float>(info.drawing.radii(), curves);
const VArray<float> opacities = attribute_interpolate<float>(info.drawing.opacities(), curves);
const VArray<float> rotations = attribute_interpolate<float>(
*attributes.lookup_or_default<float>("rotation", bke::AttrDomain::Point, 0.0f), curves);
const VArray<ColorGeometry4f> vertex_colors = attribute_interpolate<ColorGeometry4f>(
*attributes.lookup_or_default<ColorGeometry4f>(
"vertex_color", bke::AttrDomain::Point, ColorGeometry4f(0.0f, 0.0f, 0.0f, 0.0f)),
curves);
/* Assumes that if the ".selection" attribute does not exist, all points are selected. */
const VArray<float> selection_float = *attributes.lookup_or_default<float>(
".selection", bke::AttrDomain::Point, true);