Skip to content

Free, open-source 3D sculpting for Linux, macOS and Windows: dense meshes, remeshing, painting, built-in AI (image/text to 3D), Send to Unreal, game-ready LODs, Gaussian splats and OpenUSD.

Pen pressure per brush: Size and Strength switches, Use global / On / Off (#122)

islandmede766794e8c98
diff --git a/changes/feat-pressure-per-brush.md b/changes/feat-pressure-per-brush.md
new file mode 100644
index 00000000..bdaeb0aa
--- /dev/null
+++ b/changes/feat-pressure-per-brush.md
@@ -0,0 +1,17 @@
+---
+whats_new: **Pen pressure per brush**: **Brush > Pen pressure** sets Size and Strength to **Use global**, **On** or
+ **Off** for the brush you hold (also in Brush Lab and **Edit > Preferences > Tablet**). Grab brushes start with
+ Size off.
+added: **Pen pressure per brush** (#122, requested by Zoldyck-Kill): every brush has its own **Pen pressure: Size**
+ and **Strength** switches, **Use global** / **On** / **Off**, in **Brush > Pen pressure**, Brush Lab and
+ **Edit > Preferences > Tablet**. **Use global** follows Pressure > Size / Strength as before; **On** and **Off**
+ override them for that brush. Kept per brush with its other settings (**Save Brush Settings** keeps them, **Reset
+ Brush to Default** puts back the default) and in a custom brush's `.sfbrush`. Move, KelvinGrab, KelvinTwist,
+ KelvinScale, Tendril and Elastic Tendril start with Size off; older saved settings load as Use global. Command:
+ `brush_pen_pressure size=on|off|global strength=on|off|global`.
+testers:
+ - Windows + pen tablet: turn on Pressure > Size on the shelf. Clay: a light stroke is thin. Brush > Pen pressure >
+ Size > Off: the same light stroke is full width. Pick Clay again: still thin (Use global).
+ - Pick Move: Brush > Pen pressure shows Size: Off; a light press grabs with the whole brush circle.
+ - Set Standard's Strength to Off, Save Brush Settings, restart: Standard still draws at full strength with any pressure.
+---
diff --git a/docs/guide/brush-lab.md b/docs/guide/brush-lab.md
index b784e72b..4ab7e076 100644
--- a/docs/guide/brush-lab.md
+++ b/docs/guide/brush-lab.md
@@ -70,6 +70,12 @@ description.
The name field at the top of the editor renames the brush when you press <kbd>Enter</kbd>.
+Under the recipe sliders are the brush's pressure curve and **Pen pressure: Size** and **Strength**, each
+**Use global**, **On** or **Off**. **Use global** (the default) follows **Pressure > Size** and **Pressure >
+Strength** on the top shelf and in **Edit > Preferences > Tablet**; **On** and **Off** override them for this brush
+only. The choice is saved in the brush's `.sfbrush` file, so a shared brush keeps it (see
+[Pen pressure and tablets](sculpting.md#pen-pressure-and-tablets)).
+
> **Tip:** to adapt a built-in recipe such as Dragon Scales, select it and move the sliders. Your version is
> saved to your library and replaces the built-in one; delete it to get the original back.
diff --git a/docs/guide/sculpting.md b/docs/guide/sculpting.md
index f017dea3..c67b27b3 100644
--- a/docs/guide/sculpting.md
+++ b/docs/guide/sculpting.md
@@ -681,6 +681,16 @@ Two toggles decide what pressure does. They are on the top shelf and in **Sculpt
| **Pressure > Strength** | On | Pen pressure scales the brush strength. |
| **Pressure > Size** | Off | Pen pressure scales the brush size (down to 5% at the lightest touch). Move, KelvinGrab, KelvinTwist and KelvinScale always grab with the full size. |
+**Each brush can override them.** **Sculpt > Brush > Pen pressure** (and the same switches in [Brush
+Lab](brush-lab.md) and **Edit > Preferences > Tablet**) sets **Size** and **Strength** for the brush you are holding
+to **Use global**, **On** or **Off**. **Use global** follows the toggles above; **On** and **Off** apply to that
+brush whatever the toggles say, so you can keep Pressure > Size on for Clay and off for Standard. Grab brushes
+(Move, KelvinGrab, KelvinTwist, KelvinScale, Tendril and Elastic Tendril) start with **Size: Off**, every other
+brush with **Use global**. The switches are kept per brush like its size and alpha: **Sculpt > Brush > Save Brush
+Settings** keeps them for the next start, **Reset Brush to Default** puts back the brush's default, and a custom
+brush also keeps them in its `.sfbrush` file. Brush settings saved before 0.11.1 load as **Use global** (grab
+brushes: **Size: Off**).
+
Pressure applies only to strokes made with the pen; mouse strokes always use full pressure. Custom brushes
also have a **Pressure curve** setting that makes them respond to a light or a firm touch (see
[Brush Lab](brush-lab.md)). If the pen moves the cursor but pressure does nothing, see
diff --git a/src/app/App.cpp b/src/app/App.cpp
index e7ac1ee2..bdb2a10b 100644
--- a/src/app/App.cpp
+++ b/src/app/App.cpp
@@ -2960,6 +2960,7 @@ void App::drawRecipeEditor(BrushRecipe& recipe) {
}
ImGui::PopItemWidth();
drawPressureCurveEditor("lab_brush_curve", ImGui::GetContentRegionAvail().x); // this brush's own (Precision.cpp)
+ drawPenPressureSwitches("lab_pen"); // (#122, BrushSettingsUi.cpp)
const float half = (ImGui::GetContentRegionAvail().x - ImGui::GetStyle().ItemSpacing.x) * 0.5f;
if (ImGui::Button("Save .sfbrush...", ImVec2(half, 0))) saveFileDialog(FileAction::SaveBrush);
ImGui::SameLine();
@@ -3871,7 +3872,7 @@ void App::drawBrushCursor() {
ImDrawList* dl;
~PopClip() { dl->PopClipRect(); }
} popClip{dl};
- const float r = radiusPx_ * (pressureSize_ && lastInputPen_ ? std::max(strokePressure(), 0.05f) : 1.0f);
+ const float r = radiusPx_ * (pressureSizeOn() && lastInputPen_ ? std::max(strokePressure(), 0.05f) : 1.0f);
const glm::vec2 at = predictedPointer(); // during a predictive stroke, where the pen will be as this frame shows
const ImVec2 c(at.x, at.y);
const SDL_Keymod mod = inputMods();
diff --git a/src/app/App.h b/src/app/App.h
index e9459413..d8d3c3f4 100644
--- a/src/app/App.h
+++ b/src/app/App.h
@@ -269,8 +269,15 @@ private:
int symmetryCopiesDrawn_ = 0; // the cursor and its symmetry dots the last drawSurfaceCursor drew (UI tests: cursor_copies)
bool invertToggle_ = false;
bool frontFacesOnly_ = false;
- bool pressureStrength_ = true;
+ bool pressureStrength_ = true; // the global switches (Preferences > Tablet, the shelf)
bool pressureSize_ = false;
+ // The current brush's own (#122, kept per brush: core/BrushSettings.h): Use global, On or Off.
+ PenPressure penSize_ = PenPressure::Global;
+ PenPressure penStrength_ = PenPressure::Global;
+ bool pressureSizeOn() const { return penPressureOn(penSize_, pressureSize_); }
+ bool pressureStrengthOn() const { return penPressureOn(penStrength_, pressureStrength_); }
+ void setPenPressure(bool size, PenPressure p); // this brush's (and a custom brush's recipe)
+ void drawPenPressureSwitches(const char* id); // Pen pressure: Size / Strength [Use global | On | Off]
// Input / stroke state
Drag drag_ = Drag::None;
@@ -1805,6 +1812,9 @@ private:
void initBrushSettings();
void syncBrushSettings(); // every frame, outside strokes
void recipeAlpha(BrushToolSettings& s) const; // the active recipe's own alpha (brush packs) into `s`
+ void recipePenPressure(BrushToolSettings& s) const; // the active recipe's own pen pressure (#122) into `s`
+ void shippedPenPressure(); // the current brush's own pen pressure, as shipped (or its recipe's)
+ void registerPenPressureCommand(); // brush_pen_pressure (#122)
void syncAlphaTile(); // the brush's Tile onto the current alpha
void registerAlphaOptionsCommand(); // brush_alpha_options (#76)
std::string brushSettingsPath() const;
diff --git a/src/app/AsyncStroke.cpp b/src/app/AsyncStroke.cpp
index 5aa75583..334bf4be 100644
--- a/src/app/AsyncStroke.cpp
+++ b/src/app/AsyncStroke.cpp
@@ -413,8 +413,8 @@ App::DabSettings App::dabSettings() const {
st.maskStrength = maskStrength_;
st.sprayScatter = sprayScatter_;
st.alphaOptions = alphaOptions_;
- st.pressureSize = pressureSize_;
- st.pressureStrength = pressureStrength_;
+ st.pressureSize = pressureSizeOn();
+ st.pressureStrength = pressureStrengthOn();
st.invert = strokeInvert_;
st.frontFacesOnly = frontFacesOnly_;
st.connectedOnly = uiPrefs_.connectedOnly;
@@ -553,10 +553,10 @@ void App::buildGhost() {
GhostDab d;
if (!ghostSurface(origin, dir, d.center, n)) continue;
d.radius = (worldSize_ && worldRadius_ > 0.0f ? worldRadius_ : radiusPx_ * camera_.worldPerPixel(d.center, c.h)) *
- (pressureSize_ ? std::max(sd.pressure, 0.05f) : 1.0f);
+ (pressureSizeOn() ? std::max(sd.pressure, 0.05f) : 1.0f);
d.normal = n;
d.strength = std::clamp((strokeBrush_ == BrushType::Smooth ? smoothStrength_ : strength_), 0.0f, 1.0f) *
- std::clamp(pressureStrength_ ? sd.pressure : 1.0f, 0.0f, 1.0f);
+ std::clamp(pressureStrengthOn() ? sd.pressure : 1.0f, 0.0f, 1.0f);
d.areaCenter = d.center - n * depth;
d.weight = sd.weight;
base.push_back(d);
diff --git a/src/app/BrushSettingsUi.cpp b/src/app/BrushSettingsUi.cpp
index ec6f3e1a..54bd64e0 100644
--- a/src/app/BrushSettingsUi.cpp
+++ b/src/app/BrushSettingsUi.cpp
@@ -5,6 +5,7 @@
// strokes, so every way of picking a brush (shelf, pickers, keys, the Library, scripts, Ctrl-held brushes) behaves
// the same without each of them knowing about it.
#include "app/App.h"
+#include "app/Ui.h"
#include "core/BrushLibrary.h"
#include "core/Image.h"
@@ -49,6 +50,8 @@ BrushToolSettings App::liveBrushSettings() const {
s.alphaPath = a.empty() ? std::string() : a.path;
s.alphaInvert = !s.alphaPath.empty() && a.inverted;
s.alphaOptions = alphaOptions_;
+ s.pressureSize = penSize_;
+ s.pressureStrength = penStrength_;
return s;
}
@@ -63,6 +66,8 @@ void App::applyBrushSettings(const BrushToolSettings& in) {
sprayScatter_ = s.sprayScatter;
lazyMouse_.radius = s.lazyRadius;
alphaOptions_ = s.alphaOptions;
+ penSize_ = s.pressureSize;
+ penStrength_ = s.pressureStrength;
// The alpha, loaded only when it differs; one that can't be loaded any more (a moved image) leaves the current.
const BrushToolSettings live = liveBrushSettings();
if (lower(live.alphaName) == lower(s.alphaName) && live.alphaPath == s.alphaPath && live.alphaInvert == s.alphaInvert)
@@ -87,6 +92,8 @@ void App::initBrushSettings() {
options_.renderPath.empty() && options_.measureIdle <= 0.0f && options_.measureStroke <= 0.0f;
brushSettingsKey_ = currentBrushKey();
registerAlphaOptionsCommand();
+ registerPenPressureCommand();
+ shippedPenPressure();
if (!brushSettingsOn_) return;
std::string err;
if (const std::string path = brushSettingsPath(); !path.empty() && !brushSettings_.load(path, err))
@@ -97,12 +104,17 @@ void App::initBrushSettings() {
void App::syncBrushSettings() {
if (drag_ != Drag::None || doc_.sculptor.strokeActive()) return;
syncAlphaTile();
- if (!brushSettingsOn_) return;
const std::string key = currentBrushKey();
if (key == brushSettingsKey_) return;
+ if (!brushSettingsOn_) { // (demo videos, benchmarks: their scripts set every value, but a grab brush's pen is its own)
+ brushSettingsKey_ = key;
+ shippedPenPressure();
+ return;
+ }
const bool firstUse = !brushSettings_.known(key);
BrushToolSettings next = brushSettings_.switchBrush(brushSettingsKey_, key, liveBrushSettings());
if (firstUse) recipeAlpha(next); // a brush-pack brush starts with its own alpha (or none), not the last brush's
+ if (firstUse) recipePenPressure(next);
applyBrushSettings(next);
brushSettingsKey_ = key;
syncAlphaTile();
@@ -119,6 +131,70 @@ void App::recipeAlpha(BrushToolSettings& s) const {
s.alphaOptions.tileX = s.alphaOptions.tileY = 1;
}
+void App::recipePenPressure(BrushToolSettings& s) const {
+ if (doc_.activeBrush < 0 || doc_.activeBrush >= int(doc_.brushes.size())) return;
+ const BrushRecipe& r = doc_.brushes[size_t(doc_.activeBrush)];
+ s.pressureSize = r.pressureSize;
+ s.pressureStrength = r.pressureStrength;
+}
+
+void App::shippedPenPressure() {
+ BrushToolSettings s = BrushSettingsStore::shipped(brushSettingsKey_);
+ recipePenPressure(s);
+ penSize_ = s.pressureSize;
+ penStrength_ = s.pressureStrength;
+}
+
+void App::setPenPressure(bool size, PenPressure p) {
+ (size ? penSize_ : penStrength_) = p;
+ if (BrushRecipe* r = doc_.activeBrush >= 0 && doc_.activeBrush < int(doc_.brushes.size())
+ ? &doc_.brushes[size_t(doc_.activeBrush)]
+ : nullptr;
+ r && (size ? r->pressureSize : r->pressureStrength) != p) {
+ (size ? r->pressureSize : r->pressureStrength) = p; // a custom brush keeps it in its .sfbrush too
+ saveBrushEdits(doc_.activeBrush);
+ }
+ const char* state = p == PenPressure::On ? "on" : p == PenPressure::Off ? "off" : "as Preferences > Tablet";
+ status_ = std::string("Pen pressure > ") + (size ? "Size" : "Strength") + " for " +
+ (activeRecipe() ? activeRecipe()->name : std::string(brushName(brush_))) + ": " + state;
+}
+
+void App::drawPenPressureSwitches(const char* id) {
+ ImGui::PushID(id);
+ ImGui::TextDisabled("Pen pressure: %s", activeRecipe() ? activeRecipe()->name.c_str() : brushLabel(brush_));
+ const float labelW = ImGui::CalcTextSize("Strength").x + ImGui::GetFontSize(); // (a clear gap before the segments)
+ for (const bool size : {true, false}) {
+ ImGui::AlignTextToFramePadding();
+ ImGui::TextUnformatted(size ? "Size" : "Strength");
+ ImGui::SameLine(labelW);
+ if (size) ui::Segmented(*this, {"brush.pen_size_global", "brush.pen_size_on", "brush.pen_size_off"});
+ else ui::Segmented(*this, {"brush.pen_strength_global", "brush.pen_strength_on", "brush.pen_strength_off"});
+ }
+ ImGui::PopID();
+}
+
+void App::registerPenPressureCommand() {
+ commands_.add({"brush_pen_pressure",
+ "The current brush's own pen pressure switches (kept per brush; Save Brush Settings keeps them): "
+ "'global' follows Preferences > Tablet's Pressure > Size / Strength, 'on' and 'off' override it "
+ "for this brush. Omitted switches stay as they are.",
+ {{"size", ParamSpec::Type::String, "Pressure > Size: global, on or off.", false},
+ {"strength", ParamSpec::Type::String, "Pressure > Strength: global, on or off.", false}},
+ [this](Document&, const Args& a) -> CommandResult {
+ for (const char* key : {"size", "strength"}) {
+ const auto it = a.find(key);
+ if (it == a.end()) continue;
+ const std::string v = argString(a, key, "");
+ if (v != "global" && v != "on" && v != "off")
+ return {false, std::string(key) + " must be global, on or off"};
+ setPenPressure(std::string(key) == "size", penPressureFromId(v));
+ }
+ return {true, std::string("Pen pressure: size ") + penPressureId(penSize_) + " (" +
+ (pressureSizeOn() ? "on" : "off") + "), strength " +
+ penPressureId(penStrength_) + " (" + (pressureStrengthOn() ? "on" : "off") + ")"};
+ }});
+}
+
void App::syncAlphaTile() { // Tile lives on the alpha (a new alpha starts at 1 x 1): the brush's option wins
alphaOptions_.clamp();
doc_.brushAlpha.tileX = alphaOptions_.tileX;
@@ -165,6 +241,7 @@ void App::resetBrushSettings() {
const bool wasSaved = brushSettings_.hasSaved(brushSettingsKey_);
BrushToolSettings shipped = brushSettings_.reset(brushSettingsKey_);
recipeAlpha(shipped); // (a pack brush's own alpha is part of its defaults)
+ recipePenPressure(shipped);
applyBrushSettings(shipped);
std::string err;
if (wasSaved && brushSettingsOn_ && !brushSettingsPath().empty() && !brushSettings_.save(brushSettingsPath(), err))
diff --git a/src/app/Config.cpp b/src/app/Config.cpp
index c827a7e4..dfcff921 100644
--- a/src/app/Config.cpp
+++ b/src/app/Config.cpp
@@ -561,6 +561,24 @@ void App::initActions() {
ICON_LC_ROTATE_CCW, nullptr, nullptr, nullptr,
"Put the current brush's Draw Size, Z Intensity, Falloff, RGB Intensity, stroke and alpha back to the values "
"SculptForge ships with, and forget what Save Brush Settings stored for it.");
+ // Pen pressure per brush (#122, BrushSettingsUi.cpp): segments of Brush, Brush Lab and Preferences > Tablet.
+ for (const bool size : {true, false})
+ for (const PenPressure p : {PenPressure::Global, PenPressure::On, PenPressure::Off}) {
+ const std::string id = std::string("brush.pen_") + (size ? "size_" : "strength_") + penPressureId(p);
+ const std::string switchName = std::string("Pressure > ") + (size ? "Size" : "Strength");
+ const std::string description =
+ p == PenPressure::Global
+ ? "This brush follows " + switchName + " (Preferences > Tablet, the shelf). Grab brushes (Move, KelvinGrab, "
+ "KelvinTwist, KelvinScale, the tendrils) start with Size off instead, since a pen's press is "
+ "nearly weightless."
+ : std::string("Pen pressure ") + (p == PenPressure::On ? "always scales" : "never scales") +
+ " this brush's " + (size ? "size" : "strength") + ", whatever " + switchName +
+ " says. Kept per brush; Save Brush Settings keeps it for next time.";
+ add(id.c_str(), p == PenPressure::Global ? "Use global" : p == PenPressure::On ? "On" : "Off",
+ size ? "Brush > Pen pressure > Size" : "Brush > Pen pressure > Strength", nullptr,
+ [this, size, p] { setPenPressure(size, p); }, nullptr, nullptr,
+ [this, size, p] { return (size ? penSize_ : penStrength_) == p; }, nullptr, description.c_str());
+ }
add("brush.share_size", "Share size and intensity across brushes", "Preferences > Input", nullptr,
[this] { setShareBrushSize(!brushSettings_.shareSizeIntensity); }, nullptr, nullptr,
[this] { return brushSettings_.shareSizeIntensity; }, nullptr,
diff --git a/src/app/Palettes.cpp b/src/app/Palettes.cpp
index 6959d021..4cc673cf 100644
--- a/src/app/Palettes.cpp
+++ b/src/app/Palettes.cpp
@@ -315,6 +315,7 @@ void App::drawPalette_Brush() {
actionRow(*this, {"brush.save_settings"}); // this brush's own settings (#78); one per row so the labels fit
actionRow(*this, {"brush.reset_settings"});
drawCustomBrushes();
+ drawPenPressureSwitches("brush_pen"); // this brush's own (#122)
ImGui::Checkbox(tr("Front faces only"), &frontFacesOnly_);
ui::HelpAction(*this, "draw.front_faces");
ImGui::SameLine();
diff --git a/src/app/PanelBrushes.cpp b/src/app/PanelBrushes.cpp
index 753468b6..82bec41a 100644
--- a/src/app/PanelBrushes.cpp
+++ b/src/app/PanelBrushes.cpp
@@ -118,9 +118,9 @@ void App::snakeHookTo(float x, float y) {
const float pressure = strokePressure();
DabParams p;
p.viewDir = n;
- p.radius = radiusPx_ * (pressureSize_ ? std::max(pressure, 0.05f) : 1.0f) * camera_.worldPerPixel(grabLast_, h);
+ p.radius = radiusPx_ * (pressureSizeOn() ? std::max(pressure, 0.05f) : 1.0f) * camera_.worldPerPixel(grabLast_, h);
p.strength = strength_;
- p.pressure = pressureStrength_ ? pressure : 1.0f;
+ p.pressure = pressureStrengthOn() ? pressure : 1.0f;
p.invert = strokeInvert_;
p.focal = focalShift_;
p.connectedOnly = uiPrefs_.connectedOnly;
@@ -153,7 +153,7 @@ void App::dragRectTo(float x, float y) {
p.viewDir = camera_.forward();
p.radius = len * camera_.worldPerPixel(dragAnchorHit_, canvasHeight());
p.strength = strength_;
- p.pressure = pressureStrength_ ? pressure : 1.0f;
+ p.pressure = pressureStrengthOn() ? pressure : 1.0f;
p.invert = strokeInvert_;
p.frontFacesOnly = frontFacesOnly_;
p.connectedOnly = uiPrefs_.connectedOnly;
diff --git a/src/app/PanelKelvinlet.cpp b/src/app/PanelKelvinlet.cpp
index 3a0885f7..ac086d85 100644
--- a/src/app/PanelKelvinlet.cpp
+++ b/src/app/PanelKelvinlet.cpp
@@ -63,7 +63,7 @@ void App::kelvinBegin(const RayHit& hit) {
void App::kelvinTo(float x, float y) {
if (strokeProbe_) strokeProbe_->emplace_back(x, y); // --measure-stroke counts each drag step as a dab
- const float pressure = pressureStrength_ ? strokePressure() : 1.0f;
+ const float pressure = pressureStrengthOn() ? strokePressure() : 1.0f;
kelvinAmount_ = std::min(1.0f, 2.0f * strength_) * pressure;
if (strokeBrush_ == BrushType::KelvinGrab) {
// The grabbed point follows the cursor in the plane through it facing the camera (as Move), or along the
diff --git a/src/app/PanelVdm.cpp b/src/app/PanelVdm.cpp
index d461bd48..98ad3dd3 100644
--- a/src/app/PanelVdm.cpp
+++ b/src/app/PanelVdm.cpp
@@ -136,10 +136,10 @@ void App::dragDotTo(float x, float y) {
DabParams p;
p.center = hit.position;
p.viewDir = camera_.forward();
- p.radius = radiusPx_ * (pressureSize_ ? std::max(pressure, 0.05f) : 1.0f) *
+ p.radius = radiusPx_ * (pressureSizeOn() ? std::max(pressure, 0.05f) : 1.0f) *
camera_.worldPerPixel(hit.position, canvasHeight());
p.strength = strokeBrush_ == BrushType::Smooth ? smoothStrength_ : strength_;
- p.pressure = pressureStrength_ ? pressure : 1.0f;
+ p.pressure = pressureStrengthOn() ? pressure : 1.0f;
p.invert = strokeInvert_;
p.frontFacesOnly = frontFacesOnly_;
p.connectedOnly = uiPrefs_.connectedOnly;
diff --git a/src/app/Tablet.cpp b/src/app/Tablet.cpp
index a7aa9d27..4dac591a 100644
--- a/src/app/Tablet.cpp
+++ b/src/app/Tablet.cpp
@@ -643,6 +643,7 @@ void App::drawTabletSection() {
ui::ActionButton(*this, "draw.pressure_strength", ImVec2(tw, 0));
ImGui::SameLine();
ui::ActionButton(*this, "draw.pressure_size", ImVec2(tw, 0));
+ drawPenPressureSwitches("prefs_pen"); // the current brush's own, over the two above (#122)
// --- Eraser and side buttons ---
ImGui::Spacing();
diff --git a/src/app/Ui.cpp b/src/app/Ui.cpp
index 92f151ed..3ef3314e 100644
--- a/src/app/Ui.cpp
+++ b/src/app/Ui.cpp
@@ -147,6 +147,7 @@ bool IsModeAction(std::string_view id) {
auto starts = [&](std::string_view p) { return id.substr(0, p.size()) == p; };
if (id == "tool.draw" || id == "tool.move" || id == "tool.scale" || id == "tool.rotate") return true;
if (id == "draw.sculpt" || id == "draw.paint") return true;
+ if (starts("brush.pen_")) return false; // a brush's pen pressure switches (#122): choices, not brush picks
return starts("brush.") || starts("mask.") || starts("select.");
}
@@ -154,7 +155,7 @@ bool IsChoiceAction(std::string_view id) {
return id == "draw.raise" || id == "draw.lower" || id == "material.smooth" || id == "material.flat" ||
id == "view.background_gradient" || id == "view.background_flat" || id == "view.shading_lit_sphere" ||
id == "view.shading_pbr" ||
- id.rfind("part.shading_", 0) == 0 || id.substr(0, 8) == "uv.mode_";
+ id.rfind("part.shading_", 0) == 0 || id.rfind("brush.pen_", 0) == 0 || id.substr(0, 8) == "uv.mode_";
}
void CentredGlyph(ImDrawList* dl, ImFont* font, ImVec2 a, ImVec2 b, ImU32 col, const char* glyph) {
diff --git a/src/app/UiTest.cpp b/src/app/UiTest.cpp
index 26f7058f..9febcd45 100644
--- a/src/app/UiTest.cpp
+++ b/src/app/UiTest.cpp
@@ -514,6 +514,11 @@ double Demo::query(const std::string& name, bool& known) const {
if (name == "focal_shift") return std::round(app_.focalShift_ * 100.0f);
if (name == "draw_size") return std::round(app_.radiusPx_);
if (name == "brush_settings_saved") return double(app_.brushSettingsStore().savedCount()); // (#78)
+ // #122: the current brush's pen pressure switches (0 Use global, 1 On, 2 Off) and what they come to (0 / 1).
+ if (name == "pen_size_mode") return double(int(app_.penSize_));
+ if (name == "pen_strength_mode") return double(int(app_.penStrength_));
+ if (name == "pen_size") return app_.pressureSizeOn() ? 1.0 : 0.0;
+ if (name == "pen_strength") return app_.pressureStrengthOn() ? 1.0 : 0.0;
if (name == "share_brush_size") return app_.brushSettingsStore().shareSizeIntensity ? 1.0 : 0.0;
if (name == "alpha_follow") return app_.alphaOptions_.followStroke ? 1.0 : 0.0; // alpha options (#76)
if (name == "alpha_angle") return std::round(app_.alphaOptions_.angle);
diff --git a/src/core/BrushRecipe.cpp b/src/core/BrushRecipe.cpp
index 95706859..a7c37417 100644
--- a/src/core/BrushRecipe.cpp
+++ b/src/core/BrushRecipe.cpp
@@ -146,6 +146,8 @@ Json BrushRecipe::toJson() const {
if (viewFalloff) j.set("viewFalloff", true);
if (!alpha.empty()) j.set("alpha", alpha);
if (alphaFollow) j.set("alphaFollow", true);
+ if (pressureSize != PenPressure::Global) j.set("penPressureSize", penPressureId(pressureSize));
+ if (pressureStrength != PenPressure::Global) j.set("penPressureStrength", penPressureId(pressureStrength));
for (const auto& p : recipeParams()) {
switch (p.kind) {
case K::Float: j.set(p.key, std::round(double(*floatField(r, p.key)) * 1000.0) / 1000.0); break;
@@ -167,6 +169,8 @@ void BrushRecipe::applyJson(const Json& j) {
if (j["connectedOnly"].isBool()) connectedOnly = j["connectedOnly"].asBool();
if (j["viewFalloff"].isBool()) viewFalloff = j["viewFalloff"].asBool();
if (j["alphaFollow"].isBool()) alphaFollow = j["alphaFollow"].asBool();
+ if (j["penPressureSize"].isString()) pressureSize = penPressureFromId(j["penPressureSize"].asString());
+ if (j["penPressureStrength"].isString()) pressureStrength = penPressureFromId(j["penPressureStrength"].asString());
if (j["alpha"].isString()) {
BrushAlpha a;
alpha = BrushAlpha::builtin(j["alpha"].asString(), a) && !a.empty() ? a.name : std::string();
diff --git a/src/core/BrushRecipe.h b/src/core/BrushRecipe.h
index 6a683fdd..609a6c6e 100644
--- a/src/core/BrushRecipe.h
+++ b/src/core/BrushRecipe.h
@@ -8,6 +8,7 @@
#pragma once
#include "core/Json.h"
+#include "core/PenPressure.h"
#include <string>
#include <vector>
@@ -78,6 +79,10 @@ struct BrushRecipe {
// alpha is on. Written to the JSON only when set. An unknown name is dropped.
std::string alpha;
bool alphaFollow = false; // the alpha turns along the stroke (Alpha > Follow stroke direction) on that first pick
+ // Pen pressure > Size / Strength for this brush (#122, core/PenPressure.h): what it starts with, and what Brush
+ // Lab sets. Written to the JSON only when not Use global.
+ PenPressure pressureSize = PenPressure::Global;
+ PenPressure pressureStrength = PenPressure::Global;
// Library bookkeeping, not part of the recipe: never written by toJson().
BrushOrigin origin;
diff --git a/src/core/BrushSettings.cpp b/src/core/BrushSettings.cpp
index a129f773..517cad2f 100644
--- a/src/core/BrushSettings.cpp
+++ b/src/core/BrushSettings.cpp
@@ -2,6 +2,7 @@
// SPDX-License-Identifier: GPL-3.0-or-later
#include "core/BrushSettings.h"
#include "core/Precision.h"
+#include "core/Sculpt.h"
#include <algorithm>
#include <filesystem>
@@ -55,6 +56,8 @@ Json BrushToolSettings::toJson() const {
j.set("alpha_tile_x", a.tileX);
j.set("alpha_tile_y", a.tileY);
}
+ j.set("pen_pressure_size", penPressureId(pressureSize)); // (always written: a missing one is the brush's default)
+ j.set("pen_pressure_strength", penPressureId(pressureStrength));
return j;
}
@@ -79,6 +82,8 @@ void BrushToolSettings::applyJson(const Json& j) {
readFloat(j, "alpha_angle_jitter", a.jitter);
a.tileX = int(j["alpha_tile_x"].asNumber(a.tileX));
a.tileY = int(j["alpha_tile_y"].asNumber(a.tileY));
+ pressureSize = penPressureFromId(j["pen_pressure_size"].asString(), pressureSize);
+ pressureStrength = penPressureFromId(j["pen_pressure_strength"].asString(), pressureStrength);
clamp();
}
@@ -92,6 +97,11 @@ BrushToolSettings BrushSettingsStore::switchBrush(const std::string& from, const
BrushToolSettings next = current; // a brush not used yet: the current values, nothing jumps
if (auto it = session_.find(to); it != session_.end()) next = it->second;
else if (auto s = saved_.find(to); s != saved_.end()) next = s->second;
+ else {
+ const BrushToolSettings own = shipped(to); // ...except pen pressure, the brush's own (a grab brush's Size off)
+ next.pressureSize = own.pressureSize;
+ next.pressureStrength = own.pressureStrength;
+ }
if (shareSizeIntensity) {
next.radiusPx = current.radiusPx;
next.strength = current.strength;
@@ -120,6 +130,9 @@ BrushToolSettings BrushSettingsStore::reset(const std::string& key) {
BrushToolSettings BrushSettingsStore::shipped(const std::string& key) {
BrushToolSettings s;
if (key == "builtin:Vdm") s.stroke = StrokeType::DragRect; // stamps a VDM where you drag (PanelVdm.cpp)
+ for (BrushType t : {BrushType::Move, BrushType::KelvinGrab, BrushType::KelvinTwist, BrushType::KelvinScale,
+ BrushType::SnakeHook, BrushType::KelvinSnake})
+ if (key == brushSettingsKey(brushName(t))) s.pressureSize = PenPressure::Off;
return s;
}
@@ -140,7 +153,7 @@ void BrushSettingsStore::applyJson(const Json& j) {
if (!brushes.isObject()) return;
for (const auto& [key, value] : brushes.members()) {
if (!value.isObject()) continue;
- BrushToolSettings s;
+ BrushToolSettings s = shipped(key); // (files before 0.11.1 have no pen pressure: the brush's default)
s.applyJson(value);
saved_[key] = s;
}
diff --git a/src/core/BrushSettings.h b/src/core/BrushSettings.h
index cb8de129..aefb1495 100644
--- a/src/core/BrushSettings.h
+++ b/src/core/BrushSettings.h
@@ -4,11 +4,13 @@
// Per-brush settings (#78): each brush keeps its own Draw Size, Z Intensity, Focal Shift, RGB Intensity, stroke and
// alpha. Picking another brush remembers the one left and brings back what the picked one had this session (or what
// Save Brush Settings stored for it, <app data>/brush-settings.json); a brush not used yet takes the current values,
-// so nothing jumps the first time. Reset Brush to Default puts back the shipped values.
+// so nothing jumps the first time. Reset Brush to Default puts back the shipped values. Pen pressure (#122) is the
+// exception to "nothing jumps": a brush not used yet starts with its own (grab brushes: Size off).
#pragma once
#include "core/AlphaOptions.h"
#include "core/Json.h"
+#include "core/PenPressure.h"
#include "core/Stroke.h"
#include <map>
@@ -29,6 +31,9 @@ struct BrushToolSettings {
std::string alphaPath;
bool alphaInvert = false;
AlphaOptions alphaOptions; // Follow stroke direction, Angle, Angle jitter, Tile (#76)
+ // Pen pressure > Size / Strength for this brush (#122): Use global (Preferences > Tablet), On or Off.
+ PenPressure pressureSize = PenPressure::Global;
+ PenPressure pressureStrength = PenPressure::Global;
bool operator==(const BrushToolSettings&) const = default;
void clamp();
@@ -53,7 +58,9 @@ public:
void store(const std::string& key, const BrushToolSettings& s);
// Reset Brush to Default: forgets `key`'s session and saved values; returns the shipped ones.
BrushToolSettings reset(const std::string& key);
- static BrushToolSettings shipped(const std::string& key); // the Vector Displacement brush stamps with DragRect
+ // The Vector Displacement brush stamps with DragRect; grab brushes (Move, the Kelvinlet grab / twist / scale,
+ // the tendrils) have Pressure > Size off, since a pen's press is nearly weightless (#122).
+ static BrushToolSettings shipped(const std::string& key);
bool hasSaved(const std::string& key) const { return saved_.count(key) != 0; }
// Used this session or saved: switchBrush brings its own values back (otherwise it takes the current ones).
bool known(const std::string& key) const { return session_.count(key) != 0 || saved_.count(key) != 0; }
diff --git a/src/core/PenPressure.h b/src/core/PenPressure.h
new file mode 100644
index 00000000..6bc9fd9b
--- /dev/null
+++ b/src/core/PenPressure.h
@@ -0,0 +1,21 @@
+// SculptForge - open source digital sculpting
+// SPDX-License-Identifier: GPL-3.0-or-later
+//
+// Pen pressure per brush (#122): each brush's Size and Strength follow the global switches (Preferences > Tablet,
+// the shelf's Pressure > Size / Strength), or are always on or always off for that brush.
+#pragma once
+
+#include <string>
+
+namespace sf {
+
+enum class PenPressure { Global, On, Off };
+
+inline bool penPressureOn(PenPressure p, bool global) { return p == PenPressure::Global ? global : p == PenPressure::On; }
+inline const char* penPressureId(PenPressure p) { return p == PenPressure::On ? "on" : p == PenPressure::Off ? "off" : "global"; }
+// "on", "off", "global" (anything else is `fallback`).
+inline PenPressure penPressureFromId(const std::string& s, PenPressure fallback = PenPressure::Global) {
+ return s == "on" ? PenPressure::On : s == "off" ? PenPressure::Off : s == "global" ? PenPressure::Global : fallback;
+}
+
+} // namespace sf
diff --git a/tests/test_brush_settings.cpp b/tests/test_brush_settings.cpp
index 709097a7..c4e80857 100644
--- a/tests/test_brush_settings.cpp
+++ b/tests/test_brush_settings.cpp
@@ -5,6 +5,7 @@
// in the session; Save Brush Settings writes them for the next start; Reset Brush to Default gives the shipped values.
#include "TestHarness.h"
+#include "core/BrushRecipe.h"
#include "core/BrushSettings.h"
#include <cstdio>
@@ -102,3 +103,69 @@ TEST(brush_settings_save_load_reset) {
CHECK(got.radiusPx == 800.0f && got.strength == 0.0f && got.stroke == StrokeType::Dots);
std::remove(path.c_str());
}
+
+// #122: each brush's own Pen pressure > Size / Strength (Use global / On / Off), grab brushes with Size off.
+TEST(brush_settings_pen_pressure_per_brush) {
+ CHECK(penPressureOn(PenPressure::Global, true) && !penPressureOn(PenPressure::Global, false));
+ CHECK(penPressureOn(PenPressure::On, false) && !penPressureOn(PenPressure::Off, true));
+ for (const char* grab : {"Move", "KelvinGrab", "KelvinTwist", "KelvinScale", "Tendril", "KelvinSnake"}) {
+ const BrushToolSettings s = BrushSettingsStore::shipped(brushSettingsKey(grab));
+ CHECK(s.pressureSize == PenPressure::Off);
+ CHECK(s.pressureStrength == PenPressure::Global);
+ }
+ CHECK(BrushSettingsStore::shipped("builtin:Clay").pressureSize == PenPressure::Global);
+ CHECK(BrushSettingsStore::shipped("builtin:Nudge").pressureSize == PenPressure::Global);
+ CHECK(BrushSettingsStore::shipped("custom:Clay Slab").pressureSize == PenPressure::Global);
+
+ // A brush not used yet takes the current values, except its own pen pressure.
+ BrushSettingsStore store;
+ BrushToolSettings live;
+ live.radiusPx = 77.0f;
+ live.pressureStrength = PenPressure::Off;
+ BrushToolSettings move = store.switchBrush("builtin:Clay", "builtin:Move", live);
+ CHECK(move.radiusPx == 77.0f);
+ CHECK(move.pressureSize == PenPressure::Off && move.pressureStrength == PenPressure::Global);
+ move.pressureSize = PenPressure::On; // the artist's choice is kept for the brush
+ const BrushToolSettings clay = store.switchBrush("builtin:Move", "builtin:Clay", move);
+ CHECK(clay.pressureStrength == PenPressure::Off && clay.pressureSize == PenPressure::Global);
+ CHECK(store.switchBrush("builtin:Clay", "builtin:Move", clay).pressureSize == PenPressure::On);
+
+ // Saved and loaded; a file from before 0.11.1 (no pen pressure) loads as Use global, a grab brush with Size off.
+ std::string err;
+ Json j;
+ CHECK(Json::parse(R"({"brushes":{"builtin:Clay":{"draw_size":50},"builtin:Move":{"draw_size":50},
+ "builtin:Standard":{"pen_pressure_size":"on","pen_pressure_strength":"off"}}})",
+ j, err));
+ BrushSettingsStore old;
+ old.applyJson(j);
+ BrushToolSettings got;
+ CHECK(old.savedFor("builtin:Clay", got) && got.pressureSize == PenPressure::Global &&
+ got.pressureStrength == PenPressure::Global);
+ CHECK(old.savedFor("builtin:Move", got) && got.pressureSize == PenPressure::Off);
+ CHECK(old.savedFor("builtin:Standard", got) && got.pressureSize == PenPressure::On &&
+ got.pressureStrength == PenPressure::Off);
+ BrushToolSettings s;
+ s.pressureSize = PenPressure::Global; // an explicit Use global on Move survives a save
+ store.store("builtin:Move", s);
+ BrushSettingsStore again;
+ again.applyJson(store.toJson());
+ CHECK(again.savedFor("builtin:Move", got) && got.pressureSize == PenPressure::Global);
+
+ // A reset gives the brush's shipped pen pressure back.
+ CHECK(again.reset("builtin:Move").pressureSize == PenPressure::Off);
+}
+
+// #122: a custom brush carries its pen pressure in its .sfbrush; older files (and Use global) write nothing.
+TEST(brush_recipe_pen_pressure) {
+ BrushRecipe r;
+ CHECK(r.toJson()["penPressureSize"].isNull() && r.toJson()["penPressureStrength"].isNull());
+ r.pressureSize = PenPressure::Off;
+ r.pressureStrength = PenPressure::On;
+ const BrushRecipe back = BrushRecipe::fromJson(r.toJson());
+ CHECK(back.pressureSize == PenPressure::Off && back.pressureStrength == PenPressure::On);
+ Json j;
+ std::string err;
+ CHECK(Json::parse(R"({"name":"Old","depth":0.3,"penPressureSize":"sideways"})", j, err));
+ const BrushRecipe old = BrushRecipe::fromJson(j);
+ CHECK(old.pressureSize == PenPressure::Global && old.pressureStrength == PenPressure::Global);
+}
diff --git a/tests/ui/pen_pressure_per_brush.sfui b/tests/ui/pen_pressure_per_brush.sfui
new file mode 100644
index 00000000..5be46abf
--- /dev/null
+++ b/tests/ui/pen_pressure_per_brush.sfui
@@ -0,0 +1,114 @@
+# #122: every brush has its own Pen pressure > Size / Strength (Use global / On / Off) in the Brush palette, Brush
+# Lab and Preferences > Tablet. Grab brushes start with Size off; the rest follow the global switches. Kept per
+# brush, saved with Save Brush Settings, put back by Reset Brush to Default; a custom brush keeps them in its recipe.
+run ui_look look=classic layout=classic # written for the Classic look and the classic palette bar and shelves
+wait 0.2
+run new_sphere subdivisions=5
+snapshot
+
+# Defaults: Use global (Size off, Strength on); grab brushes: Size off whatever the global switch says.
+click "Standard##brush.standard"
+expect_value pen_size_mode == 0
+expect_value pen_strength_mode == 0
+expect_value pen_size == 0
+expect_value pen_strength == 1
+click "Pressure > Size"
+expect_value pen_size == 1
+click "Move##brush.move"
+wait 0.1 # (the switch is picked up on the next frame)
+expect_value pen_size_mode == 2
+expect_value pen_size == 0
+expect_value pen_strength == 1
+click "Tendril##brush.tendril"
+wait 0.1
+expect_value pen_size_mode == 2
+click "Clay##brush.clay"
+wait 0.1
+expect_value pen_size_mode == 0
+expect_value pen_size == 1
+
+# Standard with the global Pressure > Size on: a light touch makes a small stroke...
+click "Standard##brush.standard"
+wait 0.1
+pen_stroke 0.3 0.45 0.7 0.55 0.2 0.2
+remember moved small
+key ctrl+z
+pen_out
+# ...and with this brush's Size off it draws at full size, while Clay still follows the global switch.
+click "Brush##palette.brush"
+click "Off##brush.pen_size_off"
+shot brush-palette
+expect_value pen_size_mode == 2
+expect_value pen_size == 0
+expect_status Pen pressure > Size for Standard: off
+click "Brush##palette.brush" # (closed again: the canvas takes the pen)
+pen_stroke 0.3 0.45 0.7 0.55 0.2 0.2
+expect_value moved > $small*1.5
+key ctrl+z
+pen_out
+click "Clay##brush.clay"
+wait 0.1
+expect_value pen_size == 1
+click "Standard##brush.standard"
+wait 0.1
+expect_value pen_size_mode == 2
+
+# Strength On for this brush with the global Pressure > Strength off: light and heavy still differ.
+click "Pressure > Strength"
+expect_value pen_strength == 0
+click "Brush##palette.brush"
+click "On##brush.pen_strength_on"
+click "Brush##palette.brush"
+expect_value pen_strength == 1
+pen_stroke 0.3 0.45 0.7 0.55 0.2 0.2
+remember moved_out light
+key ctrl+z
+pen_out
+pen_stroke 0.3 0.45 0.7 0.55 0.9 0.9
+expect_value moved_out > $light*3
+key ctrl+z
+pen_out
+click "Brush##palette.brush"
+click "Use global##brush.pen_strength_global"
+expect_value pen_strength == 0
+click "Brush##palette.brush"
+click "Pressure > Strength"
+expect_value pen_strength == 1
+
+# Save Brush Settings keeps them; Reset Brush to Default gives Use global back (Move: Size off).
+click "Brush##palette.brush"
+click "Save Brush Settings##brush.save_settings"
+expect_value brush_settings_saved == 1
+click "Reset Brush to Default##brush.reset_settings"
+expect_value pen_size_mode == 0
+expect_value brush_settings_saved == 0
+click "Brush##palette.brush"
+click "Move##brush.move"
+wait 0.1
+click "Brush##palette.brush"
+click "On##brush.pen_size_on"
+expect_value pen_size_mode == 1
+click "Reset Brush to Default##brush.reset_settings"
+expect_value pen_size_mode == 2
+click "Brush##palette.brush"
+
+# A custom brush keeps its own in its recipe, and the command sets them too.
+run brush_create name="Pen Slab" depth=0.4
+wait 0.1
+expect_value pen_strength_mode == 0
+run brush_pen_pressure strength=off size=on
+expect_value pen_strength_mode == 2
+expect_value pen_size_mode == 1
+click "Clay##brush.clay"
+wait 0.1
+expect_value pen_strength_mode == 0
+run brush_create name="Pen Slab" depth=0.4
+wait 0.1
+expect_value pen_strength_mode == 2
+
+# Preferences > Tablet shows the current brush's switches under the global ones.
+click "Preferences##palette.preferences"
+click "Tablet##preferences.tablet"
+wait 0.3
+expect "Use global##brush.pen_size_global"
+shot preferences-tablet