GPv3: Populate part of the buffer data #109093

Merged
Falk David merged 21 commits from casey-bianco-davis/blender:GPv3-populate-buffer-data into main 2024-01-19 11:47:10 +01:00
3 changed files with 33 additions and 7 deletions

View File

@ -80,7 +80,7 @@ void legacy_gpencil_frame_to_grease_pencil_drawing(const bGPDframe &gpf,
SpanAttributeWriter<float> stroke_hardnesses = attributes.lookup_or_add_for_write_span<float>(
"hardness", AttrDomain::Curve);
SpanAttributeWriter<float> stroke_point_aspect_ratios =
attributes.lookup_or_add_for_write_span<float>("point_aspect_ratio", AttrDomain::Curve);
attributes.lookup_or_add_for_write_span<float>("aspect_ratio", AttrDomain::Curve);
SpanAttributeWriter<float2> stroke_fill_translations =
attributes.lookup_or_add_for_write_span<float2>("fill_translation", AttrDomain::Curve);
SpanAttributeWriter<float> stroke_fill_rotations =

View File

@ -54,12 +54,21 @@ vec3 gpencil_lighting(void)
return clamp(light_accum, 0.0, 1e10);
}
vec4 debug_texture(vec2 uv)
{
vec4 col = vec4(mod(uv.xy, 1.0), 0.0, 1.0);
return col * min(length(uv.xy * 2 - 1), 1);
}
void main()
{
vec4 col;
if (flag_test(gp_interp_flat.mat_flag, GP_STROKE_TEXTURE_USE)) {
bool premul = flag_test(gp_interp_flat.mat_flag, GP_STROKE_TEXTURE_PREMUL);
col = texture_read_as_linearrgb(gpStrokeTexture, premul, gp_interp.uv);
/* Debug color. (Because textures are not yet implemented) */
col = debug_texture(gp_interp.uv);
}
else if (flag_test(gp_interp_flat.mat_flag, GP_FILL_TEXTURE_USE)) {
bool use_clip = flag_test(gp_interp_flat.mat_flag, GP_FILL_TEXTURE_CLIP);

View File

@ -488,13 +488,22 @@ static void grease_pencil_geom_batch_ensure(Object &object,
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);
/* 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);
const VArray<int8_t> start_caps = *attributes.lookup_or_default<int8_t>(
"start_cap", bke::AttrDomain::Curve, GP_STROKE_CAP_TYPE_ROUND);
const VArray<int8_t> end_caps = *attributes.lookup_or_default<int8_t>(
"end_cap", bke::AttrDomain::Curve, GP_STROKE_CAP_TYPE_ROUND);
"end_cap", bke::AttrDomain::Curve, 0);
const VArray<float> stroke_hardnesses = *attributes.lookup_or_default<float>(
"hardness", bke::AttrDomain::Curve, 1.0f);
const VArray<float> stroke_point_aspect_ratios = *attributes.lookup_or_default<float>(
"aspect_ratio", bke::AttrDomain::Curve, 1.0f);
const VArray<ColorGeometry4f> stroke_fill_colors =
*attributes.lookup_or_default<ColorGeometry4f>(
"fill_color", bke::AttrDomain::Curve, ColorGeometry4f(0.0f, 0.0f, 0.0f, 0.0f));
const VArray<int> materials = *attributes.lookup_or_default<int>(
"material_index", bke::AttrDomain::Curve, 0);
const VArray<float> hardness = *attributes.lookup_or_default<float>(
@ -506,12 +515,15 @@ static void grease_pencil_geom_batch_ensure(Object &object,
const IndexMask visible_strokes = ed::greasepencil::retrieve_visible_strokes(
object, info.drawing, memory);
curves.ensure_evaluated_lengths();
auto populate_point = [&](IndexRange verts_range,
int curve_i,
int8_t start_cap,
int8_t end_cap,
int point_i,
int idx,
float length,
GreasePencilStrokeVert &s_vert,
GreasePencilColorVert &c_vert) {
copy_v3_v3(s_vert.pos, positions[point_i]);
@ -522,15 +534,14 @@ static void grease_pencil_geom_batch_ensure(Object &object,
s_vert.stroke_id = verts_range.first();
s_vert.mat = materials[curve_i] % GPENCIL_MATERIAL_BUFFER_LEN;
/* TODO: Populate rotation and aspect. */
s_vert.packed_asp_hard_rot = pack_rotation_aspect_hardness(0.0f, 1.0f, hardness[curve_i]);
/* TODO: Populate stroke UVs. */
s_vert.u_stroke = 0;
s_vert.packed_asp_hard_rot = pack_rotation_aspect_hardness(
rotations[point_i], stroke_point_aspect_ratios[curve_i], stroke_hardnesses[curve_i]);
s_vert.u_stroke = length;
/* TODO: Populate fill UVs. */
s_vert.uv_fill[0] = s_vert.uv_fill[1] = 0;
copy_v4_v4(c_vert.vcol, vertex_colors[point_i]);
copy_v4_v4(c_vert.fcol, vertex_colors[point_i]);
copy_v4_v4(c_vert.fcol, stroke_fill_colors[curve_i]);
c_vert.fcol[3] = (int(c_vert.fcol[3] * 10000.0f) * 10.0f) + 1.0f;
int v_mat = (verts_range[idx] << GP_VERTEX_ID_SHIFT) | GP_IS_STROKE_VERTEX_BIT;
@ -548,6 +559,8 @@ static void grease_pencil_geom_batch_ensure(Object &object,
MutableSpan<GreasePencilStrokeVert> verts_slice = verts.slice(verts_range);
MutableSpan<GreasePencilColorVert> cols_slice = cols.slice(verts_range);
const Span<float> lengths = curves.evaluated_lengths_for_curve(curve_i, is_cyclic);
/* First vertex is not drawn. */
verts_slice.first().mat = -1;
@ -565,24 +578,28 @@ static void grease_pencil_geom_batch_ensure(Object &object,
/* Write all the point attributes to the vertex buffers. Create a quad for each point. */
for (const int i : IndexRange(points.size())) {
const int idx = i + 1;
const float length = (i >= 1) ? lengths[i - 1] : 0.0f;
populate_point(verts_range,
curve_i,
start_caps[curve_i],
end_caps[curve_i],
points[i],
idx,
length,
verts_slice[idx],
cols_slice[idx]);
}
if (is_cyclic) {
const int idx = points.size() + 1;
const float length = lengths[points.size() - 1];
populate_point(verts_range,
curve_i,
start_caps[curve_i],
end_caps[curve_i],
points[0],
idx,
length,
verts_slice[idx],
cols_slice[idx]);
}