GPv3: Implement the alpha threshold setting for the Fill tool
The fill tool can take opacity into account ("Advanced" brush settings).
In that case any point with a total opacity lower than the threshold is
rendered as a transparent boundary.
This was still a hardcoded setting in the fill tool, now uses brush
settings.
Pull Request: https://projects.blender.org/blender/blender/pulls/123469
This commit is contained in:
@@ -443,6 +443,7 @@ enum FillToolFitMethod {
|
||||
* \param boundary_layers: Layers that are purely for boundaries, regular strokes are not rendered.
|
||||
* \param src_drawings: Drawings to include as boundary strokes.
|
||||
* \param invert: Construct boundary around empty areas instead.
|
||||
* \param alpha_threshold: Render transparent stroke where opacity is below the threshold.
|
||||
* \param fill_point: Point from which to start the bucket fill.
|
||||
* \param fit_method: View fitting method to include all strokes.
|
||||
* \param stroke_material_index: Material index to use for the new strokes.
|
||||
@@ -455,6 +456,7 @@ bke::CurvesGeometry fill_strokes(const ViewContext &view_context,
|
||||
const VArray<bool> &boundary_layers,
|
||||
Span<DrawingInfo> src_drawings,
|
||||
bool invert,
|
||||
const std::optional<float> alpha_threshold,
|
||||
const float2 &fill_point,
|
||||
FillToolFitMethod fit_method,
|
||||
int stroke_material_index,
|
||||
|
||||
@@ -59,6 +59,7 @@
|
||||
#include "grease_pencil_intern.hh"
|
||||
#include "paint_intern.hh"
|
||||
#include "wm_event_types.hh"
|
||||
#include <optional>
|
||||
|
||||
namespace blender::ed::sculpt_paint {
|
||||
|
||||
@@ -727,6 +728,10 @@ static bool grease_pencil_apply_fill(bContext &C, wmOperator &op, const wmEvent
|
||||
const Brush &brush = *BKE_paint_brush(&ts.gp_paint->paint);
|
||||
const float2 mouse_position = float2(event.mval);
|
||||
const int simplify_levels = brush.gpencil_settings->fill_simplylvl;
|
||||
const std::optional<float> alpha_threshold =
|
||||
(brush.gpencil_settings->flag & GP_BRUSH_FILL_HIDE) ?
|
||||
std::nullopt :
|
||||
std::make_optional(brush.gpencil_settings->fill_threshold);
|
||||
|
||||
if (!grease_pencil.has_active_layer()) {
|
||||
return false;
|
||||
@@ -748,6 +753,7 @@ static bool grease_pencil_apply_fill(bContext &C, wmOperator &op, const wmEvent
|
||||
boundary_layers,
|
||||
info.sources,
|
||||
op_data.invert,
|
||||
alpha_threshold,
|
||||
mouse_position,
|
||||
fit_method,
|
||||
op_data.material_index,
|
||||
|
||||
@@ -803,10 +803,9 @@ static VArray<ColorGeometry4f> stroke_colors(const Object &object,
|
||||
const VArray<float> &opacities,
|
||||
const VArray<int> materials,
|
||||
const ColorGeometry4f &tint_color,
|
||||
const float alpha_threshold,
|
||||
const bool brush_fill_hide)
|
||||
const std::optional<float> alpha_threshold)
|
||||
{
|
||||
if (brush_fill_hide) {
|
||||
if (!alpha_threshold) {
|
||||
return VArray<ColorGeometry4f>::ForSingle(tint_color, curves.points_num());
|
||||
}
|
||||
|
||||
@@ -820,7 +819,7 @@ static VArray<ColorGeometry4f> stroke_colors(const Object &object,
|
||||
1.0f;
|
||||
const IndexRange points = curves.points_by_curve()[curve_i];
|
||||
for (const int point_i : points) {
|
||||
const float alpha = (material_alpha * opacities[point_i] > alpha_threshold ? 1.0f : 0.0f);
|
||||
const float alpha = (material_alpha * opacities[point_i] > *alpha_threshold ? 1.0f : 0.0f);
|
||||
colors[point_i] = ColorGeometry4f(tint_color.r, tint_color.g, tint_color.b, alpha);
|
||||
}
|
||||
}
|
||||
@@ -987,6 +986,7 @@ bke::CurvesGeometry fill_strokes(const ViewContext &view_context,
|
||||
const VArray<bool> &boundary_layers,
|
||||
const Span<DrawingInfo> src_drawings,
|
||||
const bool invert,
|
||||
const std::optional<float> alpha_threshold,
|
||||
const float2 &fill_point,
|
||||
const FillToolFitMethod fit_method,
|
||||
const int stroke_material_index,
|
||||
@@ -1046,8 +1046,6 @@ bke::CurvesGeometry fill_strokes(const ViewContext &view_context,
|
||||
GPU_depth_mask(true);
|
||||
image_render::set_viewmat(view_context, scene, image_size, zoom, offset);
|
||||
|
||||
const float alpha_threshold = 0.2f;
|
||||
const bool brush_fill_hide = false;
|
||||
const bool use_xray = false;
|
||||
|
||||
const float4x4 layer_to_world = layer.to_world_space(object);
|
||||
@@ -1081,8 +1079,7 @@ bke::CurvesGeometry fill_strokes(const ViewContext &view_context,
|
||||
opacities,
|
||||
materials,
|
||||
draw_boundary_color,
|
||||
alpha_threshold,
|
||||
brush_fill_hide);
|
||||
alpha_threshold);
|
||||
|
||||
image_render::draw_grease_pencil_strokes(rv3d,
|
||||
image_size,
|
||||
|
||||
Reference in New Issue
Block a user