Blender  V3.3
MOD_gpencilcolor.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2017 Blender Foundation. */
3 
8 #include <stdio.h>
9 
10 #include "BLI_utildefines.h"
11 
12 #include "BLI_math_color.h"
13 #include "BLI_math_vector.h"
14 
15 #include "BLT_translation.h"
16 
17 #include "DNA_defaults.h"
19 #include "DNA_gpencil_types.h"
20 #include "DNA_material_types.h"
21 #include "DNA_object_types.h"
22 #include "DNA_screen_types.h"
23 
24 #include "BKE_colortools.h"
25 #include "BKE_context.h"
26 #include "BKE_gpencil_modifier.h"
27 #include "BKE_lib_query.h"
28 #include "BKE_main.h"
29 #include "BKE_material.h"
30 #include "BKE_screen.h"
31 
32 #include "UI_interface.h"
33 #include "UI_resources.h"
34 
35 #include "BKE_modifier.h"
36 
37 #include "DEG_depsgraph.h"
38 
40 #include "MOD_gpencil_ui_common.h"
41 #include "MOD_gpencil_util.h"
42 
43 static void initData(GpencilModifierData *md)
44 {
46 
47  BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(gpmd, modifier));
48 
50 
51  gpmd->curve_intensity = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
53 }
54 
55 static void copyData(const GpencilModifierData *md, GpencilModifierData *target)
56 {
59 
60  if (tgmd->curve_intensity != NULL) {
62  tgmd->curve_intensity = NULL;
63  }
64 
66 
68 }
69 
70 /* color correction strokes */
73  Object *ob,
74  bGPDlayer *gpl,
75  bGPDframe *UNUSED(gpf),
76  bGPDstroke *gps)
77 {
78 
80  float hsv[3], factor[3];
81  const bool use_curve = (mmd->flag & GP_COLOR_CUSTOM_CURVE) != 0 && mmd->curve_intensity;
82 
84  mmd->layername,
85  mmd->material,
86  mmd->pass_index,
87  mmd->layer_pass,
88  1,
89  gpl,
90  gps,
95  return;
96  }
97 
98  copy_v3_v3(factor, mmd->hsv);
100 
101  /* Apply to Vertex Color. */
102  /* Fill */
103  if (mmd->modify_color != GP_MODIFY_COLOR_STROKE) {
104  /* If not using Vertex Color, use the material color. */
105  if ((gp_style != NULL) && (gps->vert_color_fill[3] == 0.0f) &&
106  (gp_style->fill_rgba[3] > 0.0f)) {
107  copy_v4_v4(gps->vert_color_fill, gp_style->fill_rgba);
108  gps->vert_color_fill[3] = 1.0f;
109  }
110 
111  rgb_to_hsv_v(gps->vert_color_fill, hsv);
112  hsv[0] = fractf(hsv[0] + factor[0] + 0.5f);
113  hsv[1] = clamp_f(hsv[1] * factor[1], 0.0f, 1.0f);
114  hsv[2] = hsv[2] * factor[2];
115  hsv_to_rgb_v(hsv, gps->vert_color_fill);
116  }
117 
118  /* Stroke */
119  if (mmd->modify_color != GP_MODIFY_COLOR_FILL) {
120 
121  for (int i = 0; i < gps->totpoints; i++) {
122  bGPDspoint *pt = &gps->points[i];
123  /* If not using Vertex Color, use the material color. */
124  if ((gp_style != NULL) && (pt->vert_color[3] == 0.0f) && (gp_style->stroke_rgba[3] > 0.0f)) {
125  copy_v4_v4(pt->vert_color, gp_style->stroke_rgba);
126  pt->vert_color[3] = 1.0f;
127  }
128 
129  /* Custom curve to modulate value. */
130  float factor_value[3];
131  copy_v3_v3(factor_value, factor);
132  if (use_curve) {
133  float value = (float)i / (gps->totpoints - 1);
134  float mixfac = BKE_curvemapping_evaluateF(mmd->curve_intensity, 0, value);
135  mul_v3_fl(factor_value, mixfac);
136  }
137 
138  rgb_to_hsv_v(pt->vert_color, hsv);
139  hsv[0] = fractf(hsv[0] + factor_value[0] + 0.5f);
140  hsv[1] = clamp_f(hsv[1] * factor_value[1], 0.0f, 1.0f);
141  hsv[2] = hsv[2] * factor_value[2];
142  hsv_to_rgb_v(hsv, pt->vert_color);
143  }
144  }
145 }
146 
147 static void bakeModifier(Main *UNUSED(bmain),
150  Object *ob)
151 {
153 }
154 
156 {
158 
159  if (gpmd->curve_intensity) {
161  }
162 }
163 
164 static void foreachIDLink(GpencilModifierData *md, Object *ob, IDWalkFunc walk, void *userData)
165 {
167 
168  walk(userData, ob, (ID **)&mmd->material, IDWALK_CB_USER);
169 }
170 
171 static void panel_draw(const bContext *UNUSED(C), Panel *panel)
172 {
173  uiLayout *layout = panel->layout;
174 
176 
177  uiLayoutSetPropSep(layout, true);
178 
179  uiItemR(layout, ptr, "modify_color", 0, NULL, ICON_NONE);
180  uiItemR(layout, ptr, "hue", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
181  uiItemR(layout, ptr, "saturation", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
182  uiItemR(layout, ptr, "value", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
183 
185 }
186 
187 static void mask_panel_draw(const bContext *UNUSED(C), Panel *panel)
188 {
189  gpencil_modifier_masking_panel_draw(panel, true, false);
190 }
191 
192 static void panelRegister(ARegionType *region_type)
193 {
195  region_type, eGpencilModifierType_Color, panel_draw);
197  region_type, "mask", "Influence", NULL, mask_panel_draw, panel_type);
199  "curve",
200  "",
203  mask_panel_type);
204 }
205 
207  /* name */ N_("Hue/Saturation"),
208  /* structName */ "ColorGpencilModifierData",
209  /* structSize */ sizeof(ColorGpencilModifierData),
212 
213  /* copyData */ copyData,
214 
215  /* deformStroke */ deformStroke,
216  /* generateStrokes */ NULL,
217  /* bakeModifier */ bakeModifier,
218  /* remapTime */ NULL,
219 
220  /* initData */ initData,
221  /* freeData */ freeData,
222  /* isDisabled */ NULL,
223  /* updateDepsgraph */ NULL,
224  /* dependsOnTime */ NULL,
225  /* foreachIDLink */ foreachIDLink,
226  /* foreachTexLink */ NULL,
227  /* panelRegister */ panelRegister,
228 };
typedef float(TangentPoint)[2]
void BKE_curvemapping_init(struct CurveMapping *cumap)
Definition: colortools.c:1235
struct CurveMapping * BKE_curvemapping_copy(const struct CurveMapping *cumap)
float BKE_curvemapping_evaluateF(const struct CurveMapping *cumap, int cur, float value)
void BKE_curvemapping_free(struct CurveMapping *cumap)
Definition: colortools.c:103
struct CurveMapping * BKE_curvemapping_add(int tot, float minx, float miny, float maxx, float maxy)
Definition: colortools.c:72
void BKE_gpencil_modifier_copydata_generic(const struct GpencilModifierData *md_src, struct GpencilModifierData *md_dst)
@ eGpencilModifierTypeFlag_SupportsEditmode
@ eGpencilModifierTypeType_Gpencil
@ IDWALK_CB_USER
Definition: BKE_lib_query.h:73
General operations, lookup, etc. for materials.
struct MaterialGPencilStyle * BKE_gpencil_material_settings(struct Object *ob, short act)
Definition: material.c:805
void(* IDWalkFunc)(void *userData, struct Object *ob, struct ID **idpoin, int cb_flag)
Definition: BKE_modifier.h:107
#define BLI_assert(a)
Definition: BLI_assert.h:46
MINLINE float clamp_f(float value, float min, float max)
void hsv_to_rgb_v(const float hsv[3], float r_rgb[3])
Definition: math_color.c:49
void rgb_to_hsv_v(const float rgb[3], float r_hsv[3])
Definition: math_color.c:232
MINLINE void copy_v4_v4(float r[4], const float a[4])
MINLINE void mul_v3_fl(float r[3], float f)
MINLINE void copy_v3_v3(float r[3], const float a[3])
#define UNUSED(x)
#define MEMCMP_STRUCT_AFTER_IS_ZERO(struct_var, member)
#define MEMCPY_STRUCT_AFTER(struct_dst, struct_src, member)
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:35
#define DNA_struct_default_get(struct_name)
Definition: DNA_defaults.h:29
@ GP_COLOR_INVERT_LAYERPASS
@ GP_COLOR_INVERT_MATERIAL
struct ColorGpencilModifierData ColorGpencilModifierData
@ GP_MODIFY_COLOR_STROKE
@ eGpencilModifierType_Color
Object is a sort of wrapper for general info.
PointerRNA * gpencil_modifier_panel_get_property_pointers(Panel *panel, PointerRNA *r_ob_ptr)
void gpencil_modifier_masking_panel_draw(Panel *panel, bool use_material, bool use_vertex)
void gpencil_modifier_panel_end(uiLayout *layout, PointerRNA *ptr)
PanelType * gpencil_modifier_subpanel_register(ARegionType *region_type, const char *name, const char *label, PanelDrawFn draw_header, PanelDrawFn draw, PanelType *parent)
PanelType * gpencil_modifier_panel_register(ARegionType *region_type, GpencilModifierType type, PanelDrawFn draw)
void gpencil_modifier_curve_header_draw(const bContext *UNUSED(C), Panel *panel)
void gpencil_modifier_curve_panel_draw(const bContext *UNUSED(C), Panel *panel)
void generic_bake_deform_stroke(Depsgraph *depsgraph, GpencilModifierData *md, Object *ob, const bool retime, gpBakeCb bake_cb)
bool is_stroke_affected_by_modifier(Object *ob, char *mlayername, Material *material, const int mpassindex, const int gpl_passindex, const int minpoints, bGPDlayer *gpl, bGPDstroke *gps, const bool inv1, const bool inv2, const bool inv3, const bool inv4)
static void deformStroke(GpencilModifierData *md, Depsgraph *UNUSED(depsgraph), Object *ob, bGPDlayer *gpl, bGPDframe *UNUSED(gpf), bGPDstroke *gps)
GpencilModifierTypeInfo modifierType_Gpencil_Color
static void freeData(GpencilModifierData *md)
static void mask_panel_draw(const bContext *UNUSED(C), Panel *panel)
static void foreachIDLink(GpencilModifierData *md, Object *ob, IDWalkFunc walk, void *userData)
static void bakeModifier(Main *UNUSED(bmain), Depsgraph *depsgraph, GpencilModifierData *md, Object *ob)
static void copyData(const GpencilModifierData *md, GpencilModifierData *target)
static void panel_draw(const bContext *UNUSED(C), Panel *panel)
static void panelRegister(ARegionType *region_type)
static void initData(GpencilModifierData *md)
#define C
Definition: RandGen.cpp:25
void uiLayoutSetPropSep(uiLayout *layout, bool is_sep)
@ UI_ITEM_R_SLIDER
void uiItemR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, int flag, const char *name, int icon)
const Depsgraph * depsgraph
MINLINE float fractf(float a)
struct CurveMapping * curve_intensity
Definition: DNA_ID.h:368
Definition: BKE_main.h:121
struct uiLayout * layout
float vert_color[4]
bGPDspoint * points
float vert_color_fill[4]
#define N_(msgid)
PointerRNA * ptr
Definition: wm_files.c:3480