107 const int mode =
data->filter_type;
115 float orig_color[3], final_color[4], hsv_color[3];
117 float brightness, contrast, gain, delta, offset;
130 float fill_color_rgba[4];
132 fill_color_rgba[3] = 1.0f;
140 hue = hsv_color[0] +
fade;
141 hsv_color[0] =
fabs((hsv_color[0] +
fade) - hue);
146 hsv_color[1] =
clamp_f(hsv_color[1] +
fade, 0.0f, 1.0f);
151 hsv_color[2] =
clamp_f(hsv_color[2] +
fade, 0.0f, 1.0f);
155 orig_color[0] =
clamp_f(orig_color[0] +
fade, 0.0f, 1.0f);
159 orig_color[1] =
clamp_f(orig_color[1] +
fade, 0.0f, 1.0f);
163 orig_color[2] =
clamp_f(orig_color[2] +
fade, 0.0f, 1.0f);
170 delta = contrast / 2.0f;
171 gain = 1.0f - delta * 2.0f;
173 offset = gain * (brightness + delta);
174 for (
int i = 0; i < 3; i++) {
175 final_color[i] =
clamp_f(gain * orig_color[i] + offset, 0.0f, 1.0f);
182 delta = contrast / 2.0f;
183 gain = 1.0f - delta * 2.0f;
185 gain = 1.0f / ((gain != 0.0f) ? gain : FLT_EPSILON);
186 offset = gain * (brightness - delta);
190 offset = gain * (brightness + delta);
192 for (
int i = 0; i < 3; i++) {
193 final_color[i] =
clamp_f(gain * orig_color[i] + offset, 0.0f, 1.0f);
198 float smooth_color[4];
234 const float len =
event->prevclickx -
event->x;
235 filter_strength = filter_strength * -
len * 0.001f;
246 .filter_strength = filter_strength,
247 .filter_fill_color = fill_color,
270 if (use_automasking) {
275 mouse[0] =
event->mval[0];
276 mouse[1] =
event->mval[1];
318 ot->
name =
"Filter Color";
319 ot->
idname =
"SCULPT_OT_color_filter";
320 ot->
description =
"Applies a filter to modify the current sculpt vertex colors";
332 ot->
srna,
"strength", 1.0f, -10.0f, 10.0f,
"Strength",
"Filter strength", -10.0f, 10.0f);
335 ot->
srna,
"fill_color", 3,
NULL, 0.0f, FLT_MAX,
"Fill Color",
"", 0.0f, 1.0f);
struct Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C)
struct Object * CTX_data_active_object(const bContext *C)
struct ToolSettings * CTX_data_tool_settings(const bContext *C)
General operations, lookup, etc. for blender objects.
void BKE_sculpt_update_object_for_edit(struct Depsgraph *depsgraph, struct Object *ob_orig, bool need_pmap, bool need_mask, bool need_colors)
#define SCULPT_FACE_SET_NONE
void BKE_sculpt_color_layer_create_if_needed(struct Object *object)
A BVH for high poly meshes.
#define BKE_pbvh_vertex_iter_begin(pbvh, node, vi, mode)
void BKE_pbvh_node_mark_update_color(PBVHNode *node)
PBVHType BKE_pbvh_type(const PBVH *pbvh)
#define BKE_pbvh_vertex_iter_end
void BKE_pbvh_parallel_range_settings(struct TaskParallelSettings *settings, bool use_threading, int totnode)
MINLINE float clamp_f(float value, float min, float max)
void hsv_to_rgb_v(const float hsv[3], float r_rgb[3])
void rgb_to_hsv_v(const float rgb[3], float r_hsv[3])
MINLINE void blend_color_mix_float(float dst[4], const float src1[4], const float src2[4])
MINLINE void blend_color_interpolate_float(float dst[4], const float src1[4], const float src2[4], float t)
MINLINE void mul_v4_fl(float r[4], float f)
MINLINE void copy_v3_v3(float r[3], const float a[3])
void BLI_task_parallel_range(const int start, const int stop, void *userdata, TaskParallelRangeFunc func, const TaskParallelSettings *settings)
BLI_INLINE void BLI_parallel_range_settings_defaults(TaskParallelSettings *settings)
struct Depsgraph Depsgraph
void IMB_colormanagement_srgb_to_scene_linear_v3(float pixel[3])
Read Guarded memory(de)allocation.
const Depsgraph * depsgraph
void RNA_float_get_array(PointerRNA *ptr, const char *name, float *values)
float RNA_float_get(PointerRNA *ptr, const char *name)
int RNA_enum_get(PointerRNA *ptr, const char *name)
PropertyRNA * RNA_def_float(StructOrFunctionRNA *cont_, const char *identifier, float default_value, float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax)
PropertyRNA * RNA_def_float_color(StructOrFunctionRNA *cont_, const char *identifier, int len, const float *default_value, float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax)
void RNA_def_property_subtype(PropertyRNA *prop, PropertySubType subtype)
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, int default_value, const char *ui_name, const char *ui_description)
void SCULPT_orig_vert_data_update(SculptOrigVertData *orig_data, PBVHVertexIter *iter)
bool SCULPT_cursor_geometry_info_update(bContext *C, SculptCursorGeometryInfo *out, const float mouse[2], bool use_sampled_normal)
void SCULPT_flush_update_done(const bContext *C, Object *ob, SculptUpdateType update_flags)
void SCULPT_flush_update_step(bContext *C, SculptUpdateType update_flags)
bool SCULPT_vertex_colors_poll(bContext *C)
void SCULPT_orig_vert_data_init(SculptOrigVertData *data, Object *ob, PBVHNode *node)
float SCULPT_automasking_factor_get(AutomaskingCache *automasking, SculptSession *ss, int vert)
AutomaskingCache * SCULPT_automasking_cache_init(Sculpt *sd, Brush *brush, Object *ob)
bool SCULPT_is_automasking_enabled(const Sculpt *sd, const SculptSession *ss, const Brush *br)
static int sculpt_color_filter_modal(bContext *C, wmOperator *op, const wmEvent *event)
static void color_filter_task_cb(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict UNUSED(tls))
@ COLOR_FILTER_BRIGHTNESS
@ COLOR_FILTER_SATURATION
void SCULPT_OT_color_filter(struct wmOperatorType *ot)
static int sculpt_color_filter_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static EnumPropertyItem prop_color_filter_types[]
void SCULPT_filter_cache_init(bContext *C, Object *ob, Sculpt *sd, const int undo_type)
void SCULPT_filter_cache_free(SculptSession *ss)
void SCULPT_undo_push_begin(struct Object *ob, const char *name)
void SCULPT_undo_push_end(void)
void SCULPT_neighbor_color_average(SculptSession *ss, float result[4], int index)
AutomaskingCache * automasking
struct SculptSession * sculpt
struct MeshElemMap * pmap
struct FilterCache * filter_cache
int(* invoke)(struct bContext *, struct wmOperator *, const struct wmEvent *) ATTR_WARN_UNUSED_RESULT
int(* modal)(struct bContext *, struct wmOperator *, const struct wmEvent *) ATTR_WARN_UNUSED_RESULT
bool(* poll)(struct bContext *) ATTR_WARN_UNUSED_RESULT
CCL_NAMESPACE_BEGIN ccl_device float fade(float t)
ccl_device_inline float2 fabs(const float2 &a)
wmEventHandler_Op * WM_event_add_modal_handler(bContext *C, wmOperator *op)