Sculpt: fix versioning error and add cutoff option

for square and cutoff mapping functions.
This commit is contained in:
Joseph Eagar 2021-10-16 15:52:05 -07:00
parent c65e1076a7
commit 556084f45a
7 changed files with 31 additions and 6 deletions

View File

@ -575,6 +575,9 @@ class UnifiedPaintPanel:
row.prop(mp, "premultiply")
row.prop(mp, "mapfunc")
if mp.mapfunc in ("SQUARE", "CUTOFF"):
col.prop(mp, "func_cutoff")
col.label(text="Output Mapping")
row = col.row()
row.prop(mp, "min")

View File

@ -104,6 +104,7 @@ typedef struct BrushMappingDef {
bool inv;
float min, max;
int blendmode;
float func_cutoff;
float factor; // if 0, will default to 1.0
bool no_default;
} BrushMappingDef;

View File

@ -449,6 +449,7 @@ void BKE_brush_channel_init(BrushChannel *ch, BrushChannelType *def)
mp->blendmode = !mdef->no_default ? MA_RAMP_MULT : mdef->blendmode;
mp->factor = mdef->factor == 0.0f ? 1.0f : mdef->factor;
mp->premultiply = 1.0f;
mp->func_cutoff = mdef->func_cutoff != 0.0f ? mdef->func_cutoff : 0.5f;
if (i == BRUSH_MAPPING_STROKE_T) {
mp->mapfunc = BRUSH_MAPFUNC_COS;
@ -956,10 +957,6 @@ double BKE_brush_channel_eval_mappings(BrushChannel *ch,
switch ((BrushMappingFunc)mp->mapfunc) {
case BRUSH_MAPFUNC_NONE:
break;
case BRUSH_MAPFUNC_SQUARE:
inputf -= floorf(inputf);
inputf = (float)(inputf > 0.5f);
break;
case BRUSH_MAPFUNC_SAW:
inputf -= floorf(inputf);
break;
@ -976,7 +973,11 @@ double BKE_brush_channel_eval_mappings(BrushChannel *ch,
user confusion we just do it here instead of making
them check the inverse checkbox.*/
inputf = 1.0f - inputf;
CLAMP(inputf, 0.0f, 1.0f);
CLAMP(inputf, 0.0f, mp->func_cutoff * 2.0f);
break;
case BRUSH_MAPFUNC_SQUARE:
inputf -= floorf(inputf);
inputf = inputf > mp->func_cutoff ? 1.0f : 0.0f; //(float)(inputf > 0.5f);
break;
default:
break;
@ -1812,11 +1813,15 @@ void BKE_brush_channelset_read(BlendDataReader *reader, BrushChannelSet *chset)
mp->premultiply = 1.0f;
}
if (mp->func_cutoff == 0.0f) {
mp->func_cutoff = 0.5f;
}
if (mp->factor == 0.0f) {
mp->factor = 1.0f;
}
if (mp->min == mp->max == 0.0f) {
if (mp->min == mp->max) {
mp->max = 1.0f;
}

View File

@ -1675,6 +1675,7 @@ void BKE_brush_builtin_create(Brush *brush, int tool)
GETCH(slide_deform_type)->ivalue = BRUSH_SLIDE_DEFORM_DRAG;
break;
case SCULPT_TOOL_PAINT: {
BRUSHSET_SET_BOOL(chset, use_space_attenuation, false);
BRUSHSET_SET_BOOL(chset, dyntopo_disabled, true);
BRUSHSET_SET_FLOAT(chset, hardness, 0.4f);
BRUSHSET_SET_FLOAT(chset, spacing, 10.0f);

View File

@ -1949,6 +1949,8 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
ch->mappings[i].blendmode = MA_RAMP_MULT;
}
ch->mappings[i].func_cutoff = 0.5f;
if (ch->mappings[i].min == ch->mappings[i].max) {
ch->mappings[i].min = 0.0f;
ch->mappings[i].max = 1.0f;
@ -1969,6 +1971,10 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
continue;
}
if (brush->sculpt_tool == SCULPT_TOOL_PAINT) {
BRUSHSET_SET_BOOL(brush->channels, use_space_attenuation, false);
}
LISTBASE_FOREACH (BrushChannel *, ch, &brush->channels->channels) {
for (int i = 0; i < BRUSH_MAPPING_MAX; i++) {
ch->mappings[i].premultiply = 1.0f;
@ -1976,6 +1982,7 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
BrushMapping *mp = ch->mappings + BRUSH_MAPPING_STROKE_T;
mp->func_cutoff = 0.5f;
mp->blendmode = MA_RAMP_MULT;
mp->max = 1.0f;
mp->mapfunc = BRUSH_MAPFUNC_COS;

View File

@ -42,6 +42,8 @@ typedef struct BrushMapping {
float min, max;
float premultiply; // premultiply input data
int mapfunc;
float func_cutoff;
int _pad[1];
} BrushMapping;
typedef struct BrushCurve {

View File

@ -672,6 +672,12 @@ void RNA_def_brush_mapping(BlenderRNA *brna)
RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
RNA_def_property_ui_text(prop, "Pre-Multiply", "Multiply input data by this amount");
prop = RNA_def_property(srna, "func_cutoff", PROP_FLOAT, PROP_FACTOR);
RNA_def_property_float_sdna(prop, "BrushMapping", "func_cutoff");
RNA_def_property_range(prop, 0.0f, 1.0f);
RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
RNA_def_property_ui_text(prop, "Cutoff", "Cutoff for square and cutoff modes");
prop = RNA_def_property(srna, "min", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, "BrushMapping", "min");
RNA_def_property_range(prop, -100000, 100000);