32using ed::greasepencil::MutableDrawingInfo;
43 bool active_layer_only_;
68 radius_ = brush->
size;
69 strength_ = brush->
alpha;
73 color_linear[3] = 1.0f;
81 if (active_layer_only_) {
83 const Layer *active_layer = grease_pencil.get_active_layer();
88 *scene, grease_pencil, *active_layer);
95 if (drawings_.is_empty()) {
103 screen_positions_per_drawing_.reinitialize(drawings_.size());
106 const int drawing_index = (&drawing_info - drawings_.data());
111 screen_positions_per_drawing_[drawing_index].reinitialize(strokes.
points_num());
121 screen_positions_per_drawing_[drawing_index][
point],
129 if (drawings_.is_empty()) {
142 float radius = radius_;
143 float strength = strength_;
153 float fill_strength = strength / 100.0f;
156 fill_strength =
math::clamp(fill_strength, 0.0f, 1.0f);
158 const bool tint_strokes =
ELEM(
160 const bool tint_fills =
ELEM(
165 std::atomic<bool> changed =
false;
166 const auto execute_tint_on_drawing = [&](
Drawing &drawing,
const int drawing_index) {
174 screen_positions_per_drawing_[drawing_index].as_span();
178 if (!bbox.has_value()) {
182 if (mouse.x < box.
min.x || mouse.x > box.
max.x || mouse.y < box.
min.y || mouse.y > box.
max.y)
187 mouse,
reinterpret_cast<const float(*)[2]
>(points.
data()), points.
size());
191 for (const int curve : range) {
192 bool stroke_touched = false;
193 for (const int curve_point : points_by_curve[curve].index_range()) {
195 const int point = curve_point + points_by_curve[curve].first();
196 const float distance = math::distance(screen_space_positions[point], mouse_position);
197 const float influence = strength * BKE_brush_curve_strength(brush, distance, radius);
198 if (influence > 0.0f) {
199 stroke_touched = true;
203 float4 premultiplied;
204 straight_to_premul_v4_v4(premultiplied, vertex_colors[point]);
205 float4 rgba = float4(
206 math::interpolate(float3(premultiplied), float3(color_), influence),
207 vertex_colors[point][3]);
208 rgba[3] = rgba[3] * (1.0f - influence) + influence;
209 premul_to_straight_v4_v4(vertex_colors[point], rgba);
213 if (tint_fills && !fill_colors.is_empty()) {
216 const bool fill_effective = stroke_touched ||
217 point_inside_stroke(screen_space_positions.slice(
218 points_by_curve[curve].first(),
219 points_by_curve[curve].size()),
221 if (fill_effective) {
222 float4 premultiplied;
223 straight_to_premul_v4_v4(premultiplied, fill_colors[curve]);
224 float4 rgba = float4(
225 math::interpolate(float3(premultiplied), float3(color_), fill_strength),
226 fill_colors[curve][3]);
227 rgba[3] = rgba[3] * (1.0f - fill_strength) + fill_strength;
228 premul_to_straight_v4_v4(fill_colors[curve], rgba);
229 stroke_touched = true;
232 if (stroke_touched) {
233 changed.store(true, std::memory_order_relaxed);
240 const int drawing_index = (&info - drawings_.data());
241 execute_tint_on_drawing(info.
drawing, drawing_index);
252 execute_tint(
C, extension_sample);
259 return std::make_unique<TintOperation>();
bool BKE_brush_use_alpha_pressure(const Brush *brush)
bool BKE_brush_use_size_pressure(const Brush *brush)
void BKE_brush_init_gpencil_settings(Brush *brush)
const float * BKE_brush_color_get(const Scene *scene, const Paint *paint, const Brush *brush)
Depsgraph * CTX_data_depsgraph_pointer(const bContext *C)
Object * CTX_data_active_object(const bContext *C)
Scene * CTX_data_scene(const bContext *C)
ARegion * CTX_wm_region(const bContext *C)
Low-level operations for curves.
Low-level operations for grease pencil.
General operations, lookup, etc. for materials.
Paint * BKE_paint_get_active_from_context(const bContext *C)
Brush * BKE_paint_brush(Paint *paint)
void srgb_to_linearrgb_v3_v3(float linear[3], const float srgb[3])
bool isect_point_poly_v2(const float pt[2], const float verts[][2], unsigned int nr)
void DEG_id_tag_update(ID *id, unsigned int flags)
Object * DEG_get_evaluated_object(const Depsgraph *depsgraph, Object *object)
@ GP_BRUSH_ACTIVE_LAYER_ONLY
eV3DProjStatus ED_view3d_project_float_global(const ARegion *region, const float co[3], float r_co[2], eV3DProjTest flag)
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
BPy_StructRNA * depsgraph
constexpr const T * data() const
constexpr int64_t size() const
OffsetIndices< int > points_by_curve() const
IndexRange curves_range() const
IndexRange points_range() const
bke::CurvesGeometry & strokes_for_write()
MutableSpan< ColorGeometry4f > fill_colors_for_write()
MutableSpan< ColorGeometry4f > vertex_colors_for_write()
float4x4 to_world_space(const Object &object) 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 on_stroke_done(const bContext &C) override
GeometryDeformation get_evaluated_grease_pencil_drawing_deformation(const Object *ob_eval, const Object &ob_orig, int layer_index, int frame)
std::optional< Bounds< T > > min_max(const std::optional< Bounds< T > > &a, const T &b)
Vector< MutableDrawingInfo > retrieve_editable_drawings_from_layer(const Scene &scene, GreasePencil &grease_pencil, const blender::bke::greasepencil::Layer &layer)
Vector< MutableDrawingInfo > retrieve_editable_drawings(const Scene &scene, GreasePencil &grease_pencil)
std::unique_ptr< GreasePencilStrokeOperation > new_tint_operation()
T clamp(const T &a, const T &min, const T &max)
VecBase< T, 3 > transform_point(const CartesianBasis &basis, const VecBase< T, 3 > &v)
void parallel_for_each(Range &&range, const Function &function)
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
VecBase< float, 4 > float4
VecBase< float, 2 > float2
ColorSceneLinear4f< eAlpha::Premultiplied > ColorGeometry4f
struct CurveMapping * curve_sensitivity
struct CurveMapping * curve_strength
struct CurveMapping * curve
struct BrushGpencilSettings * gpencil_settings
struct ToolSettings * toolsettings
bke::greasepencil::Drawing & drawing
bke::greasepencil::Drawing & drawing
void WM_event_add_notifier(const bContext *C, uint type, void *reference)