Blender  V2.93
brush.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
21 #include "MEM_guardedalloc.h"
22 
23 #include "DNA_brush_types.h"
24 #include "DNA_defaults.h"
25 #include "DNA_gpencil_types.h"
26 #include "DNA_material_types.h"
27 #include "DNA_object_types.h"
28 #include "DNA_scene_types.h"
29 
30 #include "BLI_listbase.h"
31 #include "BLI_math.h"
32 #include "BLI_rand.h"
33 
34 #include "BLT_translation.h"
35 
36 #include "BKE_brush.h"
37 #include "BKE_colortools.h"
38 #include "BKE_context.h"
39 #include "BKE_gpencil.h"
40 #include "BKE_icons.h"
41 #include "BKE_idtype.h"
42 #include "BKE_lib_id.h"
43 #include "BKE_lib_query.h"
44 #include "BKE_lib_remap.h"
45 #include "BKE_main.h"
46 #include "BKE_material.h"
47 #include "BKE_paint.h"
48 #include "BKE_texture.h"
49 
50 #include "IMB_colormanagement.h"
51 #include "IMB_imbuf.h"
52 #include "IMB_imbuf_types.h"
53 
54 #include "RE_texture.h" /* RE_texture_evaluate */
55 
56 #include "BLO_read_write.h"
57 
58 static void brush_init_data(ID *id)
59 {
60  Brush *brush = (Brush *)id;
62 
64 
65  /* enable fake user by default */
66  id_fake_user_set(&brush->id);
67 
68  /* the default alpha falloff curve */
70 }
71 
72 static void brush_copy_data(Main *UNUSED(bmain), ID *id_dst, const ID *id_src, const int flag)
73 {
74  Brush *brush_dst = (Brush *)id_dst;
75  const Brush *brush_src = (const Brush *)id_src;
76  if (brush_src->icon_imbuf) {
77  brush_dst->icon_imbuf = IMB_dupImBuf(brush_src->icon_imbuf);
78  }
79 
80  if ((flag & LIB_ID_COPY_NO_PREVIEW) == 0) {
81  BKE_previewimg_id_copy(&brush_dst->id, &brush_src->id);
82  }
83  else {
84  brush_dst->preview = NULL;
85  }
86 
87  brush_dst->curve = BKE_curvemapping_copy(brush_src->curve);
88  if (brush_src->gpencil_settings != NULL) {
89  brush_dst->gpencil_settings = MEM_dupallocN(brush_src->gpencil_settings);
93  brush_src->gpencil_settings->curve_strength);
95  brush_src->gpencil_settings->curve_jitter);
96 
102  brush_src->gpencil_settings->curve_rand_uv);
104  brush_src->gpencil_settings->curve_rand_hue);
108  brush_src->gpencil_settings->curve_rand_value);
109  }
110 
111  /* enable fake user by default */
112  id_fake_user_set(&brush_dst->id);
113 }
114 
115 static void brush_free_data(ID *id)
116 {
117  Brush *brush = (Brush *)id;
118  if (brush->icon_imbuf) {
119  IMB_freeImBuf(brush->icon_imbuf);
120  }
122 
123  if (brush->gpencil_settings != NULL) {
127 
134 
136  }
137 
138  MEM_SAFE_FREE(brush->gradient);
139 
140  BKE_previewimg_free(&(brush->preview));
141 }
142 
143 static void brush_make_local(Main *bmain, ID *id, const int flags)
144 {
145  Brush *brush = (Brush *)id;
146  const bool lib_local = (flags & LIB_ID_MAKELOCAL_FULL_LIBRARY) != 0;
147  bool is_local = false, is_lib = false;
148 
149  /* - only lib users: do nothing (unless force_local is set)
150  * - only local users: set flag
151  * - mixed: make copy
152  */
153 
154  if (!ID_IS_LINKED(brush)) {
155  return;
156  }
157 
158  if (brush->clone.image) {
159  /* Special case: ima always local immediately. Clone image should only have one user anyway. */
160  BKE_lib_id_make_local(bmain, &brush->clone.image->id, false, 0);
161  }
162 
163  BKE_library_ID_test_usages(bmain, brush, &is_local, &is_lib);
164 
165  if (lib_local || is_local) {
166  if (!is_lib) {
167  BKE_lib_id_clear_library_data(bmain, &brush->id);
168  BKE_lib_id_expand_local(bmain, &brush->id);
169 
170  /* enable fake user by default */
171  id_fake_user_set(&brush->id);
172  }
173  else {
174  Brush *brush_new = (Brush *)BKE_id_copy(bmain, &brush->id); /* Ensures FAKE_USER is set */
175 
176  brush_new->id.us = 0;
177 
178  /* setting newid is mandatory for complex make_lib_local logic... */
179  ID_NEW_SET(brush, brush_new);
180 
181  if (!lib_local) {
182  BKE_libblock_remap(bmain, brush, brush_new, ID_REMAP_SKIP_INDIRECT_USAGE);
183  }
184  }
185  }
186 }
187 
189 {
190  Brush *brush = (Brush *)id;
191 
195  if (brush->gpencil_settings) {
197  }
200 }
201 
202 static void brush_blend_write(BlendWriter *writer, ID *id, const void *id_address)
203 {
204  Brush *brush = (Brush *)id;
205  if (brush->id.us > 0 || BLO_write_is_undo(writer)) {
206  BLO_write_id_struct(writer, Brush, id_address, &brush->id);
207  BKE_id_blend_write(writer, &brush->id);
208 
209  if (brush->curve) {
210  BKE_curvemapping_blend_write(writer, brush->curve);
211  }
212 
213  if (brush->gpencil_settings) {
215 
216  if (brush->gpencil_settings->curve_sensitivity) {
218  }
219  if (brush->gpencil_settings->curve_strength) {
221  }
222  if (brush->gpencil_settings->curve_jitter) {
224  }
227  }
230  }
231  if (brush->gpencil_settings->curve_rand_uv) {
233  }
234  if (brush->gpencil_settings->curve_rand_hue) {
236  }
239  }
240  if (brush->gpencil_settings->curve_rand_value) {
242  }
243  }
244  if (brush->gradient) {
245  BLO_write_struct(writer, ColorBand, brush->gradient);
246  }
247  }
248 }
249 
250 static void brush_blend_read_data(BlendDataReader *reader, ID *id)
251 {
252  Brush *brush = (Brush *)id;
253 
254  /* Falloff curve. */
255  BLO_read_data_address(reader, &brush->curve);
256 
257  BLO_read_data_address(reader, &brush->gradient);
258 
259  if (brush->curve) {
260  BKE_curvemapping_blend_read(reader, brush->curve);
261  }
262  else {
264  }
265 
266  /* grease pencil */
267  BLO_read_data_address(reader, &brush->gpencil_settings);
268  if (brush->gpencil_settings != NULL) {
272 
279 
280  if (brush->gpencil_settings->curve_sensitivity) {
282  }
283 
284  if (brush->gpencil_settings->curve_strength) {
286  }
287 
288  if (brush->gpencil_settings->curve_jitter) {
290  }
291 
294  }
295 
298  }
299 
300  if (brush->gpencil_settings->curve_rand_uv) {
302  }
303 
304  if (brush->gpencil_settings->curve_rand_hue) {
306  }
307 
310  }
311 
312  if (brush->gpencil_settings->curve_rand_value) {
314  }
315  }
316 
317  brush->preview = NULL;
318  brush->icon_imbuf = NULL;
319 }
320 
321 static void brush_blend_read_lib(BlendLibReader *reader, ID *id)
322 {
323  Brush *brush = (Brush *)id;
324 
325  /* brush->(mask_)mtex.obj is ignored on purpose? */
326  BLO_read_id_address(reader, brush->id.lib, &brush->mtex.tex);
327  BLO_read_id_address(reader, brush->id.lib, &brush->mask_mtex.tex);
328  BLO_read_id_address(reader, brush->id.lib, &brush->clone.image);
329  BLO_read_id_address(reader, brush->id.lib, &brush->toggle_brush);
330  BLO_read_id_address(reader, brush->id.lib, &brush->paint_curve);
331 
332  /* link default grease pencil palette */
333  if (brush->gpencil_settings != NULL) {
335  BLO_read_id_address(reader, brush->id.lib, &brush->gpencil_settings->material);
336 
337  if (!brush->gpencil_settings->material) {
339  }
340  }
341  else {
342  brush->gpencil_settings->material = NULL;
343  }
344  }
345 }
346 
347 static void brush_blend_read_expand(BlendExpander *expander, ID *id)
348 {
349  Brush *brush = (Brush *)id;
350  BLO_expand(expander, brush->mtex.tex);
351  BLO_expand(expander, brush->mask_mtex.tex);
352  BLO_expand(expander, brush->clone.image);
353  BLO_expand(expander, brush->paint_curve);
354  if (brush->gpencil_settings != NULL) {
355  BLO_expand(expander, brush->gpencil_settings->material);
356  }
357 }
358 
360 {
361  BlendLibReader *reader = cb_data->user_data;
362  ID *id_old = *cb_data->id_pointer;
363  /* Old data has not been remapped to new values of the pointers, if we want to keep the old
364  * pointer here we need its new address. */
365  ID *id_old_new = id_old != NULL ? BLO_read_get_new_id_address(reader, id_old->lib, id_old) :
366  NULL;
367  BLI_assert(id_old_new == NULL || ELEM(id_old, id_old_new, id_old_new->orig_id));
368  if (cb_data->cb_flag & IDWALK_CB_USER) {
369  id_us_plus_no_lib(id_old_new);
370  id_us_min(id_old);
371  }
372  *cb_data->id_pointer = id_old_new;
373  return IDWALK_RET_NOP;
374 }
375 
376 static void brush_undo_preserve(BlendLibReader *reader, ID *id_new, ID *id_old)
377 {
378  /* Whole Brush is preserved across undo-steps. */
379  BKE_lib_id_swap(NULL, id_new, id_old);
380 
381  /* `id_new` now has content from `id_old`, we need to ensure those old ID pointers are valid.
382  * Note: Since we want to re-use all old pointers here, code is much simpler than for Scene. */
384 
385  /* Note: We do not swap IDProperties, as dealing with potential ID pointers in those would be
386  * fairly delicate. */
387  SWAP(IDProperty *, id_new->properties, id_old->properties);
388 }
389 
391  .id_code = ID_BR,
392  .id_filter = FILTER_ID_BR,
393  .main_listbase_index = INDEX_ID_BR,
394  .struct_size = sizeof(Brush),
395  .name = "Brush",
396  .name_plural = "brushes",
397  .translation_context = BLT_I18NCONTEXT_ID_BRUSH,
398  .flags = IDTYPE_FLAGS_NO_ANIMDATA,
399 
401  .copy_data = brush_copy_data,
402  .free_data = brush_free_data,
403  .make_local = brush_make_local,
404  .foreach_id = brush_foreach_id,
405  .foreach_cache = NULL,
406  .owner_get = NULL,
407 
408  .blend_write = brush_blend_write,
409  .blend_read_data = brush_blend_read_data,
410  .blend_read_lib = brush_blend_read_lib,
411  .blend_read_expand = brush_blend_read_expand,
412 
413  .blend_read_undo_preserve = brush_undo_preserve,
414 
415  .lib_override_apply_post = NULL,
416 };
417 
418 static RNG *brush_rng;
419 
421 {
422  brush_rng = BLI_rng_new(0);
423  BLI_rng_srandom(brush_rng, 31415682);
424 }
425 
427 {
428  if (brush_rng == NULL) {
429  return;
430  }
432  brush_rng = NULL;
433 }
434 
435 static void brush_defaults(Brush *brush)
436 {
437 
438  const Brush *brush_def = DNA_struct_default_get(Brush);
439 
440 #define FROM_DEFAULT(member) memcpy(&brush->member, &brush_def->member, sizeof(brush->member))
441 #define FROM_DEFAULT_PTR(member) memcpy(brush->member, brush_def->member, sizeof(brush->member))
442 
444  FROM_DEFAULT(flag);
445  FROM_DEFAULT(weight);
448  FROM_DEFAULT(hardness);
449  FROM_DEFAULT(autosmooth_factor);
450  FROM_DEFAULT(topology_rake_factor);
451  FROM_DEFAULT(crease_pinch_factor);
452  FROM_DEFAULT(normal_radius_factor);
453  FROM_DEFAULT(wet_paint_radius_factor);
454  FROM_DEFAULT(area_radius_factor);
455  FROM_DEFAULT(disconnected_distance_max);
456  FROM_DEFAULT(sculpt_plane);
457  FROM_DEFAULT(plane_offset);
458  FROM_DEFAULT(clone.alpha);
459  FROM_DEFAULT(normal_weight);
460  FROM_DEFAULT(fill_threshold);
461  FROM_DEFAULT(flag);
462  FROM_DEFAULT(sampling_flag);
463  FROM_DEFAULT_PTR(rgb);
464  FROM_DEFAULT_PTR(secondary_rgb);
465  FROM_DEFAULT(spacing);
466  FROM_DEFAULT(smooth_stroke_radius);
467  FROM_DEFAULT(smooth_stroke_factor);
468  FROM_DEFAULT(rate);
469  FROM_DEFAULT(jitter);
470  FROM_DEFAULT(texture_sample_bias);
471  FROM_DEFAULT(texture_overlay_alpha);
472  FROM_DEFAULT(mask_overlay_alpha);
473  FROM_DEFAULT(cursor_overlay_alpha);
475  FROM_DEFAULT_PTR(add_col);
476  FROM_DEFAULT_PTR(sub_col);
477  FROM_DEFAULT(stencil_pos);
478  FROM_DEFAULT(stencil_dimension);
479  FROM_DEFAULT(mtex);
480  FROM_DEFAULT(mask_mtex);
481 
482 #undef FROM_DEFAULT
483 #undef FROM_DEFAULT_PTR
484 }
485 
486 /* Datablock add/copy/free/make_local */
487 
492 Brush *BKE_brush_add(Main *bmain, const char *name, const eObjectMode ob_mode)
493 {
494  Brush *brush;
495 
496  brush = BKE_id_new(bmain, ID_BR, name);
497 
498  brush->ob_mode = ob_mode;
499 
500  return brush;
501 }
502 
503 /* add grease pencil settings */
505 {
506  if (brush->gpencil_settings == NULL) {
507  brush->gpencil_settings = MEM_callocN(sizeof(BrushGpencilSettings), "BrushGpencilSettings");
508  }
509 
510  brush->gpencil_settings->draw_smoothlvl = 1;
511  brush->gpencil_settings->flag = 0;
513  brush->gpencil_settings->draw_strength = 1.0f;
514  brush->gpencil_settings->draw_jitter = 0.0f;
517 
518  /* curves */
519  brush->gpencil_settings->curve_sensitivity = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
520  brush->gpencil_settings->curve_strength = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
521  brush->gpencil_settings->curve_jitter = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
522 
523  brush->gpencil_settings->curve_rand_pressure = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
524  brush->gpencil_settings->curve_rand_strength = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
525  brush->gpencil_settings->curve_rand_uv = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
526  brush->gpencil_settings->curve_rand_hue = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
527  brush->gpencil_settings->curve_rand_saturation = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
528  brush->gpencil_settings->curve_rand_value = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
529 }
530 
531 /* add a new gp-brush */
532 Brush *BKE_brush_add_gpencil(Main *bmain, ToolSettings *ts, const char *name, eObjectMode mode)
533 {
534  Paint *paint = NULL;
535  Brush *brush;
536  switch (mode) {
537  case OB_MODE_PAINT_GPENCIL: {
538  paint = &ts->gp_paint->paint;
539  break;
540  }
541  case OB_MODE_SCULPT_GPENCIL: {
542  paint = &ts->gp_sculptpaint->paint;
543  break;
544  }
545  case OB_MODE_WEIGHT_GPENCIL: {
546  paint = &ts->gp_weightpaint->paint;
547  break;
548  }
549  case OB_MODE_VERTEX_GPENCIL: {
550  paint = &ts->gp_vertexpaint->paint;
551  break;
552  }
553  default:
554  paint = &ts->gp_paint->paint;
555  }
556 
557  brush = BKE_brush_add(bmain, name, mode);
558 
559  BKE_paint_brush_set(paint, brush);
560  id_us_min(&brush->id);
561 
562  brush->size = 3;
563 
564  /* grease pencil basic settings */
566 
567  /* return brush */
568  return brush;
569 }
570 
571 /* Delete a Brush. */
572 bool BKE_brush_delete(Main *bmain, Brush *brush)
573 {
574  if (brush->id.tag & LIB_TAG_INDIRECT) {
575  return false;
576  }
577  if (ID_REAL_USERS(brush) <= 1 && ID_EXTRA_USERS(brush) == 0 &&
578  BKE_library_ID_is_indirectly_used(bmain, brush)) {
579  return false;
580  }
581 
582  BKE_id_delete(bmain, brush);
583 
584  return true;
585 }
586 
587 /* grease pencil cumapping->preset */
588 typedef enum eGPCurveMappingPreset {
596 
597 static void brush_gpencil_curvemap_reset(CurveMap *cuma, int tot, int preset)
598 {
599  if (cuma->curve) {
600  MEM_freeN(cuma->curve);
601  }
602 
603  cuma->totpoint = tot;
604  cuma->curve = MEM_callocN(cuma->totpoint * sizeof(CurveMapPoint), __func__);
605 
606  switch (preset) {
608  cuma->curve[0].x = 0.0f;
609  cuma->curve[0].y = 0.0f;
610  cuma->curve[1].x = 0.75115f;
611  cuma->curve[1].y = 0.25f;
612  cuma->curve[2].x = 1.0f;
613  cuma->curve[2].y = 1.0f;
614  break;
615  case GPCURVE_PRESET_INK:
616  cuma->curve[0].x = 0.0f;
617  cuma->curve[0].y = 0.0f;
618  cuma->curve[1].x = 0.63448f;
619  cuma->curve[1].y = 0.375f;
620  cuma->curve[2].x = 1.0f;
621  cuma->curve[2].y = 1.0f;
622  break;
624  cuma->curve[0].x = 0.0f;
625  cuma->curve[0].y = 0.0f;
626  cuma->curve[1].x = 0.55f;
627  cuma->curve[1].y = 0.45f;
628  cuma->curve[2].x = 0.85f;
629  cuma->curve[2].y = 1.0f;
630  break;
632  cuma->curve[0].x = 0.0f;
633  cuma->curve[0].y = 0.0f;
634  cuma->curve[1].x = 0.38f;
635  cuma->curve[1].y = 0.22f;
636  cuma->curve[2].x = 0.65f;
637  cuma->curve[2].y = 0.68f;
638  cuma->curve[3].x = 1.0f;
639  cuma->curve[3].y = 1.0f;
640  break;
642  cuma->curve[0].x = 0.0f;
643  cuma->curve[0].y = 0.0f;
644  cuma->curve[1].x = 0.25f;
645  cuma->curve[1].y = 0.40f;
646  cuma->curve[2].x = 1.0f;
647  cuma->curve[2].y = 1.0f;
648  break;
650  cuma->curve[0].x = 0.0f;
651  cuma->curve[0].y = 0.0f;
652  cuma->curve[1].x = 0.31f;
653  cuma->curve[1].y = 0.22f;
654  cuma->curve[2].x = 0.61f;
655  cuma->curve[2].y = 0.88f;
656  cuma->curve[3].x = 1.0f;
657  cuma->curve[3].y = 1.0f;
658  break;
659  default:
660  break;
661  }
662 
663  if (cuma->table) {
664  MEM_freeN(cuma->table);
665  cuma->table = NULL;
666  }
667 }
668 
669 void BKE_gpencil_brush_preset_set(Main *bmain, Brush *brush, const short type)
670 {
671 #define SMOOTH_STROKE_RADIUS 40
672 #define SMOOTH_STROKE_FACTOR 0.9f
673 #define ACTIVE_SMOOTH 0.35f
674 
675  CurveMapping *custom_curve = NULL;
676 
677  /* Optionally assign a material preset. */
678  enum {
679  PRESET_MATERIAL_NONE = 0,
680  PRESET_MATERIAL_DOT_STROKE,
681  } material_preset = PRESET_MATERIAL_NONE;
682 
683  /* Set general defaults at brush level. */
686 
687  brush->rgb[0] = 0.498f;
688  brush->rgb[1] = 1.0f;
689  brush->rgb[2] = 0.498f;
690 
691  brush->secondary_rgb[0] = 1.0f;
692  brush->secondary_rgb[1] = 1.0f;
693  brush->secondary_rgb[2] = 1.0f;
694 
696 
697  if (brush->gpencil_settings == NULL) {
698  return;
699  }
700 
701  /* Set preset type. */
703 
704  /* Set vertex mix factor. */
706  brush->gpencil_settings->vertex_factor = 1.0f;
707 
708  switch (type) {
710  brush->size = 300.0f;
712 
713  brush->gpencil_settings->draw_strength = 0.4f;
715 
716  brush->gpencil_settings->input_samples = 10;
718  brush->gpencil_settings->draw_angle = 0.0f;
719  brush->gpencil_settings->draw_angle_factor = 0.0f;
720  brush->gpencil_settings->hardeness = 0.9f;
722 
725 
726  zero_v3(brush->secondary_rgb);
727 
728  material_preset = PRESET_MATERIAL_DOT_STROKE;
729 
730  break;
731  }
733 
734  brush->size = 60.0f;
736 
737  brush->gpencil_settings->draw_strength = 1.0f;
738 
739  brush->gpencil_settings->input_samples = 10;
741  brush->gpencil_settings->draw_angle = 0.0f;
742  brush->gpencil_settings->draw_angle_factor = 0.0f;
743  brush->gpencil_settings->hardeness = 1.0f;
745 
747  brush->gpencil_settings->draw_smoothfac = 0.1f;
748  brush->gpencil_settings->draw_smoothlvl = 1;
749  brush->gpencil_settings->draw_subdivide = 0;
750  brush->gpencil_settings->simplify_f = 0.002f;
751 
752  brush->gpencil_settings->draw_random_press = 0.0f;
753  brush->gpencil_settings->draw_jitter = 0.0f;
755 
756  /* Curve. */
757  custom_curve = brush->gpencil_settings->curve_sensitivity;
758  BKE_curvemapping_set_defaults(custom_curve, 0, 0.0f, 0.0f, 1.0f, 1.0f);
759  BKE_curvemapping_init(custom_curve);
761 
764 
765  zero_v3(brush->secondary_rgb);
766  break;
767  }
769  brush->size = 60.0f;
771 
772  brush->gpencil_settings->draw_strength = 1.0f;
773 
774  brush->gpencil_settings->input_samples = 10;
776  brush->gpencil_settings->draw_angle = 0.0f;
777  brush->gpencil_settings->draw_angle_factor = 0.0f;
778  brush->gpencil_settings->hardeness = 1.0f;
780 
782  brush->gpencil_settings->draw_smoothfac = 0.0f;
783  brush->gpencil_settings->draw_smoothlvl = 2;
784  brush->gpencil_settings->draw_subdivide = 0;
785  brush->gpencil_settings->simplify_f = 0.000f;
786 
788  brush->gpencil_settings->draw_random_press = 0.6f;
789  brush->gpencil_settings->draw_random_strength = 0.0f;
790  brush->gpencil_settings->draw_jitter = 0.0f;
792 
793  /* Curve. */
794  custom_curve = brush->gpencil_settings->curve_sensitivity;
795  BKE_curvemapping_set_defaults(custom_curve, 0, 0.0f, 0.0f, 1.0f, 1.0f);
796  BKE_curvemapping_init(custom_curve);
798 
801 
802  zero_v3(brush->secondary_rgb);
803  break;
804  }
806  brush->size = 150.0f;
808 
809  brush->gpencil_settings->draw_strength = 0.3f;
810 
811  brush->gpencil_settings->input_samples = 10;
813  brush->gpencil_settings->draw_angle = 0.0f;
814  brush->gpencil_settings->draw_angle_factor = 0.0f;
815  brush->gpencil_settings->hardeness = 1.0f;
817 
819  brush->gpencil_settings->draw_smoothfac = 0.1f;
820  brush->gpencil_settings->draw_smoothlvl = 1;
821  brush->gpencil_settings->draw_subdivide = 0;
822  brush->gpencil_settings->simplify_f = 0.002f;
823 
825  brush->gpencil_settings->draw_random_press = 0.0f;
826  brush->gpencil_settings->draw_random_strength = 0.0f;
827  brush->gpencil_settings->draw_jitter = 0.0f;
829 
830  /* Curve. */
831  custom_curve = brush->gpencil_settings->curve_sensitivity;
832  BKE_curvemapping_set_defaults(custom_curve, 0, 0.0f, 0.0f, 1.0f, 1.0f);
833  BKE_curvemapping_init(custom_curve);
835 
838 
839  zero_v3(brush->secondary_rgb);
840  break;
841  }
843  brush->size = 150.0f;
845 
846  brush->gpencil_settings->draw_strength = 1.0f;
847 
848  brush->gpencil_settings->input_samples = 10;
849  brush->gpencil_settings->active_smooth = 0.3f;
850  brush->gpencil_settings->draw_angle = DEG2RAD(35.0f);
851  brush->gpencil_settings->draw_angle_factor = 0.5f;
852  brush->gpencil_settings->hardeness = 1.0f;
854 
856  brush->gpencil_settings->draw_smoothfac = 0.0f;
857  brush->gpencil_settings->draw_smoothlvl = 1;
858  brush->gpencil_settings->draw_subdivide = 0;
859  brush->gpencil_settings->simplify_f = 0.002f;
860 
862  brush->gpencil_settings->draw_random_press = 0.0f;
863  brush->gpencil_settings->draw_jitter = 0.0f;
865 
866  /* Curve. */
867  custom_curve = brush->gpencil_settings->curve_sensitivity;
868  BKE_curvemapping_set_defaults(custom_curve, 0, 0.0f, 0.0f, 1.0f, 1.0f);
869  BKE_curvemapping_init(custom_curve);
871 
872  custom_curve = brush->gpencil_settings->curve_strength;
873  BKE_curvemapping_set_defaults(custom_curve, 0, 0.0f, 0.0f, 1.0f, 1.0f);
874  BKE_curvemapping_init(custom_curve);
876 
879 
880  zero_v3(brush->secondary_rgb);
881  break;
882  }
883  case GP_BRUSH_PRESET_PEN: {
884  brush->size = 25.0f;
886 
887  brush->gpencil_settings->draw_strength = 1.0f;
889 
890  brush->gpencil_settings->input_samples = 10;
892  brush->gpencil_settings->draw_angle = 0.0f;
893  brush->gpencil_settings->draw_angle_factor = 0.0f;
894  brush->gpencil_settings->hardeness = 1.0f;
896 
898  brush->gpencil_settings->draw_smoothfac = 0.0f;
899  brush->gpencil_settings->draw_smoothlvl = 1;
900  brush->gpencil_settings->draw_subdivide = 1;
901  brush->gpencil_settings->simplify_f = 0.002f;
902 
903  brush->gpencil_settings->draw_random_press = 0.0f;
904  brush->gpencil_settings->draw_random_strength = 0.0f;
905  brush->gpencil_settings->draw_jitter = 0.0f;
907 
910 
911  zero_v3(brush->secondary_rgb);
912  break;
913  }
915  brush->size = 80.0f;
917 
918  brush->gpencil_settings->draw_strength = 0.4f;
920 
921  brush->gpencil_settings->input_samples = 10;
923  brush->gpencil_settings->draw_angle = 0.0f;
924  brush->gpencil_settings->draw_angle_factor = 0.0f;
925  brush->gpencil_settings->hardeness = 0.8f;
927 
929  brush->gpencil_settings->draw_smoothfac = 0.0f;
930  brush->gpencil_settings->draw_smoothlvl = 1;
931  brush->gpencil_settings->draw_subdivide = 0;
932  brush->gpencil_settings->simplify_f = 0.000f;
933 
934  brush->gpencil_settings->draw_random_press = 0.0f;
935  brush->gpencil_settings->draw_random_strength = 0.0f;
936  brush->gpencil_settings->draw_jitter = 0.0f;
938 
941 
942  zero_v3(brush->secondary_rgb);
943 
944  material_preset = PRESET_MATERIAL_DOT_STROKE;
945 
946  break;
947  }
948  case GP_BRUSH_PRESET_PENCIL: {
949  brush->size = 20.0f;
951 
952  brush->gpencil_settings->draw_strength = 0.6f;
954 
955  brush->gpencil_settings->input_samples = 10;
957  brush->gpencil_settings->draw_angle = 0.0f;
958  brush->gpencil_settings->draw_angle_factor = 0.0f;
959  brush->gpencil_settings->hardeness = 1.0f;
961 
963  brush->gpencil_settings->draw_smoothfac = 0.0f;
964  brush->gpencil_settings->draw_smoothlvl = 1;
965  brush->gpencil_settings->draw_subdivide = 0;
966  brush->gpencil_settings->simplify_f = 0.002f;
967 
968  brush->gpencil_settings->draw_random_press = 0.0f;
969  brush->gpencil_settings->draw_jitter = 0.0f;
971 
974 
975  zero_v3(brush->secondary_rgb);
976  break;
977  }
979  brush->size = 5.0f;
980 
981  brush->gpencil_settings->fill_leak = 3;
982  brush->gpencil_settings->fill_threshold = 0.1f;
983  brush->gpencil_settings->fill_simplylvl = 1;
984  brush->gpencil_settings->fill_factor = 1.0f;
985 
986  brush->gpencil_settings->draw_strength = 1.0f;
987  brush->gpencil_settings->hardeness = 1.0f;
989  brush->gpencil_settings->draw_smoothfac = 0.1f;
990  brush->gpencil_settings->draw_smoothlvl = 1;
991  brush->gpencil_settings->draw_subdivide = 1;
992 
994 
998 
999  zero_v3(brush->secondary_rgb);
1000  break;
1001  }
1003  brush->size = 30.0f;
1004  brush->gpencil_settings->draw_strength = 0.5f;
1011  brush->gpencil_settings->era_strength_f = 100.0f;
1012  brush->gpencil_settings->era_thickness_f = 10.0f;
1013 
1014  break;
1015  }
1017  brush->size = 30.0f;
1018  brush->gpencil_settings->draw_strength = 1.0f;
1020  brush->gpencil_settings->era_strength_f = 100.0f;
1021  brush->gpencil_settings->era_thickness_f = 50.0f;
1022 
1025 
1026  break;
1027  }
1029  brush->size = 30.0f;
1031 
1034 
1035  break;
1036  }
1038  brush->size = 30.0f;
1040 
1043 
1044  break;
1045  }
1046  case GP_BRUSH_PRESET_TINT: {
1048  brush->gpencil_tool = GPAINT_TOOL_TINT;
1049 
1050  brush->size = 25.0f;
1052 
1053  brush->gpencil_settings->draw_strength = 0.8f;
1055 
1056  zero_v3(brush->secondary_rgb);
1057  break;
1058  }
1062 
1063  brush->size = 25.0f;
1065 
1066  brush->gpencil_settings->draw_strength = 0.8f;
1068 
1069  zero_v3(brush->secondary_rgb);
1070  break;
1071  }
1075 
1076  brush->size = 25.0f;
1078 
1079  brush->gpencil_settings->draw_strength = 0.8f;
1081 
1082  zero_v3(brush->secondary_rgb);
1083  break;
1084  }
1088 
1089  brush->size = 25.0f;
1091 
1092  brush->gpencil_settings->draw_strength = 0.8f;
1094 
1095  zero_v3(brush->secondary_rgb);
1096  break;
1097  }
1101 
1102  brush->size = 25.0f;
1104 
1105  brush->gpencil_settings->draw_strength = 0.8f;
1107 
1108  zero_v3(brush->secondary_rgb);
1109  break;
1110  }
1114 
1115  brush->size = 25.0f;
1117 
1118  brush->gpencil_settings->draw_strength = 0.8f;
1120 
1121  zero_v3(brush->secondary_rgb);
1122  break;
1123  }
1127 
1128  brush->size = 25.0f;
1130 
1131  brush->gpencil_settings->draw_strength = 0.3f;
1135 
1136  break;
1137  }
1141 
1142  brush->size = 25.0f;
1144 
1145  brush->gpencil_settings->draw_strength = 0.3f;
1148 
1149  break;
1150  }
1154 
1155  brush->size = 25.0f;
1157 
1158  brush->gpencil_settings->draw_strength = 0.5f;
1161 
1162  break;
1163  }
1168 
1169  brush->size = 25.0f;
1170 
1171  brush->gpencil_settings->draw_strength = 0.3f;
1174 
1175  break;
1176  }
1180 
1181  brush->size = 25.0f;
1183 
1184  brush->gpencil_settings->draw_strength = 0.3f;
1187 
1188  break;
1189  }
1193 
1194  brush->size = 50.0f;
1196 
1197  brush->gpencil_settings->draw_strength = 0.3f;
1200 
1201  break;
1202  }
1206 
1207  brush->size = 50.0f;
1209 
1210  brush->gpencil_settings->draw_strength = 0.5f;
1213 
1214  break;
1215  }
1219 
1220  brush->size = 25.0f;
1222 
1223  brush->gpencil_settings->draw_strength = 0.5f;
1226 
1227  break;
1228  }
1233 
1234  brush->size = 25.0f;
1235 
1236  brush->gpencil_settings->draw_strength = 1.0f;
1239 
1240  break;
1241  }
1245 
1246  brush->size = 25.0f;
1248 
1249  brush->gpencil_settings->draw_strength = 0.8f;
1252 
1253  break;
1254  }
1255  default:
1256  break;
1257  }
1258 
1259  switch (material_preset) {
1260  case PRESET_MATERIAL_NONE:
1261  break;
1262  case PRESET_MATERIAL_DOT_STROKE: {
1263  /* Create and link Black Dots material to brush.
1264  * This material is required because the brush uses the material
1265  * to define how the stroke is drawn. */
1266  const char *ma_id = "Dots Stroke";
1267  Material *ma = BLI_findstring(&bmain->materials, ma_id, offsetof(ID, name) + 2);
1268  if (ma == NULL) {
1269  ma = BKE_gpencil_material_add(bmain, ma_id);
1271  BLI_assert(ma->id.us == 1);
1272  id_us_min(&ma->id);
1273  }
1274 
1275  BKE_gpencil_brush_material_set(brush, ma);
1276 
1277  /* Pin the material to the brush. */
1279  break;
1280  }
1281  }
1282 }
1283 
1285  Main *bmain, ToolSettings *ts, const char *brush_name, eObjectMode mode, bool *r_new)
1286 {
1287  *r_new = false;
1288  Brush *brush = BLI_findstring(&bmain->brushes, brush_name, offsetof(ID, name) + 2);
1289 
1290  /* If the brush exist, but the type is not GPencil or the mode is wrong, create a new one. */
1291  if ((brush != NULL) && ((brush->gpencil_settings == NULL) || (brush->ob_mode != mode))) {
1292  brush = NULL;
1293  }
1294 
1295  if (brush == NULL) {
1296  brush = BKE_brush_add_gpencil(bmain, ts, brush_name, mode);
1297  *r_new = true;
1298  }
1299 
1300  if (brush->gpencil_settings == NULL) {
1302  }
1303 
1304  return brush;
1305 }
1306 
1307 /* Create a set of grease pencil Drawing presets. */
1309 {
1310  bool r_new = false;
1311 
1312  Paint *paint = &ts->gp_paint->paint;
1313  Brush *brush_prev = paint->brush;
1314  Brush *brush, *deft_draw;
1315  /* Airbrush brush. */
1316  brush = gpencil_brush_ensure(bmain, ts, "Airbrush", OB_MODE_PAINT_GPENCIL, &r_new);
1317  if ((reset) || (r_new)) {
1319  }
1320 
1321  /* Ink Pen brush. */
1322  brush = gpencil_brush_ensure(bmain, ts, "Ink Pen", OB_MODE_PAINT_GPENCIL, &r_new);
1323  if ((reset) || (r_new)) {
1325  }
1326 
1327  /* Ink Pen Rough brush. */
1328  brush = gpencil_brush_ensure(bmain, ts, "Ink Pen Rough", OB_MODE_PAINT_GPENCIL, &r_new);
1329  if ((reset) || (r_new)) {
1331  }
1332 
1333  /* Marker Bold brush. */
1334  brush = gpencil_brush_ensure(bmain, ts, "Marker Bold", OB_MODE_PAINT_GPENCIL, &r_new);
1335  if ((reset) || (r_new)) {
1337  }
1338 
1339  /* Marker Chisel brush. */
1340  brush = gpencil_brush_ensure(bmain, ts, "Marker Chisel", OB_MODE_PAINT_GPENCIL, &r_new);
1341  if ((reset) || (r_new)) {
1343  }
1344 
1345  /* Pen brush. */
1346  brush = gpencil_brush_ensure(bmain, ts, "Pen", OB_MODE_PAINT_GPENCIL, &r_new);
1347  if ((reset) || (r_new)) {
1349  }
1350 
1351  /* Pencil Soft brush. */
1352  brush = gpencil_brush_ensure(bmain, ts, "Pencil Soft", OB_MODE_PAINT_GPENCIL, &r_new);
1353  if ((reset) || (r_new)) {
1355  }
1356 
1357  /* Pencil brush. */
1358  brush = gpencil_brush_ensure(bmain, ts, "Pencil", OB_MODE_PAINT_GPENCIL, &r_new);
1359  if ((reset) || (r_new)) {
1361  }
1362  deft_draw = brush; /* save default brush. */
1363 
1364  /* Fill brush. */
1365  brush = gpencil_brush_ensure(bmain, ts, "Fill Area", OB_MODE_PAINT_GPENCIL, &r_new);
1366  if ((reset) || (r_new)) {
1368  }
1369 
1370  /* Soft Eraser brush. */
1371  brush = gpencil_brush_ensure(bmain, ts, "Eraser Soft", OB_MODE_PAINT_GPENCIL, &r_new);
1372  if ((reset) || (r_new)) {
1374  }
1375 
1376  /* Hard Eraser brush. */
1377  brush = gpencil_brush_ensure(bmain, ts, "Eraser Hard", OB_MODE_PAINT_GPENCIL, &r_new);
1378  if ((reset) || (r_new)) {
1380  }
1381 
1382  /* Point Eraser brush. */
1383  brush = gpencil_brush_ensure(bmain, ts, "Eraser Point", OB_MODE_PAINT_GPENCIL, &r_new);
1384  if ((reset) || (r_new)) {
1386  }
1387 
1388  /* Stroke Eraser brush. */
1389  brush = gpencil_brush_ensure(bmain, ts, "Eraser Stroke", OB_MODE_PAINT_GPENCIL, &r_new);
1390  if ((reset) || (r_new)) {
1392  }
1393 
1394  /* Tint brush. */
1395  brush = gpencil_brush_ensure(bmain, ts, "Tint", OB_MODE_PAINT_GPENCIL, &r_new);
1396  if ((reset) || (r_new)) {
1398  }
1399 
1400  /* Set default Draw brush. */
1401  if (reset || brush_prev == NULL) {
1402  BKE_paint_brush_set(paint, deft_draw);
1403  }
1404  else {
1405  if (brush_prev != NULL) {
1406  BKE_paint_brush_set(paint, brush_prev);
1407  }
1408  }
1409 }
1410 
1411 /* Create a set of grease pencil Vertex Paint presets. */
1413 {
1414  bool r_new = false;
1415 
1416  Paint *vertexpaint = &ts->gp_vertexpaint->paint;
1417  Brush *brush_prev = vertexpaint->brush;
1418  Brush *brush, *deft_vertex;
1419  /* Vertex Draw brush. */
1420  brush = gpencil_brush_ensure(bmain, ts, "Vertex Draw", OB_MODE_VERTEX_GPENCIL, &r_new);
1421  if ((reset) || (r_new)) {
1423  }
1424  deft_vertex = brush; /* save default brush. */
1425 
1426  /* Vertex Blur brush. */
1427  brush = gpencil_brush_ensure(bmain, ts, "Vertex Blur", OB_MODE_VERTEX_GPENCIL, &r_new);
1428  if ((reset) || (r_new)) {
1430  }
1431  /* Vertex Average brush. */
1432  brush = gpencil_brush_ensure(bmain, ts, "Vertex Average", OB_MODE_VERTEX_GPENCIL, &r_new);
1433  if ((reset) || (r_new)) {
1435  }
1436  /* Vertex Smear brush. */
1437  brush = gpencil_brush_ensure(bmain, ts, "Vertex Smear", OB_MODE_VERTEX_GPENCIL, &r_new);
1438  if ((reset) || (r_new)) {
1440  }
1441  /* Vertex Replace brush. */
1442  brush = gpencil_brush_ensure(bmain, ts, "Vertex Replace", OB_MODE_VERTEX_GPENCIL, &r_new);
1443  if ((reset) || (r_new)) {
1445  }
1446 
1447  /* Set default Vertex brush. */
1448  if (reset || brush_prev == NULL) {
1449  BKE_paint_brush_set(vertexpaint, deft_vertex);
1450  }
1451  else {
1452  if (brush_prev != NULL) {
1453  BKE_paint_brush_set(vertexpaint, brush_prev);
1454  }
1455  }
1456 }
1457 
1458 /* Create a set of grease pencil Sculpt Paint presets. */
1460 {
1461  bool r_new = false;
1462 
1463  Paint *sculptpaint = &ts->gp_sculptpaint->paint;
1464  Brush *brush_prev = sculptpaint->brush;
1465  Brush *brush, *deft_sculpt;
1466 
1467  /* Smooth brush. */
1468  brush = gpencil_brush_ensure(bmain, ts, "Smooth Stroke", OB_MODE_SCULPT_GPENCIL, &r_new);
1469  if ((reset) || (r_new)) {
1471  }
1472  deft_sculpt = brush;
1473 
1474  /* Strength brush. */
1475  brush = gpencil_brush_ensure(bmain, ts, "Strength Stroke", OB_MODE_SCULPT_GPENCIL, &r_new);
1476  if ((reset) || (r_new)) {
1478  }
1479 
1480  /* Thickness brush. */
1481  brush = gpencil_brush_ensure(bmain, ts, "Thickness Stroke", OB_MODE_SCULPT_GPENCIL, &r_new);
1482  if ((reset) || (r_new)) {
1484  }
1485 
1486  /* Grab brush. */
1487  brush = gpencil_brush_ensure(bmain, ts, "Grab Stroke", OB_MODE_SCULPT_GPENCIL, &r_new);
1488  if ((reset) || (r_new)) {
1490  }
1491 
1492  /* Push brush. */
1493  brush = gpencil_brush_ensure(bmain, ts, "Push Stroke", OB_MODE_SCULPT_GPENCIL, &r_new);
1494  if ((reset) || (r_new)) {
1496  }
1497 
1498  /* Twist brush. */
1499  brush = gpencil_brush_ensure(bmain, ts, "Twist Stroke", OB_MODE_SCULPT_GPENCIL, &r_new);
1500  if ((reset) || (r_new)) {
1502  }
1503 
1504  /* Pinch brush. */
1505  brush = gpencil_brush_ensure(bmain, ts, "Pinch Stroke", OB_MODE_SCULPT_GPENCIL, &r_new);
1506  if ((reset) || (r_new)) {
1508  }
1509 
1510  /* Randomize brush. */
1511  brush = gpencil_brush_ensure(bmain, ts, "Randomize Stroke", OB_MODE_SCULPT_GPENCIL, &r_new);
1512  if ((reset) || (r_new)) {
1514  }
1515 
1516  /* Clone brush. */
1517  brush = gpencil_brush_ensure(bmain, ts, "Clone Stroke", OB_MODE_SCULPT_GPENCIL, &r_new);
1518  if ((reset) || (r_new)) {
1520  }
1521 
1522  /* Set default brush. */
1523  if (reset || brush_prev == NULL) {
1524  BKE_paint_brush_set(sculptpaint, deft_sculpt);
1525  }
1526  else {
1527  if (brush_prev != NULL) {
1528  BKE_paint_brush_set(sculptpaint, brush_prev);
1529  }
1530  }
1531 }
1532 
1533 /* Create a set of grease pencil Weight Paint presets. */
1535 {
1536  bool r_new = false;
1537 
1538  Paint *weightpaint = &ts->gp_weightpaint->paint;
1539  Brush *brush_prev = weightpaint->brush;
1540  Brush *brush, *deft_weight;
1541  /* Vertex Draw brush. */
1542  brush = gpencil_brush_ensure(bmain, ts, "Draw Weight", OB_MODE_WEIGHT_GPENCIL, &r_new);
1543  if ((reset) || (r_new)) {
1545  }
1546  deft_weight = brush; /* save default brush. */
1547 
1548  /* Set default brush. */
1549  if (reset || brush_prev == NULL) {
1550  BKE_paint_brush_set(weightpaint, deft_weight);
1551  }
1552  else {
1553  if (brush_prev != NULL) {
1554  BKE_paint_brush_set(weightpaint, brush_prev);
1555  }
1556  }
1557 }
1558 
1559 struct Brush *BKE_brush_first_search(struct Main *bmain, const eObjectMode ob_mode)
1560 {
1561  Brush *brush;
1562 
1563  for (brush = bmain->brushes.first; brush; brush = brush->id.next) {
1564  if (brush->ob_mode & ob_mode) {
1565  return brush;
1566  }
1567  }
1568  return NULL;
1569 }
1570 
1572 {
1573  /* create a fake brush and set it to the defaults */
1574  Brush def = {{NULL}};
1575  brush_defaults(&def);
1576 
1577 #define BR_TEST(field, t) \
1578  if (br->field != def.field) { \
1579  printf("br->" #field " = %" #t ";\n", br->field); \
1580  } \
1581  ((void)0)
1582 
1583 #define BR_TEST_FLAG(_f) \
1584  if ((br->flag & _f) && !(def.flag & _f)) { \
1585  printf("br->flag |= " #_f ";\n"); \
1586  } \
1587  else if (!(br->flag & _f) && (def.flag & _f)) { \
1588  printf("br->flag &= ~" #_f ";\n"); \
1589  } \
1590  ((void)0)
1591 
1592 #define BR_TEST_FLAG_OVERLAY(_f) \
1593  if ((br->overlay_flags & _f) && !(def.overlay_flags & _f)) { \
1594  printf("br->overlay_flags |= " #_f ";\n"); \
1595  } \
1596  else if (!(br->overlay_flags & _f) && (def.overlay_flags & _f)) { \
1597  printf("br->overlay_flags &= ~" #_f ";\n"); \
1598  } \
1599  ((void)0)
1600 
1601  /* print out any non-default brush state */
1602  BR_TEST(normal_weight, f);
1603 
1604  BR_TEST(blend, d);
1605  BR_TEST(size, d);
1606 
1607  /* br->flag */
1631 
1638 
1639  BR_TEST(jitter, f);
1640  BR_TEST(spacing, d);
1643  BR_TEST(rate, f);
1644 
1645  BR_TEST(alpha, f);
1646 
1647  BR_TEST(sculpt_plane, d);
1648 
1649  BR_TEST(plane_offset, f);
1650 
1652 
1654 
1656 
1657  BR_TEST(plane_trim, f);
1658 
1661 
1662  BR_TEST(add_col[0], f);
1663  BR_TEST(add_col[1], f);
1664  BR_TEST(add_col[2], f);
1665  BR_TEST(add_col[3], f);
1666  BR_TEST(sub_col[0], f);
1667  BR_TEST(sub_col[1], f);
1668  BR_TEST(sub_col[2], f);
1669  BR_TEST(sub_col[3], f);
1670 
1671  printf("\n");
1672 
1673 #undef BR_TEST
1674 #undef BR_TEST_FLAG
1675 }
1676 
1678 {
1679  /* enable this to see any non-default
1680  * settings used by a brush: */
1681  // BKE_brush_debug_print_state(br);
1682 
1683  brush_defaults(br);
1685 
1686  /* Use the curve presets by default */
1688 
1689  /* Note that sculpt defaults where set when 0.5 was the default (now it's 1.0)
1690  * assign this so logic below can remain the same. */
1691  br->alpha = 0.5f;
1692 
1693  /* Brush settings */
1694  switch (br->sculpt_tool) {
1696  br->flag |= BRUSH_DIR_IN;
1698  br->spacing = 5;
1699  break;
1702  br->spacing = 10;
1703  br->alpha = 1.0f;
1704  break;
1706  br->spacing = 10;
1707  br->alpha = 1.0f;
1709  break;
1710  case SCULPT_TOOL_CLAY:
1711  br->flag |= BRUSH_SIZE_PRESSURE;
1712  br->spacing = 3;
1713  br->autosmooth_factor = 0.25f;
1714  br->normal_radius_factor = 0.75f;
1715  br->hardness = 0.65f;
1716  break;
1718  br->alpha = 0.5f;
1719  br->normal_radius_factor = 1.0f;
1720  br->spacing = 6;
1721  br->hardness = 0.5f;
1722  br->flag |= BRUSH_SIZE_PRESSURE;
1723  br->flag &= ~BRUSH_SPACE_ATTEN;
1724  break;
1727  br->flag &= ~BRUSH_SPACE_ATTEN;
1728  br->alpha = 0.6f;
1729  br->spacing = 5;
1730  br->normal_radius_factor = 1.55f;
1731  br->tip_roundness = 0.18f;
1733  break;
1736  br->alpha = 0.7f;
1737  br->normal_radius_factor = 0.70f;
1738  br->multiplane_scrape_angle = 60;
1740  br->spacing = 5;
1741  break;
1742  case SCULPT_TOOL_CREASE:
1743  br->flag |= BRUSH_DIR_IN;
1744  br->alpha = 0.25;
1745  break;
1746  case SCULPT_TOOL_SCRAPE:
1747  case SCULPT_TOOL_FILL:
1748  br->alpha = 0.7f;
1749  br->area_radius_factor = 0.5f;
1750  br->spacing = 7;
1751  br->flag |= BRUSH_ACCUMULATE;
1753  break;
1754  case SCULPT_TOOL_ROTATE:
1755  br->alpha = 1.0;
1756  break;
1757  case SCULPT_TOOL_SMOOTH:
1758  br->flag &= ~BRUSH_SPACE_ATTEN;
1759  br->spacing = 5;
1760  br->alpha = 0.7f;
1762  br->surface_smooth_current_vertex = 0.5f;
1763  br->surface_smooth_iterations = 4;
1764  break;
1766  br->alpha = 1.0f;
1767  br->rake_factor = 1.0f;
1768  break;
1769  case SCULPT_TOOL_THUMB:
1770  br->size = 75;
1771  br->flag &= ~BRUSH_ALPHA_PRESSURE;
1772  br->flag &= ~BRUSH_SPACE;
1773  br->flag &= ~BRUSH_SPACE_ATTEN;
1774  break;
1778  br->flag &= ~BRUSH_ALPHA_PRESSURE;
1779  br->flag &= ~BRUSH_SPACE;
1780  br->flag &= ~BRUSH_SPACE_ATTEN;
1781  break;
1782  case SCULPT_TOOL_POSE:
1783  br->pose_smooth_iterations = 4;
1784  br->pose_ik_segments = 1;
1786  br->flag &= ~BRUSH_ALPHA_PRESSURE;
1787  br->flag &= ~BRUSH_SPACE;
1788  br->flag &= ~BRUSH_SPACE_ATTEN;
1789  break;
1790  case SCULPT_TOOL_BOUNDARY:
1791  br->flag &= ~BRUSH_ALPHA_PRESSURE;
1792  br->flag &= ~BRUSH_SPACE;
1793  br->flag &= ~BRUSH_SPACE_ATTEN;
1795  break;
1797  br->alpha = 0.5f;
1798  br->flag &= ~BRUSH_ALPHA_PRESSURE;
1799  br->flag &= ~BRUSH_SPACE;
1800  br->flag &= ~BRUSH_SPACE_ATTEN;
1801  break;
1802  case SCULPT_TOOL_GRAB:
1803  br->alpha = 0.4f;
1804  br->size = 75;
1805  br->flag &= ~BRUSH_ALPHA_PRESSURE;
1806  br->flag &= ~BRUSH_SPACE;
1807  br->flag &= ~BRUSH_SPACE_ATTEN;
1808  break;
1809  case SCULPT_TOOL_CLOTH:
1810  br->cloth_mass = 1.0f;
1811  br->cloth_damping = 0.01f;
1812  br->cloth_sim_limit = 2.5f;
1813  br->cloth_sim_falloff = 0.75f;
1816  break;
1817  case SCULPT_TOOL_LAYER:
1818  br->flag &= ~BRUSH_SPACE_ATTEN;
1819  br->hardness = 0.35f;
1820  br->alpha = 1.0f;
1821  br->height = 0.05f;
1822  break;
1823  case SCULPT_TOOL_PAINT:
1824  br->hardness = 0.4f;
1825  br->spacing = 10;
1826  br->alpha = 0.6f;
1827  br->flow = 1.0f;
1828  br->tip_scale_x = 1.0f;
1829  br->tip_roundness = 1.0f;
1830  br->density = 1.0f;
1831  br->flag &= ~BRUSH_SPACE_ATTEN;
1832  zero_v3(br->rgb);
1833  break;
1834  case SCULPT_TOOL_SMEAR:
1835  br->alpha = 1.0f;
1836  br->spacing = 5;
1837  br->flag &= ~BRUSH_ALPHA_PRESSURE;
1838  br->flag &= ~BRUSH_SPACE_ATTEN;
1840  break;
1842  br->alpha = 1.0f;
1843  br->spacing = 5;
1844  br->hardness = 0.7f;
1845  br->flag &= ~BRUSH_ALPHA_PRESSURE;
1846  br->flag &= ~BRUSH_SPACE_ATTEN;
1848  break;
1849  default:
1850  break;
1851  }
1852 
1853  /* Cursor colors */
1854 
1855  /* Default Alpha */
1856  br->add_col[3] = 0.90f;
1857  br->sub_col[3] = 0.90f;
1858 
1859  switch (br->sculpt_tool) {
1860  case SCULPT_TOOL_DRAW:
1862  case SCULPT_TOOL_CLAY:
1865  case SCULPT_TOOL_LAYER:
1866  case SCULPT_TOOL_INFLATE:
1867  case SCULPT_TOOL_BLOB:
1868  case SCULPT_TOOL_CREASE:
1869  br->add_col[0] = 0.0f;
1870  br->add_col[1] = 0.5f;
1871  br->add_col[2] = 1.0f;
1872  br->sub_col[0] = 0.0f;
1873  br->sub_col[1] = 0.5f;
1874  br->sub_col[2] = 1.0f;
1875  break;
1876 
1877  case SCULPT_TOOL_SMOOTH:
1878  case SCULPT_TOOL_FLATTEN:
1879  case SCULPT_TOOL_FILL:
1880  case SCULPT_TOOL_SCRAPE:
1882  br->add_col[0] = 0.877f;
1883  br->add_col[1] = 0.142f;
1884  br->add_col[2] = 0.117f;
1885  br->sub_col[0] = 0.877f;
1886  br->sub_col[1] = 0.142f;
1887  br->sub_col[2] = 0.117f;
1888  break;
1889 
1890  case SCULPT_TOOL_PINCH:
1891  case SCULPT_TOOL_GRAB:
1893  case SCULPT_TOOL_THUMB:
1894  case SCULPT_TOOL_NUDGE:
1895  case SCULPT_TOOL_ROTATE:
1897  case SCULPT_TOOL_POSE:
1898  case SCULPT_TOOL_BOUNDARY:
1900  br->add_col[0] = 1.0f;
1901  br->add_col[1] = 0.95f;
1902  br->add_col[2] = 0.005f;
1903  br->sub_col[0] = 1.0f;
1904  br->sub_col[1] = 0.95f;
1905  br->sub_col[2] = 0.005f;
1906  break;
1907 
1908  case SCULPT_TOOL_SIMPLIFY:
1909  case SCULPT_TOOL_PAINT:
1910  case SCULPT_TOOL_MASK:
1914  br->add_col[0] = 0.75f;
1915  br->add_col[1] = 0.75f;
1916  br->add_col[2] = 0.75f;
1917  br->sub_col[0] = 0.75f;
1918  br->sub_col[1] = 0.75f;
1919  br->sub_col[2] = 0.75f;
1920  break;
1921 
1922  case SCULPT_TOOL_CLOTH:
1923  br->add_col[0] = 1.0f;
1924  br->add_col[1] = 0.5f;
1925  br->add_col[2] = 0.1f;
1926  br->sub_col[0] = 1.0f;
1927  br->sub_col[1] = 0.5f;
1928  br->sub_col[2] = 0.1f;
1929  break;
1930  default:
1931  break;
1932  }
1933 }
1934 
1939 {
1940  CurveMapping *cumap = NULL;
1941  CurveMap *cuma = NULL;
1942 
1943  if (!b->curve) {
1944  b->curve = BKE_curvemapping_add(1, 0, 0, 1, 1);
1945  }
1946  cumap = b->curve;
1947  cumap->flag &= ~CUMA_EXTEND_EXTRAPOLATE;
1948  cumap->preset = preset;
1949 
1950  cuma = b->curve->cm;
1951  BKE_curvemap_reset(cuma, &cumap->clipr, cumap->preset, CURVEMAP_SLOPE_NEGATIVE);
1952  BKE_curvemapping_changed(cumap, false);
1953 }
1954 
1955 /* Generic texture sampler for 3D painting systems. point has to be either in
1956  * region space mouse coordinates, or 3d world coordinates for 3D mapping.
1957  *
1958  * rgba outputs straight alpha. */
1960  const Brush *br,
1961  const float point[3],
1962  float rgba[4],
1963  const int thread,
1964  struct ImagePool *pool)
1965 {
1967  const MTex *mtex = &br->mtex;
1968  float intensity = 1.0;
1969  bool hasrgb = false;
1970 
1971  if (!mtex->tex) {
1972  intensity = 1;
1973  }
1974  else if (mtex->brush_map_mode == MTEX_MAP_MODE_3D) {
1975  /* Get strength by feeding the vertex
1976  * location directly into a texture */
1977  hasrgb = RE_texture_evaluate(mtex, point, thread, pool, false, false, &intensity, rgba);
1978  }
1979  else if (mtex->brush_map_mode == MTEX_MAP_MODE_STENCIL) {
1980  float rotation = -mtex->rot;
1981  const float point_2d[2] = {point[0], point[1]};
1982  float x, y;
1983  float co[3];
1984 
1985  x = point_2d[0] - br->stencil_pos[0];
1986  y = point_2d[1] - br->stencil_pos[1];
1987 
1988  if (rotation > 0.001f || rotation < -0.001f) {
1989  const float angle = atan2f(y, x) + rotation;
1990  const float flen = sqrtf(x * x + y * y);
1991 
1992  x = flen * cosf(angle);
1993  y = flen * sinf(angle);
1994  }
1995 
1996  if (fabsf(x) > br->stencil_dimension[0] || fabsf(y) > br->stencil_dimension[1]) {
1997  zero_v4(rgba);
1998  return 0.0f;
1999  }
2000  x /= (br->stencil_dimension[0]);
2001  y /= (br->stencil_dimension[1]);
2002 
2003  co[0] = x;
2004  co[1] = y;
2005  co[2] = 0.0f;
2006 
2007  hasrgb = RE_texture_evaluate(mtex, co, thread, pool, false, false, &intensity, rgba);
2008  }
2009  else {
2010  float rotation = -mtex->rot;
2011  const float point_2d[2] = {point[0], point[1]};
2012  float x = 0.0f, y = 0.0f; /* Quite warnings */
2013  float invradius = 1.0f; /* Quite warnings */
2014  float co[3];
2015 
2017  /* keep coordinates relative to mouse */
2018 
2019  rotation += ups->brush_rotation;
2020 
2021  x = point_2d[0] - ups->tex_mouse[0];
2022  y = point_2d[1] - ups->tex_mouse[1];
2023 
2024  /* use pressure adjusted size for fixed mode */
2025  invradius = 1.0f / ups->pixel_radius;
2026  }
2027  else if (mtex->brush_map_mode == MTEX_MAP_MODE_TILED) {
2028  /* leave the coordinates relative to the screen */
2029 
2030  /* use unadjusted size for tiled mode */
2031  invradius = 1.0f / BKE_brush_size_get(scene, br);
2032 
2033  x = point_2d[0];
2034  y = point_2d[1];
2035  }
2036  else if (mtex->brush_map_mode == MTEX_MAP_MODE_RANDOM) {
2037  rotation += ups->brush_rotation;
2038  /* these contain a random coordinate */
2039  x = point_2d[0] - ups->tex_mouse[0];
2040  y = point_2d[1] - ups->tex_mouse[1];
2041 
2042  invradius = 1.0f / ups->pixel_radius;
2043  }
2044 
2045  x *= invradius;
2046  y *= invradius;
2047 
2048  /* it is probably worth optimizing for those cases where
2049  * the texture is not rotated by skipping the calls to
2050  * atan2, sqrtf, sin, and cos. */
2051  if (rotation > 0.001f || rotation < -0.001f) {
2052  const float angle = atan2f(y, x) + rotation;
2053  const float flen = sqrtf(x * x + y * y);
2054 
2055  x = flen * cosf(angle);
2056  y = flen * sinf(angle);
2057  }
2058 
2059  co[0] = x;
2060  co[1] = y;
2061  co[2] = 0.0f;
2062 
2063  hasrgb = RE_texture_evaluate(mtex, co, thread, pool, false, false, &intensity, rgba);
2064  }
2065 
2066  intensity += br->texture_sample_bias;
2067 
2068  if (!hasrgb) {
2069  rgba[0] = intensity;
2070  rgba[1] = intensity;
2071  rgba[2] = intensity;
2072  rgba[3] = 1.0f;
2073  }
2074  /* For consistency, sampling always returns color in linear space */
2075  else if (ups->do_linear_conversion) {
2077  }
2078 
2079  return intensity;
2080 }
2081 
2083  const Scene *scene, Brush *br, const float point[2], const int thread, struct ImagePool *pool)
2084 {
2086  MTex *mtex = &br->mask_mtex;
2087  float rgba[4], intensity;
2088 
2089  if (!mtex->tex) {
2090  return 1.0f;
2091  }
2093  float rotation = -mtex->rot;
2094  const float point_2d[2] = {point[0], point[1]};
2095  float x, y;
2096  float co[3];
2097 
2098  x = point_2d[0] - br->mask_stencil_pos[0];
2099  y = point_2d[1] - br->mask_stencil_pos[1];
2100 
2101  if (rotation > 0.001f || rotation < -0.001f) {
2102  const float angle = atan2f(y, x) + rotation;
2103  const float flen = sqrtf(x * x + y * y);
2104 
2105  x = flen * cosf(angle);
2106  y = flen * sinf(angle);
2107  }
2108 
2109  if (fabsf(x) > br->mask_stencil_dimension[0] || fabsf(y) > br->mask_stencil_dimension[1]) {
2110  zero_v4(rgba);
2111  return 0.0f;
2112  }
2113  x /= (br->mask_stencil_dimension[0]);
2114  y /= (br->mask_stencil_dimension[1]);
2115 
2116  co[0] = x;
2117  co[1] = y;
2118  co[2] = 0.0f;
2119 
2120  RE_texture_evaluate(mtex, co, thread, pool, false, false, &intensity, rgba);
2121  }
2122  else {
2123  float rotation = -mtex->rot;
2124  const float point_2d[2] = {point[0], point[1]};
2125  float x = 0.0f, y = 0.0f; /* Quite warnings */
2126  float invradius = 1.0f; /* Quite warnings */
2127  float co[3];
2128 
2130  /* keep coordinates relative to mouse */
2131 
2132  rotation += ups->brush_rotation_sec;
2133 
2134  x = point_2d[0] - ups->mask_tex_mouse[0];
2135  y = point_2d[1] - ups->mask_tex_mouse[1];
2136 
2137  /* use pressure adjusted size for fixed mode */
2138  invradius = 1.0f / ups->pixel_radius;
2139  }
2140  else if (mtex->brush_map_mode == MTEX_MAP_MODE_TILED) {
2141  /* leave the coordinates relative to the screen */
2142 
2143  /* use unadjusted size for tiled mode */
2144  invradius = 1.0f / BKE_brush_size_get(scene, br);
2145 
2146  x = point_2d[0];
2147  y = point_2d[1];
2148  }
2149  else if (mtex->brush_map_mode == MTEX_MAP_MODE_RANDOM) {
2150  rotation += ups->brush_rotation_sec;
2151  /* these contain a random coordinate */
2152  x = point_2d[0] - ups->mask_tex_mouse[0];
2153  y = point_2d[1] - ups->mask_tex_mouse[1];
2154 
2155  invradius = 1.0f / ups->pixel_radius;
2156  }
2157 
2158  x *= invradius;
2159  y *= invradius;
2160 
2161  /* it is probably worth optimizing for those cases where
2162  * the texture is not rotated by skipping the calls to
2163  * atan2, sqrtf, sin, and cos. */
2164  if (rotation > 0.001f || rotation < -0.001f) {
2165  const float angle = atan2f(y, x) + rotation;
2166  const float flen = sqrtf(x * x + y * y);
2167 
2168  x = flen * cosf(angle);
2169  y = flen * sinf(angle);
2170  }
2171 
2172  co[0] = x;
2173  co[1] = y;
2174  co[2] = 0.0f;
2175 
2176  RE_texture_evaluate(mtex, co, thread, pool, false, false, &intensity, rgba);
2177  }
2178 
2179  CLAMP(intensity, 0.0f, 1.0f);
2180 
2181  switch (br->mask_pressure) {
2183  intensity = ((1.0f - intensity) < ups->size_pressure_value) ? 1.0f : 0.0f;
2184  break;
2186  intensity = ups->size_pressure_value + intensity * (1.0f - ups->size_pressure_value);
2187  break;
2188  default:
2189  break;
2190  }
2191 
2192  return intensity;
2193 }
2194 
2195 /* Unified Size / Strength / Color */
2196 
2197 /* XXX: be careful about setting size and unprojected radius
2198  * because they depend on one another
2199  * these functions do not set the other corresponding value
2200  * this can lead to odd behavior if size and unprojected
2201  * radius become inconsistent.
2202  * the biggest problem is that it isn't possible to change
2203  * unprojected radius because a view context is not
2204  * available. my usual solution to this is to use the
2205  * ratio of change of the size to change the unprojected
2206  * radius. Not completely convinced that is correct.
2207  * In any case, a better solution is needed to prevent
2208  * inconsistency. */
2209 
2210 const float *BKE_brush_color_get(const struct Scene *scene, const struct Brush *brush)
2211 {
2213  return (ups->flag & UNIFIED_PAINT_COLOR) ? ups->rgb : brush->rgb;
2214 }
2215 
2216 const float *BKE_brush_secondary_color_get(const struct Scene *scene, const struct Brush *brush)
2217 {
2219  return (ups->flag & UNIFIED_PAINT_COLOR) ? ups->secondary_rgb : brush->secondary_rgb;
2220 }
2221 
2222 void BKE_brush_color_set(struct Scene *scene, struct Brush *brush, const float color[3])
2223 {
2225 
2226  if (ups->flag & UNIFIED_PAINT_COLOR) {
2227  copy_v3_v3(ups->rgb, color);
2228  }
2229  else {
2230  copy_v3_v3(brush->rgb, color);
2231  }
2232 }
2233 
2235 {
2237 
2238  /* make sure range is sane */
2240 
2241  if (ups->flag & UNIFIED_PAINT_SIZE) {
2242  ups->size = size;
2243  }
2244  else {
2245  brush->size = size;
2246  }
2247 }
2248 
2249 int BKE_brush_size_get(const Scene *scene, const Brush *brush)
2250 {
2252  int size = (ups->flag & UNIFIED_PAINT_SIZE) ? ups->size : brush->size;
2253 
2254  return size;
2255 }
2256 
2257 bool BKE_brush_use_locked_size(const Scene *scene, const Brush *brush)
2258 {
2259  const short us_flag = scene->toolsettings->unified_paint_settings.flag;
2260 
2261  return (us_flag & UNIFIED_PAINT_SIZE) ? (us_flag & UNIFIED_PAINT_BRUSH_LOCK_SIZE) :
2262  (brush->flag & BRUSH_LOCK_SIZE);
2263 }
2264 
2266 {
2267  return brush->flag & BRUSH_SIZE_PRESSURE;
2268 }
2269 
2271 {
2272  return brush->flag & BRUSH_ALPHA_PRESSURE;
2273 }
2274 
2276 {
2277  return ELEM(brush->sculpt_tool,
2292 }
2293 
2295 {
2297 
2298  if (ups->flag & UNIFIED_PAINT_SIZE) {
2300  }
2301  else {
2303  }
2304 }
2305 
2307 {
2309 
2310  return (ups->flag & UNIFIED_PAINT_SIZE) ? ups->unprojected_radius : brush->unprojected_radius;
2311 }
2312 
2314 {
2316 
2317  if (ups->flag & UNIFIED_PAINT_ALPHA) {
2318  ups->alpha = alpha;
2319  }
2320  else {
2321  brush->alpha = alpha;
2322  }
2323 }
2324 
2325 float BKE_brush_alpha_get(const Scene *scene, const Brush *brush)
2326 {
2328 
2329  return (ups->flag & UNIFIED_PAINT_ALPHA) ? ups->alpha : brush->alpha;
2330 }
2331 
2332 float BKE_brush_weight_get(const Scene *scene, const Brush *brush)
2333 {
2335 
2336  return (ups->flag & UNIFIED_PAINT_WEIGHT) ? ups->weight : brush->weight;
2337 }
2338 
2339 void BKE_brush_weight_set(const Scene *scene, Brush *brush, float value)
2340 {
2342 
2343  if (ups->flag & UNIFIED_PAINT_WEIGHT) {
2344  ups->weight = value;
2345  }
2346  else {
2347  brush->weight = value;
2348  }
2349 }
2350 
2351 /* scale unprojected radius to reflect a change in the brush's 2D size */
2353  int new_brush_size,
2354  int old_brush_size)
2355 {
2356  float scale = new_brush_size;
2357  /* avoid division by zero */
2358  if (old_brush_size != 0) {
2359  scale /= (float)old_brush_size;
2360  }
2361  (*unprojected_radius) *= scale;
2362 }
2363 
2364 /* scale brush size to reflect a change in the brush's unprojected radius */
2365 void BKE_brush_scale_size(int *r_brush_size,
2366  float new_unprojected_radius,
2367  float old_unprojected_radius)
2368 {
2369  float scale = new_unprojected_radius;
2370  /* avoid division by zero */
2371  if (old_unprojected_radius != 0) {
2372  scale /= new_unprojected_radius;
2373  }
2374  (*r_brush_size) = (int)((float)(*r_brush_size) * scale);
2375 }
2376 
2377 void BKE_brush_jitter_pos(const Scene *scene, Brush *brush, const float pos[2], float jitterpos[2])
2378 {
2379  float rand_pos[2];
2380  float spread;
2381  int diameter;
2382 
2383  do {
2384  rand_pos[0] = BLI_rng_get_float(brush_rng) - 0.5f;
2385  rand_pos[1] = BLI_rng_get_float(brush_rng) - 0.5f;
2386  } while (len_squared_v2(rand_pos) > square_f(0.5f));
2387 
2388  if (brush->flag & BRUSH_ABSOLUTE_JITTER) {
2389  diameter = 2 * brush->jitter_absolute;
2390  spread = 1.0;
2391  }
2392  else {
2393  diameter = 2 * BKE_brush_size_get(scene, brush);
2394  spread = brush->jitter;
2395  }
2396  /* find random position within a circle of diameter 1 */
2397  jitterpos[0] = pos[0] + 2 * rand_pos[0] * diameter * spread;
2398  jitterpos[1] = pos[1] + 2 * rand_pos[1] * diameter * spread;
2399 }
2400 
2402 {
2403  /* we multiply with brush radius as an optimization for the brush
2404  * texture sampling functions */
2405  if (mask) {
2408  }
2409  else {
2412  }
2413 }
2414 
2415 /* Uses the brush curve control to find a strength value */
2416 float BKE_brush_curve_strength(const Brush *br, float p, const float len)
2417 {
2418  float strength = 1.0f;
2419 
2420  if (p >= len) {
2421  return 0;
2422  }
2423 
2424  p = p / len;
2425  p = 1.0f - p;
2426 
2427  switch (br->curve_preset) {
2428  case BRUSH_CURVE_CUSTOM:
2429  strength = BKE_curvemapping_evaluateF(br->curve, 0, 1.0f - p);
2430  break;
2431  case BRUSH_CURVE_SHARP:
2432  strength = p * p;
2433  break;
2434  case BRUSH_CURVE_SMOOTH:
2435  strength = 3.0f * p * p - 2.0f * p * p * p;
2436  break;
2437  case BRUSH_CURVE_SMOOTHER:
2438  strength = pow3f(p) * (p * (p * 6.0f - 15.0f) + 10.0f);
2439  break;
2440  case BRUSH_CURVE_ROOT:
2441  strength = sqrtf(p);
2442  break;
2443  case BRUSH_CURVE_LIN:
2444  strength = p;
2445  break;
2446  case BRUSH_CURVE_CONSTANT:
2447  strength = 1.0f;
2448  break;
2449  case BRUSH_CURVE_SPHERE:
2450  strength = sqrtf(2 * p - p * p);
2451  break;
2452  case BRUSH_CURVE_POW4:
2453  strength = p * p * p * p;
2454  break;
2455  case BRUSH_CURVE_INVSQUARE:
2456  strength = p * (2.0f - p);
2457  break;
2458  }
2459 
2460  return strength;
2461 }
2462 
2463 /* Uses the brush curve control to find a strength value between 0 and 1 */
2464 float BKE_brush_curve_strength_clamped(Brush *br, float p, const float len)
2465 {
2466  float strength = BKE_brush_curve_strength(br, p, len);
2467 
2468  CLAMP(strength, 0.0f, 1.0f);
2469 
2470  return strength;
2471 }
2472 
2473 /* TODO: should probably be unified with BrushPainter stuff? */
2474 unsigned int *BKE_brush_gen_texture_cache(Brush *br, int half_side, bool use_secondary)
2475 {
2476  unsigned int *texcache = NULL;
2477  MTex *mtex = (use_secondary) ? &br->mask_mtex : &br->mtex;
2478  float intensity;
2479  float rgba_dummy[4];
2480  int ix, iy;
2481  int side = half_side * 2;
2482 
2483  if (mtex->tex) {
2484  float x, y, step = 2.0 / side, co[3];
2485 
2486  texcache = MEM_callocN(sizeof(int) * side * side, "Brush texture cache");
2487 
2488  /* do normalized canonical view coords for texture */
2489  for (y = -1.0, iy = 0; iy < side; iy++, y += step) {
2490  for (x = -1.0, ix = 0; ix < side; ix++, x += step) {
2491  co[0] = x;
2492  co[1] = y;
2493  co[2] = 0.0f;
2494 
2495  /* This is copied from displace modifier code */
2496  /* TODO(sergey): brush are always caching with CM enabled for now. */
2497  RE_texture_evaluate(mtex, co, 0, NULL, false, false, &intensity, rgba_dummy);
2498  copy_v4_uchar((uchar *)&texcache[iy * side + ix], (char)(intensity * 255.0f));
2499  }
2500  }
2501  }
2502 
2503  return texcache;
2504 }
2505 
2506 /**** Radial Control ****/
2507 struct ImBuf *BKE_brush_gen_radial_control_imbuf(Brush *br, bool secondary, bool display_gradient)
2508 {
2509  ImBuf *im = MEM_callocN(sizeof(ImBuf), "radial control texture");
2510  unsigned int *texcache;
2511  int side = 512;
2512  int half = side / 2;
2513  int i, j;
2514 
2516  texcache = BKE_brush_gen_texture_cache(br, half, secondary);
2517  im->rect_float = MEM_callocN(sizeof(float) * side * side, "radial control rect");
2518  im->x = im->y = side;
2519 
2520  if (display_gradient || texcache) {
2521  for (i = 0; i < side; i++) {
2522  for (j = 0; j < side; j++) {
2523  float magn = sqrtf(pow2f(i - half) + pow2f(j - half));
2524  im->rect_float[i * side + j] = BKE_brush_curve_strength_clamped(br, magn, half);
2525  }
2526  }
2527  }
2528 
2529  if (texcache) {
2530  /* Modulate curve with texture */
2531  for (i = 0; i < side; i++) {
2532  for (j = 0; j < side; j++) {
2533  const int col = texcache[i * side + j];
2534  im->rect_float[i * side + j] *= (((char *)&col)[0] + ((char *)&col)[1] +
2535  ((char *)&col)[2]) /
2536  3.0f / 255.0f;
2537  }
2538  }
2539  MEM_freeN(texcache);
2540  }
2541 
2542  return im;
2543 }
typedef float(TangentPoint)[2]
void BKE_curvemapping_init(struct CurveMapping *cumap)
Definition: colortools.c:1200
void BKE_curvemapping_set_defaults(struct CurveMapping *cumap, int tot, float minx, float miny, float maxx, float maxy)
Definition: colortools.c:53
struct CurveMapping * BKE_curvemapping_copy(const struct CurveMapping *cumap)
float BKE_curvemapping_evaluateF(const struct CurveMapping *cumap, int cur, float value)
void BKE_curvemapping_blend_read(struct BlendDataReader *reader, struct CurveMapping *cumap)
Definition: colortools.c:1252
void BKE_curvemap_reset(struct CurveMap *cuma, const struct rctf *clipr, int preset, int slope)
void BKE_curvemapping_changed(struct CurveMapping *cumap, const bool rem_doubles)
Definition: colortools.c:877
void BKE_curvemapping_blend_write(struct BlendWriter *writer, const struct CurveMapping *cumap)
void BKE_curvemapping_free(struct CurveMapping *cumap)
Definition: colortools.c:119
@ CURVEMAP_SLOPE_NEGATIVE
struct CurveMapping * BKE_curvemapping_add(int tot, float minx, float miny, float maxx, float maxy)
Definition: colortools.c:88
void BKE_gpencil_brush_material_set(struct Brush *brush, struct Material *material)
Definition: gpencil.c:1804
void BKE_previewimg_free(struct PreviewImage **prv)
Definition: icons.cc:295
void BKE_previewimg_id_copy(struct ID *new_id, const struct ID *old_id)
@ IDTYPE_FLAGS_NO_ANIMDATA
Definition: BKE_idtype.h:51
struct ID * BKE_id_copy(struct Main *bmain, const struct ID *id)
void BKE_lib_id_expand_local(struct Main *bmain, struct ID *id)
Definition: lib_id.c:393
void id_us_min(struct ID *id)
Definition: lib_id.c:297
void id_fake_user_set(struct ID *id)
Definition: lib_id.c:328
@ LIB_ID_COPY_NO_PREVIEW
Definition: BKE_lib_id.h:116
bool BKE_lib_id_make_local(struct Main *bmain, struct ID *id, const bool test, const int flags)
Definition: lib_id.c:479
@ LIB_ID_MAKELOCAL_FULL_LIBRARY
Definition: BKE_lib_id.h:240
void BKE_id_blend_write(struct BlendWriter *writer, struct ID *id)
Definition: lib_id.c:2395
void id_us_plus_no_lib(struct ID *id)
Definition: lib_id.c:272
bool void BKE_lib_id_clear_library_data(struct Main *bmain, struct ID *id)
Definition: lib_id.c:202
void BKE_id_delete(struct Main *bmain, void *idv) ATTR_NONNULL()
void * BKE_id_new(struct Main *bmain, const short type, const char *name)
Definition: lib_id.c:1177
void BKE_lib_id_swap(struct Main *bmain, struct ID *id_a, struct ID *id_b)
Definition: lib_id.c:729
@ IDWALK_NOP
#define BKE_LIB_FOREACHID_PROCESS(_data, _id_super, _cb_flag)
void BKE_library_foreach_ID_link(struct Main *bmain, struct ID *id, LibraryIDLinkCallback callback, void *user_data, int flag)
Definition: lib_query.c:322
@ IDWALK_RET_NOP
Definition: BKE_lib_query.h:97
bool BKE_library_ID_is_indirectly_used(struct Main *bmain, void *idv)
Definition: lib_query.c:588
void BKE_library_ID_test_usages(struct Main *bmain, void *idv, bool *is_used_local, bool *is_used_linked)
Definition: lib_query.c:597
@ IDWALK_CB_USER
Definition: BKE_lib_query.h:87
@ IDWALK_CB_NOP
Definition: BKE_lib_query.h:47
void void BKE_libblock_remap(struct Main *bmain, void *old_idv, void *new_idv, const short remap_flags) ATTR_NONNULL(1
@ ID_REMAP_SKIP_INDIRECT_USAGE
Definition: BKE_lib_remap.h:46
General operations, lookup, etc. for materials.
struct Material * BKE_gpencil_material_add(struct Main *bmain, const char *name)
Definition: material.c:310
void BKE_paint_brush_set(struct Paint *paint, struct Brush *br)
Definition: paint.c:609
void BKE_texture_mtex_foreach_id(struct LibraryForeachIDData *data, struct MTex *mtex)
Definition: texture.c:235
#define BLI_assert(a)
Definition: BLI_assert.h:58
void * BLI_findstring(const struct ListBase *listbase, const char *id, const int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
MINLINE float pow2f(float x)
MINLINE float square_f(float a)
MINLINE float pow3f(float x)
#define DEG2RAD(_deg)
MINLINE float len_squared_v2(const float v[2]) ATTR_WARN_UNUSED_RESULT
MINLINE void copy_v4_uchar(unsigned char r[4], const unsigned char a)
MINLINE void copy_v3_v3(float r[3], const float a[3])
MINLINE void zero_v4(float r[4])
MINLINE void zero_v3(float r[3])
MINLINE void copy_v2_fl(float r[2], float f)
Random number functions.
void BLI_rng_srandom(struct RNG *rng, unsigned int seed) ATTR_NONNULL(1)
Definition: rand.cc:89
void BLI_rng_free(struct RNG *rng) ATTR_NONNULL(1)
Definition: rand.cc:76
struct RNG * BLI_rng_new(unsigned int seed)
Definition: rand.cc:54
float BLI_rng_get_float(struct RNG *rng) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition: rand.cc:120
unsigned char uchar
Definition: BLI_sys_types.h:86
#define SWAP(type, a, b)
#define UNUSED(x)
#define ELEM(...)
#define MEMCMP_STRUCT_AFTER_IS_ZERO(struct_var, member)
#define MEMCPY_STRUCT_AFTER(struct_dst, struct_src, member)
#define BLO_read_data_address(reader, ptr_p)
ID * BLO_read_get_new_id_address(BlendLibReader *reader, struct Library *lib, struct ID *id)
Definition: readfile.c:5615
#define BLO_write_id_struct(writer, struct_name, id_address, id)
#define BLO_write_struct(writer, struct_name, data_ptr)
#define BLO_read_id_address(reader, lib, id_ptr_p)
#define BLO_expand(expander, id)
bool BLO_write_is_undo(BlendWriter *writer)
Definition: writefile.c:1412
#define BLT_I18NCONTEXT_ID_BRUSH
#define ID_EXTRA_USERS(id)
Definition: DNA_ID.h:414
@ LIB_TAG_INDIRECT
Definition: DNA_ID.h:524
#define FILTER_ID_BR
Definition: DNA_ID.h:707
#define ID_IS_LINKED(_id)
Definition: DNA_ID.h:426
#define ID_REAL_USERS(id)
Definition: DNA_ID.h:413
#define ID_NEW_SET(_id, _idn)
Definition: DNA_ID.h:464
@ INDEX_ID_BR
Definition: DNA_ID.h:847
@ ID_BR
Definition: DNA_ID_enums.h:81
@ GPAINT_TOOL_ERASE
@ GPAINT_TOOL_FILL
@ GPAINT_TOOL_DRAW
@ GPAINT_TOOL_TINT
@ GPWEIGHT_TOOL_DRAW
@ GPVERTEX_TOOL_AVERAGE
@ GPVERTEX_TOOL_REPLACE
@ GPVERTEX_TOOL_DRAW
@ GPVERTEX_TOOL_BLUR
@ GPVERTEX_TOOL_SMEAR
@ GP_SCULPT_FLAGMODE_APPLY_POSITION
@ GP_SCULPT_FLAGMODE_APPLY_THICKNESS
@ BRUSH_CURVE_CUSTOM
@ BRUSH_CURVE_SHARP
@ BRUSH_CURVE_INVSQUARE
@ BRUSH_CURVE_SPHERE
@ BRUSH_CURVE_CONSTANT
@ BRUSH_CURVE_POW4
@ BRUSH_CURVE_ROOT
@ BRUSH_CURVE_SMOOTH
@ BRUSH_CURVE_SMOOTHER
@ BRUSH_CURVE_LIN
@ GP_BRUSH_GROUP_RANDOM
@ GP_BRUSH_DEFAULT_ERASER
@ GP_BRUSH_USE_STRENGTH_PRESSURE
@ GP_BRUSH_GROUP_SETTINGS
@ GP_BRUSH_MATERIAL_PINNED
@ GP_BRUSH_FILL_SHOW_EXTENDLINES
@ GP_BRUSH_USE_JITTER_PRESSURE
@ GP_BRUSH_USE_PRESSURE
@ BRUSH_OFFSET_PRESSURE
@ BRUSH_ORIGINAL_NORMAL
@ BRUSH_ALPHA_PRESSURE
@ BRUSH_SPACE_ATTEN
@ BRUSH_LOCK_ALPHA
@ BRUSH_FRONTFACE
@ BRUSH_ADAPTIVE_SPACE
@ BRUSH_DRAG_DOT
@ BRUSH_SPACING_PRESSURE
@ BRUSH_EDGE_TO_EDGE
@ BRUSH_SMOOTH_STROKE
@ BRUSH_ACCUMULATE
@ BRUSH_DIR_IN
@ BRUSH_ANCHORED
@ BRUSH_CUSTOM_ICON
@ BRUSH_JITTER_PRESSURE
@ BRUSH_PLANE_TRIM
@ BRUSH_LOCK_SIZE
@ BRUSH_INVERSE_SMOOTH_PRESSURE
@ BRUSH_ABSOLUTE_JITTER
@ BRUSH_PERSISTENT
@ BRUSH_SIZE_PRESSURE
@ BRUSH_AIRBRUSH
@ BRUSH_SPACE
@ BRUSH_INVERT_TO_SCRAPE_FILL
@ BRUSH_CLOTH_DEFORM_DRAG
@ SCULPT_TOOL_SMOOTH
@ SCULPT_TOOL_CLOTH
@ SCULPT_TOOL_DRAW_SHARP
@ SCULPT_TOOL_NUDGE
@ SCULPT_TOOL_SCRAPE
@ SCULPT_TOOL_THUMB
@ SCULPT_TOOL_SIMPLIFY
@ SCULPT_TOOL_DRAW_FACE_SETS
@ SCULPT_TOOL_GRAB
@ SCULPT_TOOL_INFLATE
@ SCULPT_TOOL_CLAY_THUMB
@ SCULPT_TOOL_DRAW
@ SCULPT_TOOL_FLATTEN
@ SCULPT_TOOL_BOUNDARY
@ SCULPT_TOOL_PAINT
@ SCULPT_TOOL_PINCH
@ SCULPT_TOOL_BLOB
@ SCULPT_TOOL_FILL
@ SCULPT_TOOL_POSE
@ SCULPT_TOOL_LAYER
@ SCULPT_TOOL_DISPLACEMENT_ERASER
@ SCULPT_TOOL_SLIDE_RELAX
@ SCULPT_TOOL_SMEAR
@ SCULPT_TOOL_DISPLACEMENT_SMEAR
@ SCULPT_TOOL_CLAY
@ SCULPT_TOOL_MASK
@ SCULPT_TOOL_MULTIPLANE_SCRAPE
@ SCULPT_TOOL_ROTATE
@ SCULPT_TOOL_ELASTIC_DEFORM
@ SCULPT_TOOL_SNAKE_HOOK
@ SCULPT_TOOL_CLAY_STRIPS
@ SCULPT_TOOL_CREASE
@ BRUSH_MASK_PRESSURE_RAMP
@ BRUSH_MASK_PRESSURE_CUTOFF
@ GP_BRUSH_ERASER_SOFT
@ GP_BRUSH_ERASER_STROKE
@ GP_BRUSH_ERASER_HARD
@ BRUSH_ELASTIC_DEFORM_GRAB_TRISCALE
@ GPSCULPT_TOOL_GRAB
@ GPSCULPT_TOOL_TWIST
@ GPSCULPT_TOOL_PUSH
@ GPSCULPT_TOOL_STRENGTH
@ GPSCULPT_TOOL_PINCH
@ GPSCULPT_TOOL_SMOOTH
@ GPSCULPT_TOOL_CLONE
@ GPSCULPT_TOOL_THICKNESS
@ GPSCULPT_TOOL_RANDOMIZE
@ BRUSH_OVERLAY_SECONDARY_OVERRIDE_ON_STROKE
@ BRUSH_OVERLAY_PRIMARY_OVERRIDE_ON_STROKE
@ BRUSH_OVERLAY_SECONDARY
@ BRUSH_OVERLAY_CURSOR
@ BRUSH_OVERLAY_CURSOR_OVERRIDE_ON_STROKE
@ BRUSH_OVERLAY_PRIMARY
@ GP_BRUSH_ICON_ERASE_SOFT
@ GP_BRUSH_ICON_GPBRUSH_RANDOMIZE
@ GP_BRUSH_ICON_VERTEX_BLUR
@ GP_BRUSH_ICON_TINT
@ GP_BRUSH_ICON_FILL
@ GP_BRUSH_ICON_PENCIL
@ GP_BRUSH_ICON_GPBRUSH_GRAB
@ GP_BRUSH_ICON_GPBRUSH_STRENGTH
@ GP_BRUSH_ICON_INKNOISE
@ GP_BRUSH_ICON_GPBRUSH_TWIST
@ GP_BRUSH_ICON_PEN
@ GP_BRUSH_ICON_VERTEX_REPLACE
@ GP_BRUSH_ICON_MARKER
@ GP_BRUSH_ICON_VERTEX_DRAW
@ GP_BRUSH_ICON_GPBRUSH_WEIGHT
@ GP_BRUSH_ICON_INK
@ GP_BRUSH_ICON_GPBRUSH_PINCH
@ GP_BRUSH_ICON_VERTEX_SMEAR
@ GP_BRUSH_ICON_GPBRUSH_THICKNESS
@ GP_BRUSH_ICON_AIRBRUSH
@ GP_BRUSH_ICON_GPBRUSH_CLONE
@ GP_BRUSH_ICON_CHISEL
@ GP_BRUSH_ICON_ERASE_STROKE
@ GP_BRUSH_ICON_ERASE_HARD
@ GP_BRUSH_ICON_GPBRUSH_SMOOTH
@ GP_BRUSH_ICON_GPBRUSH_PUSH
@ GP_BRUSH_ICON_VERTEX_AVERAGE
@ GP_BRUSH_PRESET_PENCIL_SOFT
@ GP_BRUSH_PRESET_TWIST_STROKE
@ GP_BRUSH_PRESET_PUSH_STROKE
@ GP_BRUSH_PRESET_MARKER_CHISEL
@ GP_BRUSH_PRESET_ERASER_HARD
@ GP_BRUSH_PRESET_VERTEX_AVERAGE
@ GP_BRUSH_PRESET_INK_PEN
@ GP_BRUSH_PRESET_INK_PEN_ROUGH
@ GP_BRUSH_PRESET_PENCIL
@ GP_BRUSH_PRESET_ERASER_STROKE
@ GP_BRUSH_PRESET_DRAW_WEIGHT
@ GP_BRUSH_PRESET_ERASER_POINT
@ GP_BRUSH_PRESET_VERTEX_BLUR
@ GP_BRUSH_PRESET_MARKER_BOLD
@ GP_BRUSH_PRESET_FILL_AREA
@ GP_BRUSH_PRESET_VERTEX_DRAW
@ GP_BRUSH_PRESET_VERTEX_REPLACE
@ GP_BRUSH_PRESET_SMOOTH_STROKE
@ GP_BRUSH_PRESET_GRAB_STROKE
@ GP_BRUSH_PRESET_AIRBRUSH
@ GP_BRUSH_PRESET_TINT
@ GP_BRUSH_PRESET_CLONE_STROKE
@ GP_BRUSH_PRESET_ERASER_SOFT
@ GP_BRUSH_PRESET_THICKNESS_STROKE
@ GP_BRUSH_PRESET_STRENGTH_STROKE
@ GP_BRUSH_PRESET_RANDOMIZE_STROKE
@ GP_BRUSH_PRESET_VERTEX_SMEAR
@ GP_BRUSH_PRESET_PINCH_STROKE
@ GP_BRUSH_PRESET_PEN
#define MAX_BRUSH_PIXEL_RADIUS
@ BRUSH_MULTIPLANE_SCRAPE_PLANES_PREVIEW
@ BRUSH_MULTIPLANE_SCRAPE_DYNAMIC
@ BRUSH_USE_CONNECTED_ONLY
@ BRUSH_POSE_IK_ANCHORED
@ GPPAINT_MODE_FILL
@ GPPAINT_MODE_BOTH
@ BRUSH_SLIDE_DEFORM_DRAG
struct Brush Brush
@ CUMA_EXTEND_EXTRAPOLATE
eCurveMappingPreset
@ CURVE_PRESET_SMOOTH
@ CURVE_PRESET_SHARP
#define DNA_struct_default_get(struct_name)
Definition: DNA_defaults.h:44
@ GP_MATERIAL_MODE_DOT
eObjectMode
@ OB_MODE_VERTEX_GPENCIL
@ OB_MODE_WEIGHT_GPENCIL
@ OB_MODE_SCULPT_GPENCIL
@ OB_MODE_PAINT_GPENCIL
Object is a sort of wrapper for general info.
@ UNIFIED_PAINT_WEIGHT
@ UNIFIED_PAINT_SIZE
@ UNIFIED_PAINT_BRUSH_LOCK_SIZE
@ UNIFIED_PAINT_ALPHA
@ UNIFIED_PAINT_COLOR
#define MTEX_MAP_MODE_VIEW
#define MTEX_MAP_MODE_3D
#define MTEX_MAP_MODE_STENCIL
#define MTEX_MAP_MODE_TILED
#define MTEX_MAP_MODE_RANDOM
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
void IMB_colormanagement_colorspace_to_scene_linear_v3(float pixel[3], struct ColorSpace *colorspace)
struct ImBuf * IMB_dupImBuf(const struct ImBuf *ibuf1)
void IMB_freeImBuf(struct ImBuf *ibuf)
Definition: allocimbuf.c:211
Contains defines and structs used throughout the imbuf module.
Read Guarded memory(de)allocation.
#define MEM_SAFE_FREE(v)
static void init_data(ModifierData *md)
Group RGB to Bright Vector Camera CLAMP
void BKE_brush_weight_set(const Scene *scene, Brush *brush, float value)
Definition: brush.c:2339
static void brush_defaults(Brush *brush)
Definition: brush.c:435
bool BKE_brush_use_alpha_pressure(const Brush *brush)
Definition: brush.c:2270
void BKE_brush_randomize_texture_coords(UnifiedPaintSettings *ups, bool mask)
Definition: brush.c:2401
float BKE_brush_weight_get(const Scene *scene, const Brush *brush)
Definition: brush.c:2332
void BKE_brush_gpencil_sculpt_presets(Main *bmain, ToolSettings *ts, const bool reset)
Definition: brush.c:1459
float BKE_brush_unprojected_radius_get(const Scene *scene, const Brush *brush)
Definition: brush.c:2306
static void brush_blend_write(BlendWriter *writer, ID *id, const void *id_address)
Definition: brush.c:202
#define BR_TEST(field, t)
int BKE_brush_size_get(const Scene *scene, const Brush *brush)
Definition: brush.c:2249
static void brush_free_data(ID *id)
Definition: brush.c:115
static void brush_blend_read_expand(BlendExpander *expander, ID *id)
Definition: brush.c:347
void BKE_brush_gpencil_weight_presets(Main *bmain, ToolSettings *ts, const bool reset)
Definition: brush.c:1534
void BKE_brush_unprojected_radius_set(Scene *scene, Brush *brush, float unprojected_radius)
Definition: brush.c:2294
void BKE_gpencil_brush_preset_set(Main *bmain, Brush *brush, const short type)
Definition: brush.c:669
float BKE_brush_curve_strength_clamped(Brush *br, float p, const float len)
Definition: brush.c:2464
void BKE_brush_size_set(Scene *scene, Brush *brush, int size)
Definition: brush.c:2234
static void brush_foreach_id(ID *id, LibraryForeachIDData *data)
Definition: brush.c:188
#define FROM_DEFAULT(member)
Brush * BKE_brush_add(Main *bmain, const char *name, const eObjectMode ob_mode)
Definition: brush.c:492
#define BR_TEST_FLAG_OVERLAY(_f)
void BKE_brush_alpha_set(Scene *scene, Brush *brush, float alpha)
Definition: brush.c:2313
void BKE_brush_jitter_pos(const Scene *scene, Brush *brush, const float pos[2], float jitterpos[2])
Definition: brush.c:2377
bool BKE_brush_use_size_pressure(const Brush *brush)
Definition: brush.c:2265
eGPCurveMappingPreset
Definition: brush.c:588
@ GPCURVE_PRESET_CHISEL_SENSIVITY
Definition: brush.c:593
@ GPCURVE_PRESET_INK
Definition: brush.c:590
@ GPCURVE_PRESET_PENCIL
Definition: brush.c:589
@ GPCURVE_PRESET_CHISEL_STRENGTH
Definition: brush.c:594
@ GPCURVE_PRESET_INKNOISE
Definition: brush.c:591
@ GPCURVE_PRESET_MARKER
Definition: brush.c:592
void BKE_brush_system_exit(void)
Definition: brush.c:426
float BKE_brush_curve_strength(const Brush *br, float p, const float len)
Definition: brush.c:2416
Brush * BKE_brush_add_gpencil(Main *bmain, ToolSettings *ts, const char *name, eObjectMode mode)
Definition: brush.c:532
static void brush_init_data(ID *id)
Definition: brush.c:58
static void brush_gpencil_curvemap_reset(CurveMap *cuma, int tot, int preset)
Definition: brush.c:597
static void brush_undo_preserve(BlendLibReader *reader, ID *id_new, ID *id_old)
Definition: brush.c:376
static void brush_make_local(Main *bmain, ID *id, const int flags)
Definition: brush.c:143
#define ACTIVE_SMOOTH
void BKE_brush_gpencil_paint_presets(Main *bmain, ToolSettings *ts, const bool reset)
Definition: brush.c:1308
const float * BKE_brush_secondary_color_get(const struct Scene *scene, const struct Brush *brush)
Definition: brush.c:2216
float BKE_brush_sample_masktex(const Scene *scene, Brush *br, const float point[2], const int thread, struct ImagePool *pool)
Definition: brush.c:2082
#define FROM_DEFAULT_PTR(member)
static RNG * brush_rng
Definition: brush.c:418
void BKE_brush_sculpt_reset(Brush *br)
Definition: brush.c:1677
const float * BKE_brush_color_get(const struct Scene *scene, const struct Brush *brush)
Definition: brush.c:2210
void BKE_brush_curve_preset(Brush *b, eCurveMappingPreset preset)
Definition: brush.c:1938
static void brush_blend_read_data(BlendDataReader *reader, ID *id)
Definition: brush.c:250
bool BKE_brush_sculpt_has_secondary_color(const Brush *brush)
Definition: brush.c:2275
void BKE_brush_system_init(void)
Definition: brush.c:420
void BKE_brush_init_gpencil_settings(Brush *brush)
Definition: brush.c:504
IDTypeInfo IDType_ID_BR
Definition: brush.c:390
void BKE_brush_scale_size(int *r_brush_size, float new_unprojected_radius, float old_unprojected_radius)
Definition: brush.c:2365
float BKE_brush_alpha_get(const Scene *scene, const Brush *brush)
Definition: brush.c:2325
#define SMOOTH_STROKE_RADIUS
void BKE_brush_debug_print_state(Brush *br)
Definition: brush.c:1571
unsigned int * BKE_brush_gen_texture_cache(Brush *br, int half_side, bool use_secondary)
Definition: brush.c:2474
void BKE_brush_gpencil_vertex_presets(Main *bmain, ToolSettings *ts, const bool reset)
Definition: brush.c:1412
static void brush_blend_read_lib(BlendLibReader *reader, ID *id)
Definition: brush.c:321
float BKE_brush_sample_tex_3d(const Scene *scene, const Brush *br, const float point[3], float rgba[4], const int thread, struct ImagePool *pool)
Definition: brush.c:1959
bool BKE_brush_delete(Main *bmain, Brush *brush)
Definition: brush.c:572
bool BKE_brush_use_locked_size(const Scene *scene, const Brush *brush)
Definition: brush.c:2257
#define SMOOTH_STROKE_FACTOR
void BKE_brush_color_set(struct Scene *scene, struct Brush *brush, const float color[3])
Definition: brush.c:2222
void BKE_brush_scale_unprojected_radius(float *unprojected_radius, int new_brush_size, int old_brush_size)
Definition: brush.c:2352
static int brush_undo_preserve_cb(LibraryIDLinkCallbackData *cb_data)
Definition: brush.c:359
static void brush_copy_data(Main *UNUSED(bmain), ID *id_dst, const ID *id_src, const int flag)
Definition: brush.c:72
struct ImBuf * BKE_brush_gen_radial_control_imbuf(Brush *br, bool secondary, bool display_gradient)
Definition: brush.c:2507
static Brush * gpencil_brush_ensure(Main *bmain, ToolSettings *ts, const char *brush_name, eObjectMode mode, bool *r_new)
Definition: brush.c:1284
#define BR_TEST_FLAG(_f)
struct Brush * BKE_brush_first_search(struct Main *bmain, const eObjectMode ob_mode)
Definition: brush.c:1559
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
void reset()
clear internal cached data and reset random seed
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
Definition: btVector3.h:356
Definition: util_half.h:41
Scene scene
static CCL_NAMESPACE_BEGIN const double alpha
uint pos
uint col
#define sinf(x)
#define cosf(x)
#define atan2f(x, y)
#define fabsf(x)
#define sqrtf(x)
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:41
void *(* MEM_dupallocN)(const void *vmemh)
Definition: mallocn.c:42
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:45
static ePaintOverlayControlFlags overlay_flags
Definition: paint.c:237
struct Image * image
struct CurveMapping * curve_sensitivity
struct CurveMapping * curve_strength
struct CurveMapping * curve_jitter
struct CurveMapping * curve_rand_pressure
struct CurveMapping * curve_rand_strength
struct CurveMapping * curve_rand_saturation
struct CurveMapping * curve_rand_hue
struct CurveMapping * curve_rand_uv
struct Material * material
struct CurveMapping * curve_rand_value
float cloth_mass
float multiplane_scrape_angle
float alpha
float topology_rake_factor
float jitter
struct ImBuf * icon_imbuf
struct ColorBand * gradient
int sculpt_plane
struct BrushClone clone
int cloth_deform_type
float area_radius_factor
float density
int slide_deform_type
int elastic_deform_type
float add_col[4]
float normal_radius_factor
struct MTex mtex
int pose_smooth_iterations
float stencil_pos[2]
int texture_overlay_alpha
float normal_weight
float rake_factor
float elastic_deform_volume_preservation
float unprojected_radius
float smooth_stroke_factor
short ob_mode
float cloth_sim_falloff
float stencil_dimension[2]
int smooth_stroke_radius
char gpencil_weight_tool
int curve_preset
struct CurveMapping * curve
char gpencil_vertex_tool
float tip_scale_x
float texture_sample_bias
float plane_trim
int jitter_absolute
float mask_stencil_pos[2]
float rgb[3]
float hardness
struct BrushGpencilSettings * gpencil_settings
float flow
float cloth_sim_limit
struct Brush * toggle_brush
float height
PreviewImage * preview
float sub_col[4]
int pose_ik_segments
char gpencil_sculpt_tool
float crease_pinch_factor
char sculpt_tool
char gpencil_tool
struct MTex mask_mtex
int mask_pressure
float mask_stencil_dimension[2]
float weight
float rate
float plane_offset
float secondary_rgb[3]
int surface_smooth_iterations
float surface_smooth_current_vertex
struct PaintCurve * paint_curve
float tip_roundness
float autosmooth_factor
float cloth_damping
float surface_smooth_shape_preservation
CurveMapPoint * table
short totpoint
CurveMapPoint * curve
CurveMap cm[4]
short id_code
Definition: BKE_idtype.h:120
Definition: DNA_ID.h:273
int tag
Definition: DNA_ID.h:292
struct Library * lib
Definition: DNA_ID.h:277
int us
Definition: DNA_ID.h:293
IDProperty * properties
Definition: DNA_ID.h:314
struct ID * orig_id
Definition: DNA_ID.h:324
void * next
Definition: DNA_ID.h:274
float * rect_float
void * first
Definition: DNA_listBase.h:47
char brush_map_mode
float rot
struct Tex * tex
Definition: BKE_main.h:116
ListBase brushes
Definition: BKE_main.h:171
ListBase materials
Definition: BKE_main.h:152
struct MaterialGPencilStyle * gp_style
struct Brush * brush
Definition: rand.cc:48
struct ToolSettings * toolsettings
GpWeightPaint * gp_weightpaint
GpPaint * gp_paint
GpSculptPaint * gp_sculptpaint
struct UnifiedPaintSettings unified_paint_settings
GpVertexPaint * gp_vertexpaint
struct ColorSpace * colorspace
bool RE_texture_evaluate(const MTex *mtex, const float vec[3], const int thread, struct ImagePool *pool, const bool skip_load_image, const bool texnode_preview, float *r_intensity, float r_rgba[4])
static int blend(const Tex *tex, const float texvec[3], TexResult *texres)
ccl_device_inline float4 mask(const int4 &mask, const float4 &a)
uint len