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.

Twelve more built-in alphas and six more VDM brushes, generated in code at first use (#43): thumbnails in the pickers and the LightBox (Brush tab lists built-in VDMs too); unit and UI tests

islandmed3674e283dcb8
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f4dd8ff2..b80f1e69 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -31,6 +31,10 @@ All notable changes to SculptForge are listed here. The format follows
- **Preferences > Input > Hold Space and drag to move the camera** (#43, off by default since ZBrush's Space opens
the QuickMenu): with Space held, left-drag rotates, right- or middle-drag pans and Ctrl+drag zooms, anywhere on
the canvas; never while typing in a text field.
+- Twelve more built-in alphas (#43): Pores, Cracks, Scales, Rivets, Stitches, Fabric Weave, Bark, Rock Strata,
+ Wrinkles, Skin Folds, Hair Strands and Dot Grid; and six more VDM brushes: Rivet, Stitches, Skin Fold, Wrinkle
+ Line, Crack and Rock Ledge. All are generated in code the first time they're used (no downloaded or bundled
+ image files), with thumbnails in the pickers and the LightBox (whose Brush tab now lists the built-in VDMs too).
- SubTool thumbnails in the SubTool list (#43), drawn from each SubTool's existing GPU buffers (no upload, the
motion proxy on dense meshes), one per frame at most and only once a change has settled, never during a stroke.
diff --git a/docs/guide/interface.md b/docs/guide/interface.md
index 07bf7320..88ab8912 100644
--- a/docs/guide/interface.md
+++ b/docs/guide/interface.md
@@ -57,7 +57,7 @@ Interface > Palettes strictly A-Z (ZBrush order)**.
|---|---|
| **File** | New Sphere, New Plane, Open, Open Recent, Save, Save As, autosave interval, Import and every export (OBJ, GLB, LOD chain, USD/USDZ, FBX for Unreal, Send to Unreal, splats), ZBrush (GoZ), Quit |
| **Edit** | Undo and Redo (with the name of the step), Paste brush |
-| **Alpha** | The brush alphas: Round, Square, Noise, images from your library, Load image, Invert loaded image |
+| **Alpha** | The brush alphas: Round, Square, Noise and twelve patterns (Pores, Cracks, Scales...), images from your library, Load image, Invert loaded image |
| **Brush** | AI Brush (Brush Lab), Community brushes, Paste brush, your custom brushes, Front faces only, Invert (Alt), the recipe editor for a custom brush, and every brush as a thumbnail grid with a filter |
| **Color** | The Paint brush, RGB while sculpting, the paint colour and swatches, Fill, Fill masked, Cavity, Clear, Show polypaint |
| **Draw** | Draw Size, Z Intensity, RGB Intensity, Focal Shift, Sculpt/Paint, Zadd/Zsub, Rgb, Front, and the tablet options (Pressure > strength, Pressure > size) with a pen readout |
@@ -219,7 +219,8 @@ brushes](brush-lab.md)).
- **Stroke** (click the Stroke tile): Dots, DragRect, Spray and LazyMouse, with Scatter for Spray and Lazy
radius for LazyMouse. See [Sculpting and brushes](sculpting.md).
-- **Alpha** (click the Alpha tile): Round, Square and Noise, the image alpha you loaded, images in your
+- **Alpha** (click the Alpha tile): Round, Square, Noise and the twelve built-in patterns (Pores, Cracks, Scales,
+ Rivets, Stitches, Fabric Weave, Bark, Rock Strata, Wrinkles, Skin Folds, Hair Strands, Dot Grid), the image alpha you loaded, images in your
library's Alphas folder, **Load image...** and **Invert loaded image**.
- **Material** (<kbd>M</kbd>, or click the Material tile): the MatCaps and Studio. Point at a material to
preview it on the model; click to keep it. Closing the picker without clicking puts the old material back.
@@ -245,8 +246,8 @@ start-up (see [Preferences](#interface-preferences)).
|---|---|---|
| **Project** | Projects (`.sfproj`) in your library and recently opened projects | Open the project |
| **Tool** | Sphere, Plane and Cube, and model files in your library | Open (replaces the scene) |
-| **Brush** | Every brush: built-in, custom and `.sfbrush` files | Select or load the brush |
-| **Alpha** | Round, Square, Noise and images in your Alphas folder | Use as the brush alpha |
+| **Brush** | Every brush: built-in, custom and `.sfbrush` files, and the VDM brushes (built-in ones too) | Select or load the brush |
+| **Alpha** | Round, Square, Noise, the twelve built-in patterns and images in your Alphas folder | Use as the brush alpha |
| **Material** | The MatCaps (your own included) and Studio | Use the material |
| **Image** | Reference images in your library | A menu: Generate 3D, relief, inflate, project onto the model, use as alpha |
| **Splats** | Gaussian splat captures (`.ply`, `.splat`) | Open the capture as a reference |
diff --git a/docs/guide/sculpting.md b/docs/guide/sculpting.md
index ad82c359..fc085f74 100644
--- a/docs/guide/sculpting.md
+++ b/docs/guide/sculpting.md
@@ -257,6 +257,21 @@ brush, built-in or custom. Choose one from the **Alpha** tile on the left shelf
| **Round** | The plain round falloff (no alpha). The default. |
| **Square** | A square stamp with soft edges. |
| **Noise** | A noisy stamp for rough, organic texture. |
+| **Pores** | Scattered skin pores of mixed sizes (use with Zsub to press them in). |
+| **Cracks** | A web of thin cracks, as in dry earth, old paint or stone. |
+| **Scales** | Overlapping rounded scales in offset rows, for reptiles and fish. |
+| **Rivets** | A three by three grid of round rivet heads, for armour and machines. |
+| **Stitches** | A seam with cross stitches along it (drag along the seam with DragRect or a stroke). |
+| **Fabric Weave** | Threads woven over and under, for cloth and canvas. |
+| **Bark** | Rough vertical ridges and furrows, as on tree bark. |
+| **Rock Strata** | Stepped layers of rock, wavy and broken, for cliffs and stone. |
+| **Wrinkles** | Fine parallel wrinkle lines, for skin around eyes, knuckles and necks. |
+| **Skin Folds** | Soft, broad folds of skin, for bellies, elbows and heavy brows. |
+| **Hair Strands** | Long flowing strands, for hair, fur and feathers (drag along the flow). |
+| **Dot Grid** | An even grid of soft dots, for studs, textures and patterns. |
+
+All of them are made by SculptForge itself the first time they're needed (no image files are downloaded or
+shipped). They show in the alpha picker and in the LightBox's **Alpha** tab (`brush_set_alpha name=cracks`).
To use your own image:
@@ -286,7 +301,10 @@ overhang, as nothing made with a height ever can.
### Stamp a VDM
1. Open the **Brush** palette and its **Vector Displacement** section, and click a map: **Horn**, **Ear Curl**,
- **Scales** or **Nostril**. The **VDM** brush becomes the brush and the stroke becomes **DragRect**. (While the
+ **Scales**, **Nostril**, **Rivet** (a domed head whose rim overhangs), **Stitches** (thread bars across a seam,
+ drawing it together), **Skin Fold** (a roll of skin hanging over a crease), **Wrinkle Line** (a fine pinched
+ crease), **Crack** (a jagged split whose sides part) or **Rock Ledge** (a stepped shelf jutting out over the
+ layer below). They're also in the LightBox's **Brush** tab. The **VDM** brush becomes the brush and the stroke becomes **DragRect**. (While the
VDM brush is the brush, the Alpha tile on the left shelf shows its map, and the alpha picker lists the maps
first. The VDM brush is also in the brush picker: <kbd>B</kbd> <kbd>V</kbd> <kbd>D</kbd>.)
2. Click on the model where the stamp should sit and drag: the drag's length sets the size and its direction
diff --git a/src/app/LightBox.cpp b/src/app/LightBox.cpp
index 590279ff..a19aa023 100644
--- a/src/app/LightBox.cpp
+++ b/src/app/LightBox.cpp
@@ -101,10 +101,9 @@ std::string dateText(int64_t t) {
}
const BrushAlpha& builtinAlpha(int i) {
- static const BrushAlpha alphas[] = {BrushAlpha::round(), BrushAlpha::square(), BrushAlpha::noise()};
- return alphas[std::clamp(i, 0, 2)];
+ const auto& all = BrushAlpha::builtins(); // Round, Square, Noise and the generated patterns (#43)
+ return all[size_t(std::clamp(i, 0, int(all.size()) - 1))];
}
-const char* const kAlphaNames[] = {"Round", "Square", "Noise"};
void SDLCALL onFolderChosen(void* userdata, const char* const* files, int) {
wakeMainLoop(); // a file dialog answered (maybe on another thread): redraw now
@@ -230,9 +229,8 @@ void LightBox::rootEntries(App& app, std::vector<AssetEntry>& out) {
}
out.push_back(std::move(e));
}
- // Vector displacement brushes from the library (built-ins are in the VDM picker).
+ // Vector displacement brushes: the built-ins (#43: thumbnails here too), then the library's.
for (const auto& v : app.doc_.vdms) {
- if (v->builtin) continue;
AssetEntry e;
e.kind = AssetKind::Vdm;
e.name = v->name;
@@ -241,11 +239,11 @@ void LightBox::rootEntries(App& app, std::vector<AssetEntry>& out) {
}
break;
case LibraryTab::Alpha: {
- for (int i = 0; i < 3; ++i) {
+ for (int i = 0; i < int(BrushAlpha::builtins().size()); ++i) {
AssetEntry e;
e.kind = AssetKind::Alpha;
e.index = i;
- e.name = kAlphaNames[i];
+ e.name = builtinAlpha(i).name;
out.push_back(std::move(e));
}
const auto files = scan(userDir, false);
@@ -447,7 +445,7 @@ void LightBox::activate(App& app, const AssetEntry& e, bool append) {
app.runCommand("vdm_set", {{"name", e.name}});
return;
case AssetKind::Alpha:
- app.runCommand("brush_set_alpha", {{"name", lower(kAlphaNames[std::clamp(e.index, 0, 2)])}});
+ app.runCommand("brush_set_alpha", {{"name", builtinAlpha(e.index).name}});
return;
case AssetKind::AlphaFile:
app.runCommand("brush_set_alpha", {{"path", e.path}, {"invert", app.alphaInvert_}});
diff --git a/src/app/Pickers.cpp b/src/app/Pickers.cpp
index 0bf16121..6bb37b2e 100644
--- a/src/app/Pickers.cpp
+++ b/src/app/Pickers.cpp
@@ -231,8 +231,8 @@ void pickerTitle(const char* icon, const char* title, const char* hint) {
}
const BrushAlpha& builtinAlpha(int i) {
- static const std::array<BrushAlpha, 3> alphas = {BrushAlpha::round(), BrushAlpha::square(), BrushAlpha::noise()};
- return alphas[size_t(std::clamp(i, 0, 2))];
+ const auto& all = BrushAlpha::builtins(); // Round, Square, Noise and the generated patterns (#43)
+ return all[size_t(std::clamp(i, 0, int(all.size()) - 1))];
}
} // namespace
@@ -833,19 +833,18 @@ void drawAlphaGrid(App& app, GridMode mode) {
const float tile = 64.0f * app.uiScale_;
const int columns = columnsFor(tile, mode);
const BrushAlpha& current = app.doc_.brushAlpha;
- static const char* const names[] = {"Round", "Square", "Noise"};
- static const char* const help[] = {"The plain round falloff (no alpha).", "A square stamp with soft edges.",
- "A noisy stamp for rough, organic texture."};
sectionHeader("Built-in");
int column = 0;
- for (int i = 0; i < 3; ++i) {
+ for (int i = 0; i < int(BrushAlpha::builtins().size()); ++i) {
tileGrid(column, columns);
- const bool on = lower(current.name) == lower(names[i]) || (i == 0 && current.empty());
+ const std::string& name = builtinAlpha(i).name;
+ const std::string help = BrushAlpha::builtinHelp(name);
+ const bool on = lower(current.name) == lower(name) || (i == 0 && current.empty());
const ImTextureID tex = app.thumbs_.alpha(builtinAlpha(i));
- if (AssetTile((std::string(names[i]) + "##alpha").c_str(), tex, ICON_LC_CIRCLE_DASHED, names[i], tile, on))
- app.runCommand("brush_set_alpha", {{"name", lower(names[i])}});
- quickInfo(tex, ICON_LC_CIRCLE_DASHED, names[i], help[i]);
- ui::HelpText(names[i], nullptr, help[i], "Alpha");
+ if (AssetTile((name + "##alpha").c_str(), tex, ICON_LC_CIRCLE_DASHED, name.c_str(), tile, on))
+ app.runCommand("brush_set_alpha", {{"name", name}});
+ quickInfo(tex, ICON_LC_CIRCLE_DASHED, name.c_str(), help.c_str());
+ ui::HelpText(name.c_str(), nullptr, help.c_str(), "Alpha");
}
// The loaded image alpha, then images in the library's Alphas folder.
const bool custom = !current.empty() && lower(current.name) != "square" && lower(current.name) != "noise";
diff --git a/src/core/BrushAlpha.cpp b/src/core/BrushAlpha.cpp
index 9542545f..203a8cf3 100644
--- a/src/core/BrushAlpha.cpp
+++ b/src/core/BrushAlpha.cpp
@@ -60,6 +60,224 @@ std::string lower(std::string s) {
return s;
}
+// A name to look up by: lower case without spaces, '_' or '-' ("Fabric Weave", "fabric_weave").
+std::string lookupKey(const std::string& s) {
+ std::string out;
+ for (unsigned char c : s)
+ if (c != ' ' && c != '_' && c != '-') out += char(std::tolower(c));
+ return out;
+}
+
+float hash01(int x, int y, uint32_t seed) { return float(hash2(x, y, seed) & 0xffffu) / 65535.0f; }
+
+float fbm(float x, float y, uint32_t seed, int octaves = 3) {
+ float sum = 0.0f, amp = 0.5f, norm = 0.0f;
+ for (int o = 0; o < octaves; ++o) {
+ sum += valueNoise2(x, y, seed + uint32_t(o)) * amp;
+ norm += amp;
+ x = x * 2.03f + 1.7f;
+ y = y * 2.03f + 3.1f;
+ amp *= 0.5f;
+ }
+ return sum / norm;
+}
+
+// Distances to the nearest and second nearest feature point of a jittered grid (Worley noise); `id` gets the
+// nearest point's cell hash.
+void worley(float x, float y, uint32_t seed, float& f1, float& f2, uint32_t* id = nullptr) {
+ const int cx = int(std::floor(x)), cy = int(std::floor(y));
+ f1 = f2 = 1e9f;
+ for (int dy = -1; dy <= 1; ++dy)
+ for (int dx = -1; dx <= 1; ++dx) {
+ const int gx = cx + dx, gy = cy + dy;
+ const float px = float(gx) + hash01(gx, gy, seed), py = float(gy) + hash01(gx, gy, seed + 7);
+ const float d = std::hypot(x - px, y - py);
+ if (d < f1) {
+ f2 = f1;
+ f1 = d;
+ if (id) *id = hash2(gx, gy, seed + 13);
+ } else if (d < f2) {
+ f2 = d;
+ }
+ }
+}
+
+// Fades a pattern that fills the square out over its outer edge, so the stamp has no hard border.
+float squareEdge(float u, float v) { return smooth01((1.0f - std::max(std::abs(u), std::abs(v))) / 0.18f); }
+float roundEdge(float u, float v) { return brushFalloff(std::sqrt(u * u + v * v), 1.0f); }
+
+// Distance from p to the segment a-b.
+float segmentDistance(float px, float py, float ax, float ay, float bx, float by) {
+ const float vx = bx - ax, vy = by - ay;
+ const float t = std::clamp(((px - ax) * vx + (py - ay) * vy) / std::max(vx * vx + vy * vy, 1e-12f), 0.0f, 1.0f);
+ return std::hypot(px - (ax + vx * t), py - (ay + vy * t));
+}
+
+constexpr float kPi = 3.14159265f;
+
+// The generated built-ins (#43): made here in code from noise and simple shapes, no image files.
+struct Generated {
+ const char* name;
+ const char* help;
+ BrushAlpha (*make)();
+};
+
+const Generated kGenerated[] = {
+ {"Pores", "Scattered skin pores of mixed sizes (use with Zsub to press them in).",
+ [] {
+ return generate("Pores", [](float u, float v) {
+ float f1, f2;
+ uint32_t id = 0;
+ worley(u * 9.0f + 20.0f, v * 9.0f + 20.0f, 41, f1, f2, &id);
+ const float r = 0.16f + 0.14f * float(id & 0xffu) / 255.0f;
+ const float pore = 1.0f - smooth01(f1 / r);
+ const float grain = fbm(u * 14.0f + 5.0f, v * 14.0f + 5.0f, 43) * 0.25f;
+ return (pore * 0.85f + grain) * squareEdge(u, v);
+ });
+ }},
+ {"Cracks", "A web of thin cracks, as in dry earth, old paint or stone.",
+ [] {
+ return generate("Cracks", [](float u, float v) {
+ const float wx = u * 3.2f + (fbm(u * 3.0f + 9.0f, v * 3.0f, 51) - 0.5f) * 0.9f;
+ const float wy = v * 3.2f + (fbm(u * 3.0f, v * 3.0f + 9.0f, 53) - 0.5f) * 0.9f;
+ float f1, f2;
+ worley(wx + 30.0f, wy + 30.0f, 55, f1, f2);
+ const float width = 0.035f + 0.04f * fbm(u * 5.0f + 2.0f, v * 5.0f, 57);
+ return (1.0f - smooth01((f2 - f1) / width)) * squareEdge(u, v);
+ });
+ }},
+ {"Scales", "Overlapping rounded scales in offset rows, for reptiles and fish.",
+ [] {
+ return generate("Scales", [](float u, float v) {
+ const float rows = 5.0f, size = 2.0f / rows;
+ float best = 0.0f;
+ const float y = (v + 1.0f) / size;
+ for (int r = int(std::floor(y)) - 1; r <= int(std::floor(y)) + 1; ++r) {
+ const float shift = (r & 1) ? 0.5f : 0.0f;
+ const float x = (u + 1.0f) / size - shift;
+ for (int c = int(std::floor(x)) - 1; c <= int(std::floor(x)) + 1; ++c) {
+ const float dx = x - (float(c) + 0.5f), dy = y - float(r); // each scale hangs from its row line
+ const float d = std::hypot(dx, dy * 1.15f);
+ if (d > 0.62f || dy > 0.1f) continue;
+ const float h = (1.0f - smooth01(d / 0.62f)) * (0.55f + 0.45f * smooth01(-dy / 0.6f));
+ best = std::max(best, h * (0.85f + 0.15f * float(r & 1))); // lower rows lie over upper ones
+ }
+ }
+ return best * squareEdge(u, v);
+ });
+ }},
+ {"Rivets", "A three by three grid of round rivet heads, for armour and machines.",
+ [] {
+ return generate("Rivets", [](float u, float v) {
+ const float cell = 2.0f / 3.0f;
+ const float cx = (std::floor((u + 1.0f) / cell) + 0.5f) * cell - 1.0f;
+ const float cy = (std::floor((v + 1.0f) / cell) + 0.5f) * cell - 1.0f;
+ const float d = std::hypot(u - cx, v - cy) / (cell * 0.3f);
+ return d < 1.0f ? std::sqrt(1.0f - d * d) : 0.0f;
+ });
+ }},
+ {"Stitches", "A seam with cross stitches along it (drag along the seam with DragRect or a stroke).",
+ [] {
+ return generate("Stitches", [](float u, float v) {
+ const float seam = 0.35f * (1.0f - smooth01(std::abs(u) / 0.05f)); // the sewn-together edge
+ float stitch = 0.0f;
+ for (int k = -4; k <= 4; ++k) {
+ const float y = float(k) * 0.22f;
+ const float d = segmentDistance(u, v, -0.32f, y - 0.06f, 0.32f, y + 0.06f);
+ stitch = std::max(stitch, 1.0f - smooth01(d / 0.055f));
+ }
+ return std::max(seam, stitch) * smooth01((1.0f - std::abs(v)) / 0.15f) * smooth01((1.0f - std::abs(u)) / 0.3f);
+ });
+ }},
+ {"Fabric Weave", "Threads woven over and under, for cloth and canvas.",
+ [] {
+ return generate("Fabric Weave", [](float u, float v) {
+ const float f = 6.0f; // threads across
+ const float x = (u + 1.0f) * f, y = (v + 1.0f) * f;
+ const int ix = int(std::floor(x)), iy = int(std::floor(y));
+ const float warp = std::sin(kPi * (x - float(ix))); // across a vertical thread
+ const float weft = std::sin(kPi * (y - float(iy))); // across a horizontal thread
+ const bool warpOnTop = ((ix + iy) & 1) == 0;
+ // The thread on top bulges in the middle of its crossing, the one below dips.
+ const float along = warpOnTop ? std::sin(kPi * (y - float(iy))) : std::sin(kPi * (x - float(ix)));
+ const float top = (warpOnTop ? warp : weft) * (0.6f + 0.4f * along);
+ const float under = (warpOnTop ? weft : warp) * 0.45f;
+ return std::max(top, under) * squareEdge(u, v);
+ });
+ }},
+ {"Bark", "Rough vertical ridges and furrows, as on tree bark.",
+ [] {
+ return generate("Bark", [](float u, float v) {
+ const float warp = (fbm(u * 2.0f + 4.0f, v * 0.6f, 61, 4) - 0.5f) * 1.2f;
+ const float ridge = 1.0f - std::abs(std::sin((u * 3.5f + warp) * kPi));
+ const float breaks = fbm(u * 6.0f, v * 2.0f + 7.0f, 63);
+ return std::clamp(std::pow(ridge, 0.6f) * (0.55f + 0.45f * breaks), 0.0f, 1.0f) * squareEdge(u, v);
+ });
+ }},
+ {"Rock Strata", "Stepped layers of rock, wavy and broken, for cliffs and stone.",
+ [] {
+ return generate("Rock Strata", [](float u, float v) {
+ const float y = v * 4.0f + (fbm(u * 1.5f + 3.0f, v * 0.8f, 71) - 0.5f) * 1.6f;
+ const float layer = y - std::floor(y);
+ const float step = smooth01(layer / 0.75f); // each layer slopes up, then drops off
+ const float rough = fbm(u * 8.0f, v * 8.0f + 11.0f, 73) * 0.3f;
+ return std::clamp(step * 0.75f + rough, 0.0f, 1.0f) * squareEdge(u, v);
+ });
+ }},
+ {"Wrinkles", "Fine parallel wrinkle lines, for skin around eyes, knuckles and necks.",
+ [] {
+ return generate("Wrinkles", [](float u, float v) {
+ float lines = 0.0f;
+ for (int k = -3; k <= 3; ++k) {
+ const float y = float(k) * 0.2f + 0.05f * std::sin(u * 2.5f + float(k)) + 0.12f * u * u;
+ const float len = 0.75f - 0.06f * float(std::abs(k));
+ const float d = std::abs(v - y);
+ const float along = smooth01((len - std::abs(u)) / 0.25f); // tapered ends
+ lines = std::max(lines, (1.0f - smooth01(d / 0.035f)) * along);
+ }
+ return lines * roundEdge(u, v * 0.8f);
+ });
+ }},
+ {"Skin Folds", "Soft, broad folds of skin, for bellies, elbows and heavy brows.",
+ [] {
+ return generate("Skin Folds", [](float u, float v) {
+ float folds = 0.0f;
+ for (int k = -1; k <= 1; ++k) {
+ const float y = float(k) * 0.42f + 0.18f * u * u;
+ const float d = v - y;
+ // A rounded roll: steep below the crease line, a long soft slope above it.
+ const float roll = d < 0.0f ? 1.0f - smooth01(-d / 0.08f) : 1.0f - smooth01(d / 0.3f);
+ folds = std::max(folds, roll * smooth01((0.85f - std::abs(u)) / 0.35f));
+ }
+ return folds * roundEdge(u * 0.9f, v * 0.9f);
+ });
+ }},
+ {"Hair Strands", "Long flowing strands, for hair, fur and feathers (drag along the flow).",
+ [] {
+ return generate("Hair Strands", [](float u, float v) {
+ const float x = u + 0.12f * std::sin(v * 2.2f) + 0.05f * std::sin(v * 5.0f + u * 3.0f);
+ const float strands = 22.0f;
+ const float s = (x + 1.0f) * strands * 0.5f;
+ const int is = int(std::floor(s));
+ const float across = s - float(is) - 0.5f;
+ const float bright = 0.55f + 0.45f * hash01(is, 0, 81);
+ const float width = 0.22f + 0.15f * hash01(is, 1, 81);
+ const float strand = 1.0f - smooth01(std::abs(across) / width);
+ const float ends = smooth01((0.85f - std::abs(v + 0.2f * (hash01(is, 2, 81) - 0.5f))) / 0.3f);
+ return strand * bright * ends * smooth01((1.0f - std::abs(u)) / 0.2f);
+ });
+ }},
+ {"Dot Grid", "An even grid of soft dots, for studs, textures and patterns.",
+ [] {
+ return generate("Dot Grid", [](float u, float v) {
+ const float cell = 2.0f / 7.0f;
+ const float cx = (std::floor((u + 1.0f) / cell) + 0.5f) * cell - 1.0f;
+ const float cy = (std::floor((v + 1.0f) / cell) + 0.5f) * cell - 1.0f;
+ return (1.0f - smooth01(std::hypot(u - cx, v - cy) / (cell * 0.32f))) * squareEdge(u, v);
+ });
+ }},
+};
+
} // namespace
float BrushAlpha::sample(float u, float v) const {
@@ -97,13 +315,44 @@ BrushAlpha BrushAlpha::noise(uint32_t seed) {
});
}
+const std::vector<BrushAlpha>& BrushAlpha::builtins() {
+ static const std::vector<BrushAlpha> all = [] { // made once, on first use
+ std::vector<BrushAlpha> v{round(), square(), noise()};
+ v.front().name = "Round";
+ for (const Generated& g : kGenerated) v.push_back(g.make());
+ return v;
+ }();
+ return all;
+}
+
+std::string BrushAlpha::builtinHelp(const std::string& name) {
+ const std::string key = lookupKey(name);
+ if (key == "round" || key == "none" || key.empty()) return "The plain round falloff (no alpha).";
+ if (key == "square") return "A square stamp with soft edges.";
+ if (key == "noise") return "A noisy stamp for rough, organic texture.";
+ for (const Generated& g : kGenerated)
+ if (lookupKey(g.name) == key) return g.help;
+ return {};
+}
+
+std::string BrushAlpha::builtinNames() {
+ std::string out;
+ for (const BrushAlpha& a : builtins()) out += (out.empty() ? "" : ", ") + lower(a.name);
+ return out;
+}
+
bool BrushAlpha::builtin(const std::string& name, BrushAlpha& out) {
- const std::string n = lower(name);
- if (n == "round" || n == "none" || n.empty()) out = round();
- else if (n == "square") out = square();
- else if (n == "noise") out = noise();
- else return false;
- return true;
+ const std::string key = lookupKey(name);
+ if (key == "none" || key.empty()) {
+ out = round();
+ return true;
+ }
+ for (const BrushAlpha& a : builtins())
+ if (lookupKey(a.name) == key) {
+ out = a;
+ return true;
+ }
+ return false;
}
BrushAlpha BrushAlpha::fromImage(const Image& image, std::string name, bool invert) {
@@ -127,8 +376,10 @@ void registerBrushCommands(CommandRegistry& registry) {
using T = ParamSpec::Type;
registry.add({"brush_set_alpha",
"Set the brush alpha (grayscale stamp shaping the falloff of every brush): a built-in "
- "(round = none, square, noise) or a grayscale image file.",
- {{"name", T::String, "Built-in alpha: round, square or noise.", false},
+ "(round = none, square, noise, pores, cracks, scales, rivets, stitches, fabric weave, bark, rock "
+ "strata, wrinkles, skin folds, hair strands, dot grid) or a grayscale image file.",
+ {{"name", T::String, "Built-in alpha: round, square, noise, pores, cracks, scales, rivets, stitches, "
+ "fabric_weave, bark, rock_strata, wrinkles, skin_folds, hair_strands or dot_grid.", false},
{"path", T::String, "Image file (png, jpg, ...) used as the alpha; overrides name.", false},
{"invert", T::Bool, "Use the image's negative (white = no effect).", false}},
[](Document& doc, const Args& a) -> CommandResult {
@@ -145,7 +396,8 @@ void registerBrushCommands(CommandRegistry& registry) {
}
const std::string name = argString(a, "name", "round");
BrushAlpha alpha;
- if (!BrushAlpha::builtin(name, alpha)) return {false, "Unknown alpha: " + name + " (round, square, noise)"};
+ if (!BrushAlpha::builtin(name, alpha))
+ return {false, "Unknown alpha: " + name + " (" + BrushAlpha::builtinNames() + ")"};
doc.brushAlpha = std::move(alpha);
return {true, "Alpha '" + doc.brushAlpha.name + "'"};
}});
diff --git a/src/core/BrushAlpha.h b/src/core/BrushAlpha.h
index 92ce805a..9c303880 100644
--- a/src/core/BrushAlpha.h
+++ b/src/core/BrushAlpha.h
@@ -14,7 +14,9 @@ class CommandRegistry;
// Grayscale stamp that shapes a brush's falloff (ZBrush "alpha"). An empty
// alpha is the plain round smoothstep falloff, so brushes behave exactly as
-// without one. Built-ins: Round (empty), Square, Noise; anything else comes
+// without one. Built-ins: Round (empty), Square, Noise and twelve patterns made
+// in code (Pores, Cracks, Scales, Rivets, Stitches, Fabric Weave, Bark, Rock
+// Strata, Wrinkles, Skin Folds, Hair Strands, Dot Grid; #43); anything else comes
// from an image's luminance (transparent pixels count as black).
struct BrushAlpha {
std::string name = "Round";
@@ -28,8 +30,13 @@ struct BrushAlpha {
static BrushAlpha round();
static BrushAlpha square();
static BrushAlpha noise(uint32_t seed = 1);
- // Case-insensitive "round"/"none", "square" or "noise"; false for unknown names.
+ // Every built-in in the pickers' order (Round, Square, Noise, then the patterns), generated on first use.
+ static const std::vector<BrushAlpha>& builtins();
+ // A built-in by name, ignoring case, spaces, '_' and '-' ("none" = Round); false for unknown names.
static bool builtin(const std::string& name, BrushAlpha& out);
+ // One line on what a built-in is for (empty for unknown names), and all their names for messages.
+ static std::string builtinHelp(const std::string& name);
+ static std::string builtinNames();
// Luminance x alpha, downscaled to at most 512 px; `invert` swaps black and white.
static BrushAlpha fromImage(const Image& image, std::string name, bool invert = false);
};
diff --git a/src/core/Vdm.cpp b/src/core/Vdm.cpp
index 33fa940b..ae1a8674 100644
--- a/src/core/Vdm.cpp
+++ b/src/core/Vdm.cpp
@@ -422,6 +422,116 @@ VectorDisplacement makeNostrilVdm(int size) {
});
}
+namespace {
+
+// 1 inside the stamp, 0 from 0.95 radii out: the generated maps below leave the square's rim where it was.
+float rimFade(float x, float y) { return 1.0f - smooth01((std::sqrt(x * x + y * y) - 0.55f) / 0.4f); }
+
+// Distance from p to the segment a-b, and the closest point on it.
+float toSegment(glm::vec2 p, glm::vec2 a, glm::vec2 b, glm::vec2& closest) {
+ const glm::vec2 v = b - a;
+ const float t = std::clamp(glm::dot(p - a, v) / std::max(glm::dot(v, v), 1e-12f), 0.0f, 1.0f);
+ closest = a + v * t;
+ return glm::length(p - closest);
+}
+
+// A smooth, repeatable wiggle (sums of sines) for crack and wrinkle lines.
+float wiggle(float t, float seed) {
+ return 0.6f * std::sin(t * 3.1f + seed) + 0.3f * std::sin(t * 7.3f + seed * 2.1f) + 0.1f * std::sin(t * 17.0f + seed);
+}
+
+} // namespace
+
+VectorDisplacement makeRivetVdm(int size) {
+ // A domed head on a short neck, its rim bulging out over the plate a little.
+ return generate("Rivet", size, [](float x, float y) {
+ const float rho = std::sqrt(x * x + y * y), r = 0.42f;
+ if (rho >= r + 0.2f) return glm::vec3(x, y, 0.0f);
+ const glm::vec2 radial = rho > 1e-6f ? glm::vec2(x, y) / rho : glm::vec2(0.0f);
+ if (rho < r) {
+ const float s = rho / r;
+ const float z = 0.06f + 0.24f * std::sqrt(std::max(0.0f, 1.0f - s * s)); // head on a 0.06 neck
+ const float out = 0.07f * smooth01((s - 0.55f) / 0.45f); // the rim overhangs
+ return glm::vec3(glm::vec2(x, y) + radial * out, z);
+ }
+ // The neck: from under the rim down to the plate.
+ const float t = (rho - r) / 0.2f;
+ const float z = 0.06f * (1.0f - smooth01(t));
+ const float in = -0.04f * (1.0f - t) * (1.0f - smooth01(t));
+ return glm::vec3(glm::vec2(x, y) + radial * in, z);
+ });
+}
+
+VectorDisplacement makeStitchesVdm(int size) {
+ // Three raised thread bars across a seam (drag along the seam: the stamp's Y); the threads draw the two sides
+ // of the seam together, so the skin bunches toward it.
+ return generate("Stitches", size, [](float x, float y) {
+ const float fade = rimFade(x, y);
+ float z = -0.06f * (1.0f - smooth01(std::abs(x) / 0.08f)); // the seam line itself
+ for (int k = -1; k <= 1; ++k) {
+ const float cy = float(k) * 0.33f;
+ glm::vec2 c;
+ const float d = toSegment(glm::vec2(x, y), glm::vec2(-0.32f, cy - 0.08f), glm::vec2(0.32f, cy + 0.08f), c);
+ z = std::max(z, 0.11f * std::sqrt(std::max(0.0f, 1.0f - smooth01(d / 0.07f))));
+ }
+ const float gather = -0.1f * std::tanh(x / 0.12f) * std::exp(-x * x / 0.12f);
+ return glm::vec3(x + gather * fade, y, z * fade);
+ });
+}
+
+VectorDisplacement makeSkinFoldVdm(int size) {
+ // A heavy roll of skin hanging over a crease (the stamp's bottom, -Y), as over an eyelid or a belly.
+ return generate("Skin Fold", size, [](float x, float y) {
+ const float crease = -0.15f + 0.25f * x * x;
+ const float d = y - crease; // above the crease > 0
+ const float fade = rimFade(x, y);
+ const float roll = d > 0.0f ? std::exp(-d * d / 0.08f) : std::exp(-d * d / 0.004f);
+ const float z = 0.22f * roll - 0.06f * std::exp(-d * d / 0.003f); // a deep line where it folds under
+ const float hang = d > 0.0f ? -0.16f * std::exp(-d * d / 0.03f) : 0.0f; // slides down over the crease
+ return glm::vec3(x, y + hang * fade, z * fade);
+ });
+}
+
+VectorDisplacement makeWrinkleVdm(int size) {
+ // A fine crease: skin pinched in from both sides and pressed down along a slightly wavy line (along X).
+ return generate("Wrinkle Line", size, [](float x, float y) {
+ const float line = 0.06f * wiggle(x * 1.2f, 0.7f);
+ const float d = y - line;
+ const float along = smooth01((0.8f - std::abs(x)) / 0.35f); // tapered ends
+ const float fade = rimFade(x, y) * along;
+ const float pinch = -0.12f * std::tanh(d / 0.06f) * std::exp(-d * d / 0.05f);
+ const float z = -0.18f * std::exp(-d * d / 0.002f) + 0.04f * std::exp(-d * d / 0.03f);
+ return glm::vec3(x, y + pinch * fade, z * fade);
+ });
+}
+
+VectorDisplacement makeCrackVdm(int size) {
+ // A jagged crack (along Y) whose sides split apart and break downward into it.
+ return generate("Crack", size, [](float x, float y) {
+ const float line = 0.12f * wiggle(y * 1.6f, 2.3f);
+ const float d = x - line;
+ const float along = smooth01((0.85f - std::abs(y)) / 0.3f);
+ const float fade = rimFade(x, y) * along;
+ const float width = 0.03f + 0.03f * (0.5f + 0.5f * std::sin(y * 9.0f));
+ const float split = 0.09f * std::tanh(d / width) * std::exp(-d * d / 0.04f); // the sides move apart
+ const float z = -0.28f * std::exp(-d * d / (width * width)) + 0.02f * std::exp(-d * d / 0.02f);
+ return glm::vec3(x + split * fade, y, z * fade);
+ });
+}
+
+VectorDisplacement makeRockLedgeVdm(int size) {
+ // A stepped shelf of rock strata whose upper layer juts out over the one below (toward -Y): an overhang.
+ return generate("Rock Ledge", size, [](float x, float y) {
+ const float fade = rimFade(x, y);
+ const float edge = -0.05f + 0.05f * wiggle(x * 2.0f, 4.1f);
+ const float t = smooth01((y - edge) / 0.18f); // 0 below the ledge, 1 on top
+ const float lip = std::exp(-(y - edge - 0.1f) * (y - edge - 0.1f) / 0.01f);
+ const float z = 0.2f * t + 0.03f * wiggle(x * 4.0f + y * 3.0f, 1.3f) * t;
+ const float jut = -0.14f * lip; // the lip pushed out over the lower layer
+ return glm::vec3(x, y + jut * fade, z * fade);
+ });
+}
+
const std::vector<std::shared_ptr<const VectorDisplacement>>& builtinVdms() {
static const std::vector<std::shared_ptr<const VectorDisplacement>> all = [] {
std::vector<std::shared_ptr<const VectorDisplacement>> v;
@@ -429,6 +539,13 @@ const std::vector<std::shared_ptr<const VectorDisplacement>>& builtinVdms() {
v.push_back(std::make_shared<const VectorDisplacement>(makeEarCurlVdm()));
v.push_back(std::make_shared<const VectorDisplacement>(makeScalesVdm()));
v.push_back(std::make_shared<const VectorDisplacement>(makeNostrilVdm()));
+ // #43: six more, made here in code like the four above (no files).
+ v.push_back(std::make_shared<const VectorDisplacement>(makeRivetVdm()));
+ v.push_back(std::make_shared<const VectorDisplacement>(makeStitchesVdm()));
+ v.push_back(std::make_shared<const VectorDisplacement>(makeSkinFoldVdm()));
+ v.push_back(std::make_shared<const VectorDisplacement>(makeWrinkleVdm()));
+ v.push_back(std::make_shared<const VectorDisplacement>(makeCrackVdm()));
+ v.push_back(std::make_shared<const VectorDisplacement>(makeRockLedgeVdm()));
return v;
}();
return all;
diff --git a/src/core/Vdm.h b/src/core/Vdm.h
index e6cac9cb..0e3e8446 100644
--- a/src/core/Vdm.h
+++ b/src/core/Vdm.h
@@ -71,15 +71,22 @@ bool writeVdmFile(const std::string& path, const VectorDisplacement& vdm, std::s
bool loadVdm(const std::string& path, VectorDisplacement& out, std::string& error, const VdmImportOptions& opt = {});
bool isVdmFile(const std::string& path);
-// --- Built-ins (procedural, CC0): Horn, Ear Curl, Scales, Nostril ---
+// --- Built-ins (procedural, made in code; CC0): Horn, Ear Curl, Scales, Nostril, Rivet, Stitches, Skin Fold,
+// Wrinkle Line, Crack, Rock Ledge ---
const std::vector<std::shared_ptr<const VectorDisplacement>>& builtinVdms();
std::shared_ptr<const VectorDisplacement> builtinVdm(const std::string& name); // case-insensitive; null if unknown
-// The four generators (exposed for tests; `size` texels a side).
+// The generators (exposed for tests; `size` texels a side).
VectorDisplacement makeHornVdm(int size = 256);
VectorDisplacement makeEarCurlVdm(int size = 256);
VectorDisplacement makeScalesVdm(int size = 256);
VectorDisplacement makeNostrilVdm(int size = 256);
+VectorDisplacement makeRivetVdm(int size = 256);
+VectorDisplacement makeStitchesVdm(int size = 256);
+VectorDisplacement makeSkinFoldVdm(int size = 256);
+VectorDisplacement makeWrinkleVdm(int size = 256);
+VectorDisplacement makeCrackVdm(int size = 256);
+VectorDisplacement makeRockLedgeVdm(int size = 256);
// --- Create VDM from a plane (ZBrush: Brush > Create > from the VDM plane; Blender: VDM Brush Baker) ---
diff --git a/tests/test_brushes.cpp b/tests/test_brushes.cpp
index 3ea24aa7..268e0a88 100644
--- a/tests/test_brushes.cpp
+++ b/tests/test_brushes.cpp
@@ -470,3 +470,46 @@ TEST(spray_and_spacing_are_deterministic) {
CHECK(pts.size() == 1 && std::abs(pts[0].x - 110.0f) < 1e-3f);
CHECK(std::string(strokeTypeName(StrokeType::LazyMouse)) == "LazyMouse");
}
+
+TEST(alpha_generated_builtins) {
+ // #43: twelve patterns made in code (no image files), after Round, Square and Noise.
+ const auto& all = BrushAlpha::builtins();
+ CHECK(all.size() == 15);
+ CHECK(all[0].empty() && all[0].name == "Round" && all[1].name == "Square" && all[2].name == "Noise");
+ for (size_t i = 3; i < all.size(); ++i) {
+ const BrushAlpha& a = all[i];
+ CHECK(a.width == 128 && a.height == 128 && a.values.size() == 128u * 128u);
+ float lo = 1.0f, hi = 0.0f, border = 0.0f;
+ double sum = 0.0;
+ for (int y = 0; y < a.height; ++y)
+ for (int x = 0; x < a.width; ++x) {
+ const float v = a.values[size_t(y) * size_t(a.width) + size_t(x)];
+ lo = std::min(lo, v);
+ hi = std::max(hi, v);
+ sum += v;
+ if (x == 0 || y == 0 || x == a.width - 1 || y == a.height - 1) border = std::max(border, v);
+ }
+ const double mean = sum / double(a.values.size());
+ CHECK(lo >= 0.0f && hi <= 1.0f && hi > 0.5f); // a real stamp, in range
+ CHECK(mean > 0.02 && mean < 0.8); // a pattern, not a blank or a flat plateau
+ CHECK(border < 0.05f); // fades out at the edge, so dabs leave no square
+ if (border >= 0.05f || mean <= 0.02 || mean >= 0.8)
+ std::printf(" %s: mean %.3f border %.3f\n", a.name.c_str(), mean, double(border));
+ CHECK(!BrushAlpha::builtinHelp(a.name).empty());
+ BrushAlpha byName;
+ CHECK(BrushAlpha::builtin(a.name, byName) && byName.values == a.values);
+ for (size_t j = 3; j < i; ++j) CHECK(all[j].values != a.values); // all different
+ }
+ // Names work in any case, with spaces, '_' or '-'.
+ BrushAlpha out;
+ CHECK(BrushAlpha::builtin("fabric_weave", out) && out.name == "Fabric Weave");
+ CHECK(BrushAlpha::builtin("ROCK-STRATA", out) && out.name == "Rock Strata");
+ CHECK(BrushAlpha::builtin("skinfolds", out) && out.name == "Skin Folds");
+ // And through the command.
+ Document d = planeDoc();
+ CommandRegistry reg;
+ CHECK(reg.execute(d, "brush_set_alpha", {{"name", std::string("hair strands")}}).ok);
+ CHECK(d.brushAlpha.name == "Hair Strands");
+ CommandResult bad = reg.execute(d, "brush_set_alpha", {{"name", std::string("star")}});
+ CHECK(!bad.ok && bad.message.find("cracks") != std::string::npos);
+}
diff --git a/tests/test_vdm.cpp b/tests/test_vdm.cpp
index 5a4475f3..df134254 100644
--- a/tests/test_vdm.cpp
+++ b/tests/test_vdm.cpp
@@ -83,7 +83,7 @@ struct VdmLibrary {
TEST(vdm_builtins_are_bounded_and_overhang) {
const auto& all = builtinVdms();
- CHECK(all.size() == 4);
+ CHECK(all.size() == 10); // Horn, Ear Curl, Scales, Nostril and the six from #43
for (const auto& v : all) {
CHECK(v->builtin && v->width == 256 && v->height == 256);
CHECK(v->extent() > 0.1f && v->extent() < 2.0f);
@@ -99,6 +99,8 @@ TEST(vdm_builtins_are_bounded_and_overhang) {
float lateral = 0.0f;
for (const glm::vec3& d : v->vectors) lateral = std::max(lateral, std::hypot(d.x, d.y));
CHECK(lateral > 0.06f);
+ if (lateral <= 0.06f || v->extent() <= 0.1f || border >= 1e-4f)
+ std::printf(" %s: lateral %.3f extent %.3f border %g\n", v->name.c_str(), lateral, v->extent(), border);
CHECK(builtinVdm(v->name) == v);
}
// The horn's tip leans over past its base toward the map's top (+Y): an overhang.
@@ -345,7 +347,7 @@ TEST(vdm_library_commands) {
{ std::ofstream(lib.root / "user" / "broken.sfvdm", std::ios::binary) << "nope"; }
const auto messages = loadBrushLibrary(d, lib.paths());
CHECK(messages.size() == 1); // broken.sfvdm
- CHECK(d.vdms.size() == 5 && findVdm(d, "studio lump") == 4);
+ CHECK(d.vdms.size() == builtinVdms().size() + 1 && findVdm(d, "studio lump") == int(builtinVdms().size()));
fs::remove(lib.root / "user" / "broken.sfvdm");
CHECK(run(d, "vdm_new_plane", {{"resolution", 64.0}}));
diff --git a/tests/ui/builtin_presets.sfui b/tests/ui/builtin_presets.sfui
new file mode 100644
index 00000000..349c3bd6
--- /dev/null
+++ b/tests/ui/builtin_presets.sfui
@@ -0,0 +1,51 @@
+# #43: twelve more built-in alphas and six more VDM brushes, made in code at first use, with thumbnails in the
+# LightBox (Alpha and Brush tabs) and in the Alpha picker; a double-click uses one.
+run new_sphere subdivisions=5
+key ,
+expect_value lightbox_open == 1
+click "LightBox/Alpha"
+expect "LightBox/Round"
+expect "LightBox/Pores"
+expect "LightBox/Cracks"
+expect "LightBox/Fabric Weave"
+wait_idle 60
+shot lightbox_alphas
+# The rest are further along the strip; the filter finds them.
+type "LightBox/##lbfilter" hair
+expect "LightBox/Hair Strands"
+expect_not "LightBox/Round"
+type "LightBox/##lbfilter" fold
+expect "LightBox/Skin Folds"
+type "LightBox/##lbfilter" weave
+expect "LightBox/Fabric Weave"
+type "LightBox/##lbfilter" bark
+expect "LightBox/Bark"
+type "LightBox/##lbfilter" grid
+expect "LightBox/Dot Grid"
+wait_idle 60
+shot lightbox_alphas_filtered
+type "LightBox/##lbfilter" crack
+double_click "LightBox/Cracks"
+expect_status Alpha 'Cracks'
+snapshot
+stroke 0.3 0.5 0.7 0.5
+expect_value moved > 100
+
+# The VDM brushes, built-in ones included, in the Brush tab.
+click "LightBox/Brush"
+type "LightBox/##lbfilter" horn
+expect "LightBox/Horn"
+type "LightBox/##lbfilter" ledge
+expect "LightBox/Rock Ledge"
+type "LightBox/##lbfilter" line
+expect "LightBox/Wrinkle Line"
+wait_idle 60
+shot lightbox_vdms
+type "LightBox/##lbfilter" fold
+expect "LightBox/Skin Fold"
+type "LightBox/##lbfilter" rivet
+double_click "LightBox/Rivet"
+expect_status VDM 'Rivet'
+expect_value brush_type == 14
+key ,
+expect_value lightbox_open == 0
diff --git a/tests/ui/vdm.sfui b/tests/ui/vdm.sfui
index f881d815..7e6db41a 100644
--- a/tests/ui/vdm.sfui
+++ b/tests/ui/vdm.sfui
@@ -2,7 +2,7 @@
# sets size and turn) and DragDot, Alt digs in, undo; the stroke comes back with the next brush; then sculpt a VDM
# plane, Create VDM (saved to the library) and stamp the new brush on the sphere.
expect_value vdm_files == 0
-expect_value vdms == 4
+expect_value vdms == 10
run new_sphere subdivisions=6
click "Brush##palette.brush"
click "Brush/##totray"
@@ -97,9 +97,9 @@ shot vdm-plane
click "Create VDM##vdm.create"
expect_status Created VDM 'Bump Spike'
expect_value vdm_files == 1
-expect_value vdms == 5
+expect_value vdms == 11
expect_value brush_type == 14
-expect "Bump Spike##vdm4"
+expect "Bump Spike##vdm10"
wait_idle 30
shot created