Implement basic global tablet pressure curve options.

Grease Pencil already implements support for full-featured
per-brush pressure curves, but it is useful to have some
basic global settings that affect all brushes and tools.

This adds two simple options:

- Raw pressure required to achieve full brush intensity.
- Softness control, using a gamma curve internally.

The most important one is the max pressure setting, because it is
critical for ergonomics, but the Linux Wacom driver lacks it.

The softness option internally converts to gamma = 4^-softness.

Reviewers: brecht, campbellbarton

Differential Revision: https://developer.blender.org/D3967
This commit is contained in:
Alexander Gavrilov 2018-11-20 15:35:59 +03:00
parent b93c81e002
commit 539b465b32
7 changed files with 48 additions and 2 deletions

View File

@ -1121,6 +1121,12 @@ class USERPREF_PT_input(Panel):
sub.prop(walk, "view_height")
sub.prop(walk, "jump_height")
sub.separator()
sub = layout.column()
sub.label(text="Tablet Pressure:")
sub.prop(inputs, "pressure_threshold_max")
sub.prop(inputs, "pressure_softness")
if inputs.use_ndof:
layout.separator()
layout.label(text="NDOF Device:")

View File

@ -8793,6 +8793,11 @@ static void do_versions_userdef(FileData *fd, BlendFileData *bfd)
if (!DNA_struct_elem_find(fd->filesdna, "UserDef", "short", "gpencil_multisamples")) {
user->gpencil_multisamples = 4;
}
/* tablet pressure threshold */
if (!DNA_struct_elem_find(fd->filesdna, "UserDef", "float", "pressure_threshold_max")) {
user->pressure_threshold_max = 1.0f;
}
}
static void do_versions(FileData *fd, Library *lib, Main *main)

View File

@ -618,6 +618,9 @@ typedef struct UserDef {
short anisotropic_filter;
short use_16bit_textures, use_gpu_mipmap;
float pressure_threshold_max; /* raw tablet pressure that maps to 100% */
float pressure_softness; /* curve non-linearity parameter */
float ndof_sensitivity; /* overall sensitivity of 3D mouse */
float ndof_orbit_sensitivity;
float ndof_deadzone; /* deadzone of 3D mouse */

View File

@ -4582,6 +4582,20 @@ static void rna_def_userdef_input(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Tweak Threshold",
"Number of pixels you have to drag before tweak event is triggered");
/* tablet pressure curve */
prop = RNA_def_property(srna, "pressure_threshold_max", PROP_FLOAT, PROP_FACTOR);
RNA_def_property_range(prop, 0.0f, 1.0f);
RNA_def_property_float_default(prop, 1.0f);
RNA_def_property_ui_range(prop, 0.0f, 1.0f, 0.01f, 3);
RNA_def_property_ui_text(prop, "Max Threshold",
"Raw input pressure value that is interpreted as 100% by Blender");
prop = RNA_def_property(srna, "pressure_softness", PROP_FLOAT, PROP_FACTOR);
RNA_def_property_range(prop, -FLT_MAX, FLT_MAX);
RNA_def_property_ui_range(prop, -1.0f, 1.0f, 0.1f, 2);
RNA_def_property_ui_text(prop, "Softness",
"Adjusts softness of the low pressure response onset using a gamma curve");
#ifdef WITH_INPUT_NDOF
/* 3D mouse settings */
/* global options */

View File

@ -3662,6 +3662,22 @@ static void wm_eventemulation(wmEvent *event)
}
}
/* applies the global tablet pressure correction curve */
float wm_pressure_curve(float pressure)
{
if (U.pressure_threshold_max != 0.0f) {
pressure /= U.pressure_threshold_max;
}
CLAMP(pressure, 0.0f, 1.0f);
if (U.pressure_softness != 0.0f) {
pressure = powf(pressure, powf(4.0f, -U.pressure_softness));
}
return pressure;
}
/* adds customdata to event */
static void update_tablet_data(wmWindow *win, wmEvent *event)
{
@ -3672,7 +3688,7 @@ static void update_tablet_data(wmWindow *win, wmEvent *event)
struct wmTabletData *wmtab = MEM_mallocN(sizeof(wmTabletData), "customdata tablet");
wmtab->Active = (int)td->Active;
wmtab->Pressure = td->Pressure;
wmtab->Pressure = wm_pressure_curve(td->Pressure);
wmtab->Xtilt = td->Xtilt;
wmtab->Ytilt = td->Ytilt;

View File

@ -2014,7 +2014,7 @@ float WM_cursor_pressure(const struct wmWindow *win)
const GHOST_TabletData *td = GHOST_GetTabletData(win->ghostwin);
/* if there's tablet data from an active tablet device then add it */
if ((td != NULL) && td->Active != GHOST_kTabletModeNone) {
return td->Pressure;
return wm_pressure_curve(td->Pressure);
}
else {
return -1.0f;

View File

@ -101,6 +101,8 @@ void wm_event_do_depsgraph(bContext *C);
void wm_event_do_refresh_wm_and_depsgraph(bContext *C);
void wm_event_do_notifiers(bContext *C);
float wm_pressure_curve(float raw_pressure);
/* wm_keymap.c */
/* wm_dropbox.c */