Merge branch 'blender-v4.3-release'

# Conflicts:
#	source/blender/draw/engines/overlay/overlay_next_curve.hh
#	source/blender/draw/engines/overlay/shaders/infos/overlay_edit_mode_info.hh
This commit is contained in:
Clément Foucault
2024-10-21 19:19:35 +02:00
7 changed files with 59 additions and 1 deletions

View File

@@ -65,6 +65,7 @@ void OVERLAY_edit_grease_pencil_cache_init(OVERLAY_Data *vedata)
OVERLAY_PrivateData *pd = vedata->stl->pd;
const DRWContextState *draw_ctx = DRW_context_state_get();
const bool use_weight = (draw_ctx->object_mode & OB_MODE_WEIGHT_GREASE_PENCIL) != 0;
View3D *v3d = draw_ctx->v3d;
GPUShader *sh;
DRWShadingGroup *grp;
@@ -96,6 +97,8 @@ void OVERLAY_edit_grease_pencil_cache_init(OVERLAY_Data *vedata)
DRW_shgroup_uniform_bool_copy(grp, "useWeight", use_weight);
DRW_shgroup_uniform_bool_copy(grp, "useGreasePencil", true);
DRW_shgroup_uniform_texture(grp, "weightTex", G_draw.weight_ramp);
const bool show_direction = (v3d->gp_flag & V3D_GP_SHOW_STROKE_DIRECTION) != 0;
DRW_shgroup_uniform_bool_copy(grp, "doStrokeEndpoints", show_direction);
}
else {
pd->edit_grease_pencil_points_grp = nullptr;

View File

@@ -90,6 +90,7 @@ class Curves {
sub.bind_texture("weightTex", &res.weight_ramp_tx);
sub.push_constant("useWeight", false);
sub.push_constant("useGreasePencil", false);
sub.push_constant("doStrokeEndpoints", false);
sub.push_constant("curveHandleDisplay", int(state.overlay.handle_display));
edit_curves_points_ = ⊂
}
@@ -142,6 +143,8 @@ class Curves {
sub.bind_ubo("globalsBlock", &res.globals_buf);
sub.push_constant("showCurveHandles", state.overlay.handle_display != CURVE_HANDLE_NONE);
sub.push_constant("curveHandleDisplay", int(state.overlay.handle_display));
sub.push_constant("useGreasePencil", false);
sub.push_constant("doStrokeEndpoints", false);
edit_legacy_curve_points_ = ⊂
}
}

View File

@@ -58,6 +58,7 @@ class GreasePencil {
const bke::AttrDomain selection_domain_edit = ED_grease_pencil_edit_selection_domain_get(ts);
const bool show_edit_point = selection_domain_edit == bke::AttrDomain::Point;
const bool show_lines = (v3d->gp_flag & V3D_GP_SHOW_EDIT_LINES);
const bool show_direction = (v3d->gp_flag & V3D_GP_SHOW_STROKE_DIRECTION);
show_points_ = show_lines_ = show_weight_ = false;
@@ -106,6 +107,7 @@ class GreasePencil {
sub.bind_texture("weightTex", &res.weight_ramp_tx);
sub.push_constant("useWeight", show_weight_);
sub.push_constant("useGreasePencil", true);
sub.push_constant("doStrokeEndpoints", show_direction);
edit_points_ = ⊂
}

View File

@@ -49,6 +49,7 @@ void OVERLAY_edit_particle_cache_init(OVERLAY_Data *vedata)
DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
DRW_shgroup_uniform_bool_copy(grp, "useWeight", false);
DRW_shgroup_uniform_bool_copy(grp, "useGreasePencil", false);
DRW_shgroup_uniform_bool_copy(grp, "doStrokeEndpoints", false);
}
void OVERLAY_edit_particle_cache_populate(OVERLAY_Data *vedata, Object *ob)

View File

@@ -926,6 +926,11 @@ SAMPLER(0, FLOAT_1D, weightTex)
PUSH_CONSTANT(BOOL, useWeight)
PUSH_CONSTANT(BOOL, useGreasePencil)
FRAGMENT_OUT(0, VEC4, fragColor)
#if 1 /* TODO(fclem): Required for legacy gpencil overlay. To be moved to specialized shader. */
TYPEDEF_SOURCE("gpencil_shader_shared.h")
VERTEX_IN(3, UINT, vflag)
PUSH_CONSTANT(BOOL, doStrokeEndpoints)
#endif
VERTEX_SOURCE("overlay_edit_particle_point_vert.glsl")
FRAGMENT_SOURCE("overlay_point_varying_color_frag.glsl")
ADDITIONAL_INFO(draw_mesh)

View File

@@ -41,6 +41,7 @@ void main()
vec3 world_pos = point_object_to_world(pos);
gl_Position = point_world_to_ndc(world_pos);
float end_point_size_factor = 1.0f;
if (useWeight) {
finalColor = vec4(weight_to_rgb(selection), 1.0);
@@ -48,10 +49,26 @@ void main()
else {
vec4 use_color = useGreasePencil ? colorGpencilVertexSelect : colorVertexSelect;
finalColor = mix(colorWire, use_color, selection);
#if 1 /* Should be checking CURVES_POINT */
if (doStrokeEndpoints) {
bool is_stroke_start = (vflag & GP_EDIT_STROKE_START) != 0u;
bool is_stroke_end = (vflag & GP_EDIT_STROKE_END) != 0u;
if (is_stroke_start) {
end_point_size_factor *= 2.0;
finalColor.rgb = vec3(0.0, 1.0, 0.0);
}
else if (is_stroke_end) {
end_point_size_factor *= 1.5;
finalColor.rgb = vec3(1.0, 0.0, 0.0);
}
}
#endif
}
float vsize = useGreasePencil ? sizeVertexGpencil : sizeVertex;
gl_PointSize = vsize * 2.0;
gl_PointSize = vsize * 2.0 * end_point_size_factor;
view_clipping_distances(world_pos);
}

View File

@@ -50,6 +50,8 @@ struct GreasePencilBatchCache {
gpu::VertBuf *edit_points_pos;
/* Selection of original points. */
gpu::VertBuf *edit_points_selection;
/* vflag of original points. */
gpu::VertBuf *edit_points_vflag;
/* Indices of visible points. */
gpu::IndexBuf *edit_points_indices;
@@ -664,6 +666,14 @@ static void index_buf_add_bezier_line_points(Object &object,
*r_drawing_start_offset += bezier_points.size() * 2;
}
/* Still use legacy vflag for GPv3 for now due to common shader defines. */
#define GREASE_PENCIL_EDIT_POINT_SELECTED (1 << 0)
#define GREASE_PENCIL_EDIT_STROKE_SELECTED (1 << 1)
#define GREASE_PENCIL_EDIT_MULTIFRAME (1 << 2)
#define GREASE_PENCIL_EDIT_STROKE_START (1 << 3)
#define GREASE_PENCIL_EDIT_STROKE_END (1 << 4)
#define GREASE_PENCIL_EDIT_POINT_DIMMED (1 << 5)
static void grease_pencil_edit_batch_ensure(Object &object,
const GreasePencil &grease_pencil,
const Scene &scene)
@@ -702,6 +712,11 @@ static void grease_pencil_edit_batch_ensure(Object &object,
&format_edit_points_selection, "selection", GPU_COMP_F32, 1, GPU_FETCH_FLOAT);
}
static GPUVertFormat format_edit_points_vflag = {0};
if (format_edit_points_vflag.attr_len == 0) {
GPU_vertformat_attr_add(&format_edit_points_vflag, "vflag", GPU_COMP_U32, 1, GPU_FETCH_INT);
}
static GPUVertFormat format_edit_line_selection = {0};
if (format_edit_line_selection.attr_len == 0) {
GPU_vertformat_attr_add(
@@ -712,6 +727,7 @@ static void grease_pencil_edit_batch_ensure(Object &object,
cache->edit_points_pos = GPU_vertbuf_create_with_format_ex(format_edit_points_pos, vbo_flag);
cache->edit_points_selection = GPU_vertbuf_create_with_format_ex(format_edit_points_selection,
vbo_flag);
cache->edit_points_vflag = GPU_vertbuf_create_with_format_ex(format_edit_points_vflag, vbo_flag);
cache->edit_line_pos = GPU_vertbuf_create_with_format_ex(format_edit_line_pos, vbo_flag);
cache->edit_line_selection = GPU_vertbuf_create_with_format_ex(format_edit_line_selection,
vbo_flag);
@@ -763,14 +779,17 @@ static void grease_pencil_edit_batch_ensure(Object &object,
GPU_vertbuf_data_alloc(*cache->edit_points_pos, total_points_num);
GPU_vertbuf_data_alloc(*cache->edit_points_selection, total_points_num);
GPU_vertbuf_data_alloc(*cache->edit_points_vflag, total_points_num);
GPU_vertbuf_data_alloc(*cache->edit_line_pos, total_line_points_num);
GPU_vertbuf_data_alloc(*cache->edit_line_selection, total_line_points_num);
MutableSpan<float3> edit_points = cache->edit_points_pos->data<float3>();
MutableSpan<float> edit_points_selection = cache->edit_points_selection->data<float>();
MutableSpan<uint32_t> edit_points_vflag = cache->edit_points_vflag->data<uint32_t>();
MutableSpan<float3> edit_line_points = cache->edit_line_pos->data<float3>();
MutableSpan<float> edit_line_selection = cache->edit_line_selection->data<float>();
edit_points_selection.fill(0.0f);
edit_points_vflag.fill(0);
edit_line_selection.fill(0.0f);
int visible_points_num = 0;
@@ -808,6 +827,12 @@ static void grease_pencil_edit_batch_ensure(Object &object,
positions_eval, range, layer_space_to_object_space, positions_eval_slice);
});
for (const int curve_i : points_by_curve_eval.index_range()) {
const IndexRange range = points_by_curve_eval[curve_i];
edit_points_vflag[range.first()] |= GREASE_PENCIL_EDIT_STROKE_START;
edit_points_vflag[range.last()] |= GREASE_PENCIL_EDIT_STROKE_END;
}
/* Do not show selection for locked layers. */
if (!layer.is_locked()) {
const IndexMask selected_editable_points =
@@ -997,6 +1022,7 @@ static void grease_pencil_edit_batch_ensure(Object &object,
cache->edit_points = GPU_batch_create(
GPU_PRIM_POINTS, cache->edit_points_pos, cache->edit_points_indices);
GPU_batch_vertbuf_add(cache->edit_points, cache->edit_points_selection, false);
GPU_batch_vertbuf_add(cache->edit_points, cache->edit_points_vflag, false);
cache->edit_lines = GPU_batch_create(
GPU_PRIM_LINE_STRIP, cache->edit_line_pos, cache->edit_line_indices);
@@ -1007,6 +1033,7 @@ static void grease_pencil_edit_batch_ensure(Object &object,
GPU_vertbuf_use(cache->edit_line_pos);
GPU_vertbuf_use(cache->edit_points_selection);
GPU_vertbuf_use(cache->edit_line_selection);
GPU_vertbuf_use(cache->edit_points_vflag);
cache->is_dirty = false;
}