forked from bartvdbraak/blender
Cavity masking - add curve control to cavity mask and move relevant
structs to paint struct (might be useful for vertex paint too in the future) Cavity masking now has a curve control. The control will set the amount of masking for positive cavity ("pointness") or negative cavity ("cavity") with x axis being the amount of cavity and 0.0 = full cavity, 1.0 = full pointness, 0.5 = no cavity and the y axis being the amount of alpha.
This commit is contained in:
parent
b7bac19aca
commit
f7e131a6ac
@ -1722,10 +1722,8 @@ class VIEW3D_PT_tools_projectpaint(View3DPaintPanel, Panel):
|
||||
sub.prop(ipaint, "normal_angle", text="")
|
||||
|
||||
layout.prop(ipaint, "use_cavity")
|
||||
sub = layout.column()
|
||||
sub.active = (ipaint.use_cavity)
|
||||
sub.prop(ipaint, "cavity_mul", slider=True)
|
||||
sub.prop(ipaint, "invert_cavity")
|
||||
if ipaint.use_cavity:
|
||||
layout.template_curve_mapping(ipaint, "cavity_curve", brush=True)
|
||||
|
||||
layout.prop(ipaint, "seam_bleed")
|
||||
layout.prop(ipaint, "dither")
|
||||
|
@ -113,6 +113,8 @@ void BKE_paint_init(struct UnifiedPaintSettings *ups, struct Paint *p, const cha
|
||||
void BKE_paint_free(struct Paint *p);
|
||||
void BKE_paint_copy(struct Paint *src, struct Paint *tar);
|
||||
|
||||
void BKE_paint_cavity_curve_preset(struct Paint *p, int preset);
|
||||
|
||||
struct Paint *BKE_paint_get_active(struct Scene *sce);
|
||||
struct Paint *BKE_paint_get_active_from_context(const struct bContext *C);
|
||||
PaintMode BKE_paintmode_get_active_from_context(const struct bContext *C);
|
||||
|
@ -48,6 +48,7 @@
|
||||
#include "BLI_listbase.h"
|
||||
|
||||
#include "BKE_brush.h"
|
||||
#include "BKE_colortools.h"
|
||||
#include "BKE_main.h"
|
||||
#include "BKE_context.h"
|
||||
#include "BKE_crazyspace.h"
|
||||
@ -395,6 +396,21 @@ bool BKE_paint_select_elem_test(Object *ob)
|
||||
BKE_paint_select_face_test(ob));
|
||||
}
|
||||
|
||||
void BKE_paint_cavity_curve_preset(Paint *p, int preset)
|
||||
{
|
||||
CurveMap *cm = NULL;
|
||||
|
||||
if (!p->cavity_curve)
|
||||
p->cavity_curve = curvemapping_add(1, 0, 0, 1, 1);
|
||||
|
||||
cm = p->cavity_curve->cm;
|
||||
cm->flag &= ~CUMA_EXTEND_EXTRAPOLATE;
|
||||
|
||||
p->cavity_curve->preset = preset;
|
||||
curvemap_reset(cm, &p->cavity_curve->clipr, p->cavity_curve->preset, CURVEMAP_SLOPE_POSITIVE);
|
||||
curvemapping_changed(p->cavity_curve, false);
|
||||
}
|
||||
|
||||
void BKE_paint_init(UnifiedPaintSettings *ups, Paint *p, const char col[3])
|
||||
{
|
||||
Brush *brush;
|
||||
@ -410,12 +426,15 @@ void BKE_paint_init(UnifiedPaintSettings *ups, Paint *p, const char col[3])
|
||||
ups->last_stroke_valid = false;
|
||||
zero_v3(ups->average_stroke_accum);
|
||||
ups->average_stroke_counter = 0;
|
||||
if (!p->cavity_curve)
|
||||
BKE_paint_cavity_curve_preset(p, CURVE_PRESET_LINE);
|
||||
}
|
||||
|
||||
void BKE_paint_free(Paint *paint)
|
||||
{
|
||||
id_us_min((ID *)paint->brush);
|
||||
id_us_min((ID *)paint->palette);
|
||||
curvemapping_free(paint->cavity_curve);
|
||||
}
|
||||
|
||||
/* called when copying scene settings, so even if 'src' and 'tar' are the same
|
||||
@ -427,6 +446,7 @@ void BKE_paint_copy(Paint *src, Paint *tar)
|
||||
tar->brush = src->brush;
|
||||
id_us_plus((ID *)tar->brush);
|
||||
id_us_plus((ID *)tar->palette);
|
||||
tar->cavity_curve = curvemapping_copy(src->cavity_curve);
|
||||
}
|
||||
|
||||
void BKE_paint_stroke_get_average(Scene *scene, Object *ob, float stroke[3])
|
||||
|
@ -5428,12 +5428,26 @@ static void link_recurs_seq(FileData *fd, ListBase *lb)
|
||||
}
|
||||
}
|
||||
|
||||
static void direct_link_paint(FileData *fd, Paint **paint)
|
||||
static void direct_link_paint(FileData *fd, Paint *p)
|
||||
{
|
||||
if (p->num_input_samples < 1)
|
||||
p->num_input_samples = 1;
|
||||
|
||||
p->cavity_curve = newdataadr(fd, p->cavity_curve);
|
||||
if (p->cavity_curve)
|
||||
direct_link_curvemapping(fd, p->cavity_curve);
|
||||
else
|
||||
BKE_paint_cavity_curve_preset(p, CURVE_PRESET_SHARP);
|
||||
}
|
||||
|
||||
static void direct_link_paint_helper(FileData *fd, Paint **paint)
|
||||
{
|
||||
/* TODO. is this needed */
|
||||
(*paint) = newdataadr(fd, (*paint));
|
||||
if (*paint && (*paint)->num_input_samples < 1)
|
||||
(*paint)->num_input_samples = 1;
|
||||
|
||||
if (*paint) {
|
||||
direct_link_paint(fd, *paint);
|
||||
}
|
||||
}
|
||||
|
||||
static void direct_link_sequence_modifiers(FileData *fd, ListBase *lb)
|
||||
@ -5499,10 +5513,12 @@ static void direct_link_scene(FileData *fd, Scene *sce)
|
||||
|
||||
sce->toolsettings= newdataadr(fd, sce->toolsettings);
|
||||
if (sce->toolsettings) {
|
||||
direct_link_paint(fd, (Paint**)&sce->toolsettings->sculpt);
|
||||
direct_link_paint(fd, (Paint**)&sce->toolsettings->vpaint);
|
||||
direct_link_paint(fd, (Paint**)&sce->toolsettings->wpaint);
|
||||
direct_link_paint(fd, (Paint**)&sce->toolsettings->uvsculpt);
|
||||
direct_link_paint_helper(fd, (Paint**)&sce->toolsettings->sculpt);
|
||||
direct_link_paint_helper(fd, (Paint**)&sce->toolsettings->vpaint);
|
||||
direct_link_paint_helper(fd, (Paint**)&sce->toolsettings->wpaint);
|
||||
direct_link_paint_helper(fd, (Paint**)&sce->toolsettings->uvsculpt);
|
||||
|
||||
direct_link_paint(fd, &sce->toolsettings->imapaint.paint);
|
||||
|
||||
sce->toolsettings->imapaint.paintcursor = NULL;
|
||||
sce->toolsettings->particle.paintcursor = NULL;
|
||||
|
@ -2316,6 +2316,12 @@ static void write_view_settings(WriteData *wd, ColorManagedViewSettings *view_se
|
||||
}
|
||||
}
|
||||
|
||||
static void write_paint(WriteData *wd, Paint *p)
|
||||
{
|
||||
if (p->cavity_curve)
|
||||
write_curvemapping(wd, p->cavity_curve);
|
||||
}
|
||||
|
||||
static void write_scenes(WriteData *wd, ListBase *scebase)
|
||||
{
|
||||
Scene *sce;
|
||||
@ -2351,18 +2357,22 @@ static void write_scenes(WriteData *wd, ListBase *scebase)
|
||||
writestruct(wd, DATA, "ToolSettings", 1, tos);
|
||||
if (tos->vpaint) {
|
||||
writestruct(wd, DATA, "VPaint", 1, tos->vpaint);
|
||||
write_paint (wd, &tos->vpaint->paint);
|
||||
}
|
||||
if (tos->wpaint) {
|
||||
writestruct(wd, DATA, "VPaint", 1, tos->wpaint);
|
||||
write_paint (wd, &tos->wpaint->paint);
|
||||
}
|
||||
if (tos->sculpt) {
|
||||
writestruct(wd, DATA, "Sculpt", 1, tos->sculpt);
|
||||
write_paint (wd, &tos->sculpt->paint);
|
||||
}
|
||||
if (tos->uvsculpt) {
|
||||
writestruct(wd, DATA, "UvSculpt", 1, tos->uvsculpt);
|
||||
write_paint (wd, &tos->uvsculpt->paint);
|
||||
}
|
||||
|
||||
// write_paint(wd, &tos->imapaint.paint);
|
||||
write_paint(wd, &tos->imapaint.paint);
|
||||
|
||||
ed= sce->ed;
|
||||
if (ed) {
|
||||
@ -3069,7 +3079,7 @@ static void write_brushes(WriteData *wd, ListBase *idbase)
|
||||
|
||||
if (brush->curve)
|
||||
write_curvemapping(wd, brush->curve);
|
||||
if (brush->curve)
|
||||
if (brush->gradient)
|
||||
writestruct(wd, DATA, "ColorBand", 1, brush->gradient);
|
||||
}
|
||||
}
|
||||
|
@ -62,6 +62,7 @@
|
||||
|
||||
#include "BKE_camera.h"
|
||||
#include "BKE_context.h"
|
||||
#include "BKE_colortools.h"
|
||||
#include "BKE_depsgraph.h"
|
||||
#include "BKE_DerivedMesh.h"
|
||||
#include "BKE_idprop.h"
|
||||
@ -257,7 +258,6 @@ typedef struct ProjPaintState {
|
||||
float screenMax[2];
|
||||
float screen_width; /* Calculated from screenMin & screenMax */
|
||||
float screen_height;
|
||||
float cavity_multiplier;
|
||||
int winx, winy; /* from the carea or from the projection render */
|
||||
|
||||
/* options for projection painting */
|
||||
@ -305,6 +305,7 @@ typedef struct ProjPaintState {
|
||||
/* redraw */
|
||||
bool need_redraw;
|
||||
|
||||
struct CurveMapping *cavity_curve;
|
||||
BlurKernel *blurkernel;
|
||||
|
||||
SpinLock *tile_lock;
|
||||
@ -1318,8 +1319,8 @@ static float project_paint_uvpixel_mask(
|
||||
}
|
||||
|
||||
ca_mask = w[0] * ca1 + w[1] * ca2 + w[2] * ca3;
|
||||
ca_mask = curvemapping_evaluateF(ps->cavity_curve, 0, ca_mask);
|
||||
CLAMP(ca_mask, 0.0, 1.0);
|
||||
ca_mask = 1.0f - ca_mask;
|
||||
mask *= ca_mask;
|
||||
}
|
||||
|
||||
@ -3253,7 +3254,8 @@ static void proj_paint_state_cavity_init(ProjPaintState *ps)
|
||||
float no[3];
|
||||
mul_v3_fl(edges[a], 1.0f / counter[a]);
|
||||
normal_short_to_float_v3(no, mv->no);
|
||||
cavities[a] = ps->cavity_multiplier * 10.0f * dot_v3v3(no, edges[a]);
|
||||
/* augment the diffe*/
|
||||
cavities[a] = saacos(10.0f * dot_v3v3(no, edges[a])) * M_1_PI;
|
||||
}
|
||||
else
|
||||
cavities[a] = 0.0;
|
||||
@ -4931,11 +4933,8 @@ static void project_state_init(bContext *C, Object *ob, ProjPaintState *ps, int
|
||||
ps->do_backfacecull = (settings->imapaint.flag & IMAGEPAINT_PROJECT_BACKFACE) ? false : true;
|
||||
ps->do_occlude = (settings->imapaint.flag & IMAGEPAINT_PROJECT_XRAY) ? false : true;
|
||||
ps->do_mask_normal = (settings->imapaint.flag & IMAGEPAINT_PROJECT_FLAT) ? false : true;
|
||||
ps->do_mask_cavity = (settings->imapaint.flag & IMAGEPAINT_PROJECT_CAVITY) ? true : false;
|
||||
ps->cavity_multiplier = settings->imapaint.cavity_mul;
|
||||
if (settings->imapaint.flag & IMAGEPAINT_PROJECT_CAVITY_INV) {
|
||||
ps->cavity_multiplier *= -1;
|
||||
}
|
||||
ps->do_mask_cavity = (settings->imapaint.paint.flags & PAINT_USE_CAVITY_MASK) ? true : false;
|
||||
ps->cavity_curve = settings->imapaint.paint.cavity_curve;
|
||||
}
|
||||
else {
|
||||
ps->do_backfacecull = ps->do_occlude = ps->do_mask_normal = ps->do_mask_cavity = 0;
|
||||
|
@ -651,7 +651,8 @@ PaintStroke *paint_stroke_new(bContext *C,
|
||||
PaintStroke *stroke = MEM_callocN(sizeof(PaintStroke), "PaintStroke");
|
||||
ToolSettings *toolsettings = CTX_data_tool_settings(C);
|
||||
UnifiedPaintSettings *ups = &toolsettings->unified_paint_settings;
|
||||
Brush *br = stroke->brush = BKE_paint_brush(BKE_paint_get_active_from_context(C));
|
||||
Paint *p = BKE_paint_get_active_from_context(C);
|
||||
Brush *br = stroke->brush = BKE_paint_brush(p);
|
||||
float zoomx, zoomy;
|
||||
|
||||
view3d_set_viewcontext(C, &stroke->vc);
|
||||
@ -683,9 +684,10 @@ PaintStroke *paint_stroke_new(bContext *C,
|
||||
zero_v3(ups->average_stroke_accum);
|
||||
ups->average_stroke_counter = 0;
|
||||
|
||||
|
||||
/* initialize here to avoid initialization conflict with threaded strokes */
|
||||
curvemapping_initialize(br->curve);
|
||||
if (p->flags & PAINT_USE_CAVITY_MASK)
|
||||
curvemapping_initialize(p->cavity_curve);
|
||||
|
||||
BKE_paint_set_overlay_override(br->overlay_flags);
|
||||
|
||||
|
@ -47,6 +47,7 @@ extern "C" {
|
||||
#include "DNA_ID.h"
|
||||
#include "DNA_freestyle_types.h"
|
||||
|
||||
struct CurveMapping;
|
||||
struct Object;
|
||||
struct Brush;
|
||||
struct World;
|
||||
@ -813,6 +814,7 @@ typedef struct TimeMarker {
|
||||
typedef struct Paint {
|
||||
struct Brush *brush;
|
||||
struct Palette *palette;
|
||||
struct CurveMapping *cavity_curve; /* cavity curve */
|
||||
|
||||
/* WM Paint cursor */
|
||||
void *paint_cursor;
|
||||
@ -850,8 +852,6 @@ typedef struct ImagePaintSettings {
|
||||
struct Image *canvas; /* canvas when the explicit system is used for painting */
|
||||
float stencil_col[3];
|
||||
float dither; /* dither amount used when painting on byte images */
|
||||
float cavity_mul;
|
||||
float pad;
|
||||
} ImagePaintSettings;
|
||||
|
||||
/* ------------------------------------------- */
|
||||
@ -1695,7 +1695,8 @@ enum {
|
||||
typedef enum {
|
||||
PAINT_SHOW_BRUSH = (1 << 0),
|
||||
PAINT_FAST_NAVIGATE = (1 << 1),
|
||||
PAINT_SHOW_BRUSH_ON_SURFACE = (1 << 2)
|
||||
PAINT_SHOW_BRUSH_ON_SURFACE = (1 << 2),
|
||||
PAINT_USE_CAVITY_MASK = (1 << 3)
|
||||
} PaintFlags;
|
||||
|
||||
/* Paint.symmetry_flags
|
||||
@ -1762,8 +1763,6 @@ typedef enum ImagePaintMode {
|
||||
#define IMAGEPAINT_PROJECT_LAYER_CLONE (1 << 7)
|
||||
#define IMAGEPAINT_PROJECT_LAYER_STENCIL (1 << 8)
|
||||
#define IMAGEPAINT_PROJECT_LAYER_STENCIL_INV (1 << 9)
|
||||
#define IMAGEPAINT_PROJECT_CAVITY (1 << 10)
|
||||
#define IMAGEPAINT_PROJECT_CAVITY_INV (1 << 11)
|
||||
|
||||
|
||||
#define IMAGEPAINT_MISSING_UVS (1 << 0)
|
||||
|
@ -475,6 +475,17 @@ static void rna_def_paint(BlenderRNA *brna)
|
||||
RNA_def_property_ui_text(prop, "Symmetry Feathering",
|
||||
"Reduce the strength of the brush where it overlaps symmetrical daubs");
|
||||
RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL);
|
||||
|
||||
prop = RNA_def_property(srna, "cavity_curve", PROP_POINTER, PROP_NONE);
|
||||
RNA_def_property_flag(prop, PROP_NEVER_NULL);
|
||||
RNA_def_property_ui_text(prop, "Curve", "Editable cavity curve");
|
||||
RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL);
|
||||
|
||||
prop = RNA_def_property(srna, "use_cavity", PROP_BOOLEAN, PROP_NONE);
|
||||
RNA_def_property_boolean_sdna(prop, NULL, "flags", PAINT_USE_CAVITY_MASK);
|
||||
RNA_def_property_ui_text(prop, "Cavity Mask", "Mask painting according to mesh geometry cavity");
|
||||
RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL);
|
||||
|
||||
}
|
||||
|
||||
static void rna_def_sculpt(BlenderRNA *brna)
|
||||
@ -682,16 +693,6 @@ static void rna_def_image_paint(BlenderRNA *brna)
|
||||
RNA_def_property_ui_text(prop, "Stencil Layer", "Set the mask layer from the UV map buttons");
|
||||
RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, "rna_ImaPaint_viewport_update");
|
||||
|
||||
prop = RNA_def_property(srna, "use_cavity", PROP_BOOLEAN, PROP_NONE);
|
||||
RNA_def_property_boolean_sdna(prop, NULL, "flag", IMAGEPAINT_PROJECT_CAVITY);
|
||||
RNA_def_property_ui_text(prop, "Cavity Mask", "Mask painting according to mesh geometry cavity");
|
||||
RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL);
|
||||
|
||||
prop = RNA_def_property(srna, "invert_cavity", PROP_BOOLEAN, PROP_NONE);
|
||||
RNA_def_property_boolean_sdna(prop, NULL, "flag", IMAGEPAINT_PROJECT_CAVITY_INV);
|
||||
RNA_def_property_ui_text(prop, "Invert Cavity", "Painting inside cavity instead of outside");
|
||||
RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL);
|
||||
|
||||
prop = RNA_def_property(srna, "invert_stencil", PROP_BOOLEAN, PROP_NONE);
|
||||
RNA_def_property_boolean_sdna(prop, NULL, "flag", IMAGEPAINT_PROJECT_LAYER_STENCIL_INV);
|
||||
RNA_def_property_ui_text(prop, "Invert", "Invert the stencil layer");
|
||||
@ -725,11 +726,6 @@ static void rna_def_image_paint(BlenderRNA *brna)
|
||||
RNA_def_property_ui_text(prop, "Dither", "Amount of dithering when painting on byte images");
|
||||
RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL);
|
||||
|
||||
prop = RNA_def_property(srna, "cavity_mul", PROP_FLOAT, PROP_NONE);
|
||||
RNA_def_property_range(prop, 0.0, 1.0);
|
||||
RNA_def_property_ui_text(prop, "Cavity Factor", "Factor for cavity effect");
|
||||
RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL);
|
||||
|
||||
prop = RNA_def_property(srna, "use_clone_layer", PROP_BOOLEAN, PROP_NONE);
|
||||
RNA_def_property_boolean_sdna(prop, NULL, "flag", IMAGEPAINT_PROJECT_LAYER_CLONE);
|
||||
RNA_def_property_ui_text(prop, "Clone Map",
|
||||
|
Loading…
Reference in New Issue
Block a user