Blender V4.3
grease_pencil_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
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(scene, brush, extension_sample.pressure);
37 const float radius_squared = radius * radius;
38
39 const bool is_masking = GPENCIL_ANY_VERTEX_MASK(
40 eGP_vertex_SelectMaskFlag(scene.toolsettings->gpencil_selectmode_vertex));
41
43 IndexMaskMemory memory;
44 const IndexMask stroke_selection = stroke_selection_mask(params, is_masking, memory);
45 if (stroke_selection.is_empty()) {
46 return false;
47 }
48 const IndexMask point_selection = point_selection_mask(params, is_masking, memory);
49 const Array<float2> view_positions = calculate_view_positions(params, point_selection);
50 const OffsetIndices<int> points_by_curve = params.drawing.strokes().points_by_curve();
51 MutableSpan<ColorGeometry4f> vertex_colors = params.drawing.vertex_colors_for_write();
52 stroke_selection.foreach_index(GrainSize(1024), [&](const int64_t curve) {
53 const IndexRange points = points_by_curve[curve];
54
55 float3 average_color(0.0f);
56 int color_count = 0;
57 for (const int point : points) {
58 const ColorGeometry4f color = vertex_colors[point];
59 const float distance = math::distance_squared(extension_sample.mouse_position,
60 view_positions[point]);
61 if (color.a > 0.0f && distance < radius_squared) {
62 average_color += float3(color.r, color.g, color.b);
63 color_count++;
64 }
65 }
66
67 if (color_count == 0) {
68 return;
69 }
70 average_color = average_color / color_count;
71 const ColorGeometry4f mix_color(average_color.x, average_color.y, average_color.z, 1.0f);
72
73 for (const int point : points) {
74 const float influence = brush_point_influence(
75 scene, brush, view_positions[point], extension_sample, params.multi_frame_falloff);
76 ColorGeometry4f &color = vertex_colors[point];
77 if (color.a > 0.0f && influence > 0.0f) {
78 color = math::interpolate(color, mix_color, influence);
79 }
80 }
81 });
82 return true;
83 });
84}
85
87
88std::unique_ptr<GreasePencilStrokeOperation> new_vertex_blur_operation()
89{
90 return std::make_unique<VertexBlurOperation>();
91}
92
93} // namespace blender::ed::sculpt_paint::greasepencil
Scene * CTX_data_scene(const bContext *C)
Low-level operations for curves.
Low-level operations for grease pencil.
Paint * BKE_paint_get_active_from_context(const bContext *C)
Definition paint.cc:477
Brush * BKE_paint_brush(Paint *paint)
Definition paint.cc:649
#define GPENCIL_ANY_VERTEX_MASK(flag)
eGP_vertex_SelectMaskFlag
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Gabor Generate Gabor noise Gradient Generate interpolated color and intensity values based on the input vector Magic Generate a psychedelic color texture Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a point
void foreach_editable_drawing(const bContext &C, FunctionRef< bool(const GreasePencilStrokeParams &params)> 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) const
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
IndexMask point_selection_mask(const GreasePencilStrokeParams &params, const bool use_masking, IndexMaskMemory &memory)
Array< float2 > calculate_view_positions(const GreasePencilStrokeParams &params, const IndexMask &selection)
std::unique_ptr< GreasePencilStrokeOperation > new_vertex_blur_operation()
float brush_point_influence(const Scene &scene, const Brush &brush, const float2 &co, const InputSample &sample, float multi_frame_falloff)
IndexMask stroke_selection_mask(const GreasePencilStrokeParams &params, const bool use_masking, IndexMaskMemory &memory)
float brush_radius(const Scene &scene, const Brush &brush, float pressure)
T interpolate(const T &a, const T &b, const FactorT &t)
T distance_squared(const VecBase< T, Size > &a, const VecBase< T, Size > &b)
VecBase< float, 3 > float3
__int64 int64_t
Definition stdint.h:89