Blender V5.3
vertex_blur.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "BKE_brush.hh"
6#include "BKE_context.hh"
7#include "BKE_curves.hh"
9#include "BKE_paint.hh"
10
12
14
15class VertexBlurOperation : public GreasePencilStrokeOperationCommon {
17
18 public:
19 void on_stroke_begin(const bContext &C, const InputSample &start_sample) override;
20 void on_stroke_extended(const bContext &C, const InputSample &extension_sample) override;
21 void on_stroke_done(const bContext &C) override;
22};
23
25{
26 this->init_stroke(C, start_sample);
27 this->on_stroke_extended(C, start_sample);
28}
29
31 const InputSample &extension_sample)
32{
33 const Scene &scene = *CTX_data_scene(&C);
35 const Brush &brush = *BKE_paint_brush(&paint);
36 const float radius = brush_radius(paint, brush, extension_sample.pressure);
37 const float radius_squared = radius * radius;
38
39 const bool use_selection_masking = ED_grease_pencil_any_vertex_mask_selection(
40 scene.toolsettings);
41
43 C,
44 [&](const GreasePencilStrokeParams &params) {
45 IndexMaskMemory memory;
46 const IndexMask stroke_selection = curve_mask_for_stroke_operation(
47 params, use_selection_masking, memory);
48 if (stroke_selection.is_empty()) {
49 return false;
50 }
51 const Array<float2> view_positions = view_positions_from_curve_mask(params,
52 stroke_selection);
53 const OffsetIndices<int> points_by_curve = params.drawing.strokes().points_by_curve();
55 stroke_selection.foreach_index(
56 [&](const int64_t curve) {
57 const IndexRange points = points_by_curve[curve];
58
59 float3 average_color(0.0f);
60 int color_count = 0;
61 for (const int point : points) {
62 const ColorGeometry4f color = vertex_colors[point];
63 const float distance = math::distance_squared(extension_sample.mouse_position,
64 view_positions[point]);
65 if (color.a > 0.0f && distance < radius_squared) {
66 average_color += float3(color.r, color.g, color.b);
67 color_count++;
68 }
69 }
70
71 if (color_count == 0) {
72 return;
73 }
74 average_color = average_color / color_count;
76 average_color.x, average_color.y, average_color.z, 1.0f);
77
78 for (const int point : points) {
79 const float influence = brush_point_influence(paint,
80 brush,
81 view_positions[point],
82 extension_sample,
83 params.multi_frame_falloff);
84 ColorGeometry4f &color = vertex_colors[point];
85 if (color.a > 0.0f && influence > 0.0f) {
87 }
88 }
89 },
91 return true;
92 },
94}
95
97
98std::unique_ptr<GreasePencilStrokeOperation> new_vertex_blur_operation()
99{
100 return std::make_unique<VertexBlurOperation>();
101}
102
103} // namespace blender::ed::sculpt_paint::greasepencil
Low-level operations for curves.
Low-level operations for grease pencil.
#define C
Definition RandGen.cpp:29
OffsetIndices< int > points_by_curve() const
const bke::CurvesGeometry & strokes() const
MutableSpan< ColorGeometry4f > vertex_colors_for_write()
void init_stroke(const bContext &C, const InputSample &start_sample)
void foreach_editable_drawing(const bContext &C, FunctionRef< bool(const GreasePencilStrokeParams &params, const DeltaProjectionFunc &projection_fn)> fn) const
void on_stroke_begin(const bContext &C, const InputSample &start_sample) override
void on_stroke_extended(const bContext &C, const InputSample &extension_sample) override
void foreach_index(Fn &&fn, Mode mode=exec_mode::serial) const
void mix_color(float fac, float4 col1, float4 col2, float4 &outcol)
float distance(float, float) RET
IndexMask curve_mask_for_stroke_operation(const GreasePencilStrokeParams &params, bool use_selection_masking, IndexMaskMemory &memory)
Array< float2 > view_positions_from_curve_mask(const GreasePencilStrokeParams &params, const IndexMask &curve_mask)
float brush_point_influence(const Paint &paint, const Brush &brush, const float2 &co, const InputSample &sample, float multi_frame_falloff)
std::unique_ptr< GreasePencilStrokeOperation > new_vertex_blur_operation()
float brush_radius(const Paint &paint, const Brush &brush, float pressure)
constexpr ParallelGrainSize grain_size(int grain_size)
T interpolate(const T &a, const T &b, const FactorT &t)
T distance_squared(const VecBase< T, Size > &a, const VecBase< T, Size > &b)
__int64 int64_t
Definition BKE_text.h:90
bool ED_grease_pencil_any_vertex_mask_selection(const ToolSettings *tool_settings)
Paint * BKE_paint_get_active_from_context(const bContext *C)
Brush * BKE_paint_brush(Paint *paint)
Scene * CTX_data_scene(const bContext *C)
ColorSceneLinear4f< eAlpha::Premultiplied > ColorGeometry4f
VecBase< float, 3 > float3
struct ToolSettings * toolsettings