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.

Viewport round 2: Soft Clay that reads strokes, one icon per brush, default material first

islandmedbff1aae99eee
diff --git a/docs/ui-design.md b/docs/ui-design.md
index c70117db..b72dfff4 100644
--- a/docs/ui-design.md
+++ b/docs/ui-design.md
@@ -308,9 +308,9 @@ Each tab shows a "Built-in" and a "User" folder at its root, as ZBrush shows Max
- **Meshes and projects**: rendered offscreen. Use `Renderer::renderToImage`, or a new `Renderer::renderMeshThumbnail(const Mesh&, matcap, size, rgba&)` if `renderToImage` is tied to the synced scene. Size 192x192 (displayed at 96, crisp on HiDPI), the default material (Soft Clay), transparent background, camera framed on the bounds from a 3/4 front view (yaw 30, pitch 15).
- Mesh loading uses the existing importers on a worker thread. GL rendering happens on the main thread, **at most 2 thumbnails per frame**.
- Projects: `saveProject` also writes `thumbnail.png` (256x256, current camera) into the `.sfproj` ZIP. The LightBox reads that instead of loading the whole project. Older projects without it are loaded on the worker and rendered once.
-- **Brushes**: on a worker, sculpt one S-curve stroke (or a ridge crossed by the brush, for Smooth/Flatten/Trim/Nudge) on the front of a fresh clay ball (icosphere sdiv 6) using the same `Sculptor`/recipe code as real strokes. Every brush, Paint included, is the same ball, camera and material (Soft Clay), so the shelf reads as one icon set. Key = brush type or recipe JSON hash plus `kThumbnailVersion` (bump it whenever thumbnails are made differently, so stale disk-cached ones are remade).
-- **Alphas**: the alpha's grayscale samples straight into a texture.
-- **Materials**: a sphere rendered with that matcap.
+- **Brushes**: on a worker, sculpt a mark of each brush's own shape on the front of a fresh clay ball (icosphere sdiv 6) using the same `Sculptor`/recipe code as real strokes, so brushes tell apart at shelf size: Standard an S, Clay three strips, ClayBuildup a hash of bars, DamStandard a diagonal cut, Crease a curved groove, Inflate a puffed ring, Pinch a sharp chevron, Smooth a bumpy ridge smoothed on one half, Flatten a planed dome, Trim a cut-down ridge, Layer a raised square frame, Nudge an upright ridge slid sideways, Move and SnakeHook pulls at the silhouette, recipes an S. The ball fills 97% of the tile. Every brush, Paint included, is the same ball, camera and material (Soft Clay), so the shelf reads as one icon set. Key = brush type or recipe JSON hash plus `kThumbnailVersion` (bump it whenever thumbnails are made differently, so stale disk-cached ones are remade).
+- **Alphas**: the alpha's samples, from the tile's charcoal (none) to the clay's lit grey (full effect), not white on black.
+- **Materials**: the same ball as the brushes, rendered with that matcap. Pickers list the default (Soft Clay) first (`matcapInListOrder`), then the others, then Studio.
- **Images**: stb-decoded, downscaled to 192.
- **Disk cache**: `<prefDir>/thumbs/<fnv1a64(kind|absPath|size|mtime|version)>.png` (stb_image_write is in third_party). In-memory LRU of 256 GL textures.
- **Placeholder**: while a thumbnail is pending, the tile shows the Lucide glyph for its kind (`box`, `brush`, `circle-dashed`, `palette`, `image`, `sparkles`, `folder`) on `#2a2a2e`.
@@ -492,7 +492,7 @@ Keep the existing orange accent, but only for **one thing per group**: the curre
| `text` / `textDim` | `#d8d8d8` / `#8c8c90` | |
| `border` | `#111113` | 1 px between regions |
| `danger` | `#e5604a` | errors |
-| canvas | neutral charcoal, soft radial vignette (`kBgFS`); 1 px `#0e0e10` frame; default material Soft Clay (matte warm grey) | |
+| canvas | neutral charcoal, soft radial vignette (`kBgFS`); 1 px `#0e0e10` frame; vignette down to `shellBg` at the edges (no step at the seams); default material Soft Clay (matte warm grey: a steep upper-left key, a fill from the right, a warm ground bounce, a broad sheen along ridges and a cool rim on the lower right; light cavity, only above a smooth sphere's own curvature) | |
Style:
- Rounding: `WindowRounding 0` (shells), `PopupRounding 6`, `FrameRounding 3`, `GrabRounding 2`.
diff --git a/src/app/AssetLibrary.h b/src/app/AssetLibrary.h
index 2aeb4133..bc2c3e96 100644
--- a/src/app/AssetLibrary.h
+++ b/src/app/AssetLibrary.h
@@ -112,7 +112,7 @@ private:
// --- Thumbnail cache keys (spec: fnv1a64(kind|absPath|size|mtime|version)) ---
-constexpr int kThumbnailVersion = 2; // bump when thumbnails are rendered differently
+constexpr int kThumbnailVersion = 3; // bump when thumbnails are rendered differently
uint64_t fnv1a64(std::string_view data, uint64_t seed = 0xcbf29ce484222325ull);
std::string hex64(uint64_t v); // 16 lower-case hex digits
// Key of a file's thumbnail: changes when the file is rewritten (size or time) or the renderer changes.
diff --git a/src/app/LightBox.cpp b/src/app/LightBox.cpp
index 863dacb6..e3e95d4c 100644
--- a/src/app/LightBox.cpp
+++ b/src/app/LightBox.cpp
@@ -241,8 +241,8 @@ void LightBox::rootEntries(App& app, std::vector<AssetEntry>& out) {
break;
}
case LibraryTab::Material:
- for (int k = 0; k <= matcapCount(); ++k) { // the MatCaps (Sculpt first), then Studio
- const int i = k < matcapCount() ? k : -1;
+ for (int k = 0; k <= matcapCount(); ++k) { // the MatCaps (the default first), then Studio
+ const int i = k < matcapCount() ? matcapInListOrder(k) : -1;
AssetEntry e;
e.kind = AssetKind::Material;
e.index = i;
diff --git a/src/app/Pickers.cpp b/src/app/Pickers.cpp
index 215bc447..8bf1ef72 100644
--- a/src/app/Pickers.cpp
+++ b/src/app/Pickers.cpp
@@ -137,9 +137,23 @@ void quickInfo(ImTextureID tex, const char* glyph, const std::string& title, con
if (!ImGui::IsItemHovered(ImGuiHoveredFlags_DelayShort | ImGuiHoveredFlags_NoSharedDelay) ||
ImGui::IsPopupOpen(nullptr, ImGuiPopupFlags_AnyPopupId) || ImGui::GetIO().KeyCtrl)
return;
+ // Beside the window the tile is in (right of it, else left), level with the tile: at the mouse it covered
+ // the grid it describes, clipping the labels and the next rows.
+ const float big = 192.0f * 0.75f;
+ {
+ constexpr float kCardW = 356.0f, kCardH = 300.0f, kGap = 6.0f; // the card's largest size, with padding
+ const ImGuiWindow* host = ImGui::GetCurrentWindow()->RootWindow;
+ const ImGuiViewport* vp = ImGui::GetMainViewport();
+ ImVec2 pos(host->Pos.x + host->Size.x + kGap, ImGui::GetItemRectMin().y), pivot(0.0f, 0.0f);
+ if (pos.x + kCardW > vp->Pos.x + vp->Size.x && host->Pos.x - kGap - kCardW >= vp->Pos.x) {
+ pos.x = host->Pos.x - kGap;
+ pivot.x = 1.0f;
+ }
+ pos.y = std::clamp(pos.y, vp->Pos.y + 4.0f, std::max(vp->Pos.y + 4.0f, vp->Pos.y + vp->Size.y - kCardH));
+ ImGui::SetNextWindowPos(pos, ImGuiCond_Always, pivot);
+ }
ImGui::SetNextWindowSizeConstraints(ImVec2(0, 0), ImVec2(340, FLT_MAX));
ImGui::BeginTooltip();
- const float big = 192.0f * 0.75f;
if (tex)
ImGui::Image(tex, ImVec2(big, big));
else if (glyph) {
@@ -862,7 +876,7 @@ void drawMaterialGrid(App& app, GridMode mode) {
int hovered = -2;
const int active = s.previewing ? s.savedMatcap : app.renderSettings_.matcap;
for (int k = 0; k <= matcapCount(); ++k) {
- const int i = k < matcapCount() ? k : -1; // the MatCaps (Sculpt first), then Studio
+ const int i = k < matcapCount() ? matcapInListOrder(k) : -1; // the MatCaps (the default first), then Studio
tileGrid(column, columns);
const char* name = i < 0 ? "Studio" : matcapName(i);
const ImTextureID tex = app.thumbs_.material(i);
@@ -874,9 +888,11 @@ void drawMaterialGrid(App& app, GridMode mode) {
}
if (ImGui::IsItemHovered()) hovered = i;
ui::HelpText(name, nullptr,
- i < 0 ? "Soft studio lighting with cavity shading, in the Base colour."
- : i == 0 ? "Made for sculpting (the default): a strong key light, crisp highlights and deep "
- "cavities so every stroke reads."
+ i < 0 ? "Soft studio lighting with cavity shading, in the Base colour."
+ : i == defaultMatcap() ? "The default: a matte warm clay with a clear key light and a soft "
+ "rim, so strokes read without glare."
+ : i == 0 ? "Made for sculpting: a strong key light, crisp highlights and deep cavities so "
+ "every stroke reads."
: "MatCap material: the whole lit look in one image.",
"Material");
}
diff --git a/src/app/Thumbnails.cpp b/src/app/Thumbnails.cpp
index b34ab7a7..e89fdf18 100644
--- a/src/app/Thumbnails.cpp
+++ b/src/app/Thumbnails.cpp
@@ -29,6 +29,9 @@ namespace {
constexpr size_t kMaxJobs = 3; // worker threads at a time
constexpr int kRendersPerFrame = 2; // GL renders per frame
constexpr double kStatSeconds = 2.0; // how long a file's size / time stamp is trusted
+// Alpha previews: the colour of no effect (the tile's charcoal) and of full effect (Soft Clay's lit grey), sRGB.
+constexpr float kAlphaNone[3] = {30.0f, 30.0f, 33.0f};
+constexpr float kAlphaFull[3] = {214.0f, 208.0f, 198.0f};
std::filesystem::path fsPath(const std::string& p) { return std::filesystem::path(std::u8string(p.begin(), p.end())); }
@@ -72,7 +75,7 @@ std::unique_ptr<Mesh> sceneMesh(Document& doc) {
constexpr float kBallRadius = 0.9f;
constexpr int kBallDetail = 6; // ~82k triangles: fine enough for crisp strokes at preview size
constexpr float kBallPitch = -8.0f; // degrees; a touch from above
-constexpr float kBallFill = 0.84f; // the ball's share of the tile's height
+constexpr float kBallFill = 0.97f; // the ball's share of the tile's height: framed tight, so the mark reads at shelf size
// Brush previews: the camera distance at which the ball fills kBallFill of the tile.
float ballDistance() {
@@ -90,6 +93,15 @@ std::vector<glm::vec3> frontCurve(float width = 1.0f) {
return pts;
}
std::vector<glm::vec3> line(glm::vec3 a, glm::vec3 b) { return {a, b}; }
+// Points on a circle of radius `r` around (cx, cy) on the front of the ball, from angle a0 to a1 (radians).
+std::vector<glm::vec3> arc(float cx, float cy, float r, float a0, float a1, int n = 24) {
+ std::vector<glm::vec3> pts;
+ for (int i = 0; i <= n; ++i) {
+ const float a = a0 + (a1 - a0) * float(i) / float(n);
+ pts.emplace_back(cx + r * std::cos(a), cy + r * std::sin(a), 2.0f);
+ }
+ return pts;
+}
void stroke(Document& d, const BrushRecipe* recipe, BrushType type, std::vector<glm::vec3> pts, float radius,
float strength, bool curve = true) {
@@ -128,49 +140,85 @@ std::unique_ptr<Mesh> sculptBrushPreview(const BrushRecipe* recipe, int type) {
stroke(d, recipe, BrushType::Standard, frontCurve(), r, 0.9f);
return sceneMesh(d);
}
+ // Each brush gets a mark of its own shape that shows what it does, so the shelf tells them apart at a glance
+ // (the same S everywhere left only a few pixels of difference between Standard, Clay, Inflate and Pinch).
+ constexpr float kPi = 3.14159265f;
const auto bt = BrushType(type);
switch (bt) {
- case BrushType::Move:
- stroke(d, nullptr, bt, line({-0.1f, -0.1f, 2.0f}, {0.45f, 0.38f, 2.0f}), 0.45f, 1.0f, false);
+ case BrushType::Clay: // three parallel strips laid on like clay
+ for (int i = -1; i <= 1; ++i) {
+ const float dx = 0.3f * float(i);
+ stroke(d, nullptr, bt, line({dx - 0.28f, -0.42f, 2.0f}, {dx + 0.12f, 0.42f, 2.0f}), 0.15f, 1.0f, false);
+ }
+ break;
+ case BrushType::ClayBuildup: // a hash of square, flat-topped bars, built up in two directions
+ for (float o : {-0.2f, 0.2f}) {
+ stroke(d, nullptr, bt, line({-0.5f, o, 2.0f}, {0.5f, o, 2.0f}), 0.13f, 0.1f, false);
+ stroke(d, nullptr, bt, line({o, -0.5f, 2.0f}, {o, 0.5f, 2.0f}), 0.13f, 0.1f, false);
+ }
+ break;
+ case BrushType::DamStandard: // one deep, sharp diagonal cut
+ stroke(d, nullptr, bt, line({-0.55f, 0.45f, 2.0f}, {0.55f, -0.45f, 2.0f}), 0.2f, 1.0f, false);
+ stroke(d, nullptr, bt, line({-0.55f, 0.45f, 2.0f}, {0.55f, -0.45f, 2.0f}), 0.2f, 1.0f, false);
+ break;
+ case BrushType::Crease: // a curved groove, like a smile line
+ stroke(d, nullptr, bt, arc(0.0f, 0.42f, 0.62f, kPi * 1.18f, kPi * 1.82f), 0.17f, 1.0f);
+ stroke(d, nullptr, bt, arc(0.0f, 0.42f, 0.62f, kPi * 1.18f, kPi * 1.82f), 0.17f, 1.0f);
+ break;
+ case BrushType::Move: // the silhouette pulled out into a broad soft lobe on the upper left
+ stroke(d, nullptr, bt, line({-0.5f, 0.45f, 2.0f}, {-0.78f, 0.72f, 2.0f}), 0.5f, 1.0f, false);
break;
case BrushType::SnakeHook:
// SnakeHook pulls out along the stroke; the path heads out past the silhouette to the side.
- stroke(d, nullptr, bt, line({0.2f, 0.12f, 2.0f}, {0.72f, 0.4f, 2.0f}), 0.24f, 1.0f, false);
+ stroke(d, nullptr, bt, line({0.15f, 0.05f, 2.0f}, {0.95f, 0.5f, 2.0f}), 0.26f, 1.0f, false);
+ break;
+ case BrushType::Inflate: // a ring, puffed up
+ stroke(d, nullptr, bt, arc(0.0f, 0.0f, 0.38f, 0.0f, 2.0f * kPi, 32), 0.2f, 1.0f);
break;
- case BrushType::Inflate:
- stroke(d, nullptr, bt, frontCurve(), 0.2f, 0.8f);
+ case BrushType::Pinch: // a raised chevron pinched to a sharp crest
+ stroke(d, nullptr, BrushType::Standard, {{-0.5f, 0.35f, 2.0f}, {0.0f, -0.3f, 2.0f}, {0.5f, 0.35f, 2.0f}}, 0.22f, 1.0f, false);
+ for (int pass = 0; pass < 2; ++pass)
+ stroke(d, nullptr, bt, {{-0.5f, 0.35f, 2.0f}, {0.0f, -0.3f, 2.0f}, {0.5f, 0.35f, 2.0f}}, 0.22f, 1.0f, false);
break;
- case BrushType::Smooth:
- case BrushType::Flatten:
- case BrushType::Trim:
- case BrushType::Nudge: {
- // These change existing form: raise a ridge first, then cross it with the brush.
- const auto ridge = line({-0.75f, 0.0f, 2.0f}, {0.75f, 0.0f, 2.0f});
- stroke(d, nullptr, BrushType::Standard, ridge, 0.22f, 1.0f, false);
- stroke(d, nullptr, BrushType::Clay, ridge, 0.22f, 1.0f, false);
- const auto across = bt == BrushType::Nudge ? line({-0.12f, -0.3f, 2.0f}, {0.12f, 0.3f, 2.0f})
- : line({0.0f, -0.65f, 2.0f}, {0.0f, 0.65f, 2.0f});
- const float strength = bt == BrushType::Nudge ? 0.05f : bt == BrushType::Trim ? 0.5f : 1.0f;
- const int passes = bt == BrushType::Smooth ? 3 : 1;
- for (int pass = 0; pass < passes; ++pass)
- stroke(d, nullptr, bt, across, bt == BrushType::Nudge ? 0.22f : 0.2f, strength, false);
+ case BrushType::Smooth: { // a bumpy ridge, its right half smoothed away
+ for (int i = 0; i < 7; ++i)
+ for (int pass = 0; pass < 4; ++pass)
+ stroke(d, nullptr, BrushType::Standard, {glm::vec3(-0.6f + 0.2f * float(i), 0.0f, 2.0f)}, 0.13f, 1.0f, false);
+ for (int pass = 0; pass < 3; ++pass)
+ stroke(d, nullptr, bt, line({0.12f, 0.0f, 2.0f}, {0.8f, 0.0f, 2.0f}), 0.26f, 1.0f, false);
break;
}
- case BrushType::Pinch:
- stroke(d, nullptr, BrushType::Standard, frontCurve(), r * 1.2f, 0.9f);
- stroke(d, nullptr, bt, frontCurve(), r * 1.2f, 1.0f);
+ case BrushType::Flatten: // a dome with a flat facet planed across its top
+ for (int pass = 0; pass < 3; ++pass)
+ stroke(d, nullptr, BrushType::Standard, {glm::vec3(0.0f, 0.0f, 2.0f)}, 0.5f, 1.0f, false);
+ for (int pass = 0; pass < 3; ++pass)
+ stroke(d, nullptr, bt, line({-0.15f, 0.05f, 2.0f}, {0.15f, -0.05f, 2.0f}), 0.32f, 1.0f, false);
break;
- case BrushType::ClayBuildup:
- stroke(d, nullptr, bt, frontCurve(), r, 0.12f);
+ case BrushType::Trim: { // a ridge cut down to hard planes along its length
+ const auto ridge = line({-0.6f, -0.35f, 2.0f}, {0.6f, 0.35f, 2.0f});
+ stroke(d, nullptr, BrushType::Standard, ridge, 0.24f, 1.0f, false);
+ stroke(d, nullptr, BrushType::Clay, ridge, 0.24f, 1.0f, false);
+ stroke(d, nullptr, bt, line({-0.3f, -0.17f, 2.0f}, {0.3f, 0.17f, 2.0f}), 0.24f, 1.0f, false);
break;
- case BrushType::Layer:
- stroke(d, nullptr, bt, frontCurve(), 0.38f, 1.0f); // its height scales with the radius
+ }
+ case BrushType::Nudge: { // an upright ridge slid sideways in the middle
+ const auto ridge = line({0.0f, -0.6f, 2.0f}, {0.0f, 0.6f, 2.0f});
+ stroke(d, nullptr, BrushType::Standard, ridge, 0.2f, 1.0f, false);
+ stroke(d, nullptr, BrushType::Clay, ridge, 0.2f, 1.0f, false);
+ stroke(d, nullptr, bt, line({-0.05f, 0.0f, 2.0f}, {0.3f, 0.0f, 2.0f}), 0.3f, 0.15f, false);
+ break;
+ }
+ case BrushType::Layer: // a square frame raised to one flat height per stroke; two strokes, two steps
+ for (int pass = 0; pass < 2; ++pass)
+ stroke(d, nullptr, bt,
+ {{-0.38f, -0.38f, 2.0f}, {0.38f, -0.38f, 2.0f}, {0.38f, 0.38f, 2.0f}, {-0.38f, 0.38f, 2.0f}, {-0.38f, -0.38f, 2.0f}},
+ 0.24f, 1.0f, false);
break;
case BrushType::Vdm: // one stamp of the built-in Horn
stroke(d, nullptr, bt, {glm::vec3(0.0f, -0.05f, 2.0f)}, 0.45f, 0.5f, false);
break;
- default:
- stroke(d, nullptr, bt, frontCurve(), r, 1.0f);
+ default: // Standard: a soft rounded S
+ stroke(d, nullptr, bt, frontCurve(1.15f), 0.19f, 1.0f);
break;
}
return sceneMesh(d);
@@ -332,7 +380,8 @@ ImTextureID ThumbnailCache::alpha(const BrushAlpha& alpha) {
return request(
"alpha|" + hex64(h),
[alpha] {
- // The stamp as ZBrush shows alphas: white = full effect on black.
+ // The stamp as a height map: full effect light, none dark. Clay grey on the tile's charcoal rather than
+ // pure white on black, so it doesn't outshine the model and the rest of the tray.
Result r;
constexpr int S = 128;
r.image.width = r.image.height = S;
@@ -342,9 +391,9 @@ ImTextureID ThumbnailCache::alpha(const BrushAlpha& alpha) {
for (int x = 0; x < S; ++x) {
const float u = (float(x) + 0.5f) / S * 2.0f - 1.0f, v = 1.0f - (float(y) + 0.5f) / S * 2.0f;
float g = shown.empty() ? brushFalloff(std::sqrt(u * u + v * v), 1.0f) : shown.sample(u, v);
- const auto c = uint8_t(std::clamp(g, 0.0f, 1.0f) * 255.0f + 0.5f);
+ const float t = std::clamp(g, 0.0f, 1.0f);
uint8_t* p = &r.image.rgba[(size_t(y) * S + size_t(x)) * 4];
- p[0] = p[1] = p[2] = c;
+ for (int k = 0; k < 3; ++k) p[k] = uint8_t(kAlphaNone[k] + (kAlphaFull[k] - kAlphaNone[k]) * t + 0.5f);
p[3] = 255;
}
return r;
@@ -360,10 +409,11 @@ ImTextureID ThumbnailCache::material(int matcap) {
hex64(fnv1a64(key)),
[matcap] {
Result r;
- r.mesh = std::make_unique<Mesh>(makeIcosphere(5, 1.0f));
+ r.mesh = std::make_unique<Mesh>(makeIcosphere(5, kBallRadius));
r.matcap = matcap;
r.yaw = 0.0f;
r.pitch = 0.0f;
+ r.distance = ballDistance(); // the same ball, framed as the brush previews are
return r;
},
true);
diff --git a/src/core/Matcap.cpp b/src/core/Matcap.cpp
index a42b2b0a..2d027f36 100644
--- a/src/core/Matcap.cpp
+++ b/src/core/Matcap.cpp
@@ -30,17 +30,17 @@ struct MatcapStyle {
};
const MatcapStyle kStyles[] = {
- {"Sculpt", {0.56f, 0.44f, 0.36f}, 0.0f, {0.0f, 0.0f, 0.0f}, 0.0f, 0.0f, {0.0f, 0.0f, 0.0f}, 0.0f, 0.0f,
+ {"Sculpt", {0.54f, 0.46f, 0.39f}, 0.0f, {0.0f, 0.0f, 0.0f}, 0.0f, 0.0f, {0.0f, 0.0f, 0.0f}, 0.0f, 0.0f,
MatcapStyle::Light::Sculpt, {0.8f, 0.35f}},
{"Red Wax", {0.50f, 0.045f, 0.03f}, 0.55f, {0.55f, 0.06f, 0.03f}, 0.55f, 70.0f, {0.25f, 0.08f, 0.06f}, 0.0f, 0.0f},
- {"Clay", {0.46f, 0.38f, 0.33f}, 0.25f, {0.05f, 0.03f, 0.02f}, 0.06f, 10.0f, {0.10f, 0.10f, 0.11f}, 0.0f, 0.0f},
+ {"Clay", {0.50f, 0.27f, 0.17f}, 0.25f, {0.05f, 0.03f, 0.02f}, 0.06f, 10.0f, {0.10f, 0.10f, 0.11f}, 0.0f, 0.0f},
{"Skin", {0.68f, 0.38f, 0.28f}, 0.6f, {0.6f, 0.16f, 0.08f}, 0.16f, 28.0f, {0.22f, 0.16f, 0.15f}, 0.0f, 0.0f},
{"Chrome", {0.95f, 0.96f, 1.0f}, 0.0f, {0.0f, 0.0f, 0.0f}, 0.0f, 1.0f, {0.0f, 0.0f, 0.0f}, 1.0f, 0.05f},
{"White", {0.78f, 0.78f, 0.76f}, 0.3f, {0.04f, 0.04f, 0.05f}, 0.3f, 45.0f, {0.12f, 0.13f, 0.15f}, 0.0f, 0.0f},
{"Bronze", {0.80f, 0.50f, 0.25f}, 0.0f, {0.0f, 0.0f, 0.0f}, 0.0f, 1.0f, {0.0f, 0.0f, 0.0f}, 1.0f, 0.35f},
// The default (defaultMatcap()). Last, so the indices of the others stay put.
{"Soft Clay", {0.50f, 0.455f, 0.41f}, 0.0f, {0.0f, 0.0f, 0.0f}, 0.0f, 0.0f, {0.0f, 0.0f, 0.0f}, 0.0f, 0.0f,
- MatcapStyle::Light::SoftClay, {0.62f, 0.3f}},
+ MatcapStyle::Light::SoftClay, {0.3f, 0.08f}},
};
constexpr int kStyleCount = int(sizeof kStyles / sizeof kStyles[0]);
@@ -84,24 +84,32 @@ glm::vec3 shadeSculpt(const MatcapStyle& m, const glm::vec3& n) {
return m.albedo * light + glm::vec3(spec) + glm::vec3(0.8f, 0.85f, 0.95f) * (fillSpec + rim);
}
-// The default: matte studio clay, a warm light grey. One broad key from the upper left wrapped far round
-// the form, a cool fill and a sky/ground ambient so nothing goes black, and only a wide, faint sheen: no
-// hot spot to blow out, so the form reads from the shading gradient and the cavity term (kStyles).
+// The default: matte studio clay, a warm light grey, built so a sculpted stroke reads at once. One key from the
+// upper left with little wrap and a steep falloff (brightness turns quickly with the slope, so the two sides of a
+// ridge part clearly), a form shadow on the lower right that goes well down without going black, a cool fill and
+// sky/ground ambient, a broad low sheen that runs along ridges (no hot spot), and a cool rim strongest on the
+// lower right so the silhouette holds against the charcoal background where the key doesn't reach.
glm::vec3 shadeSoftClay(const MatcapStyle& m, const glm::vec3& n) {
const glm::vec3 v(0.0f, 0.0f, 1.0f);
- const glm::vec3 key = glm::normalize(glm::vec3(-0.45f, 0.6f, 0.7f));
- const glm::vec3 fill = glm::normalize(glm::vec3(0.8f, -0.2f, 0.5f));
- const float k = std::max((glm::dot(n, key) + 0.2f) / 1.2f, 0.0f);
- const float diff = std::pow(k, 1.7f); // falls off steadily, so slopes and strokes read everywhere
- const float fd = std::max(glm::dot(n, fill), 0.0f);
+ const glm::vec3 key = glm::normalize(glm::vec3(-0.55f, 0.68f, 0.55f));
+ const glm::vec3 fill = glm::normalize(glm::vec3(0.85f, -0.2f, 0.35f));
+ const float k = std::max(glm::dot(n, key) * 0.92f + 0.08f, 0.0f);
+ const float diff = std::pow(k, 2.4f);
+ // A real fill from the right, about a third of the key: the shadow side stays a mid value, and slopes there
+ // turn towards or away from it, so strokes read on that side too.
+ const float fd = std::max((glm::dot(n, fill) + 0.25f) / 1.25f, 0.0f);
+ // Sky above, a warm bounce from the ground below: the lower left, where neither light reaches, stays clay.
const float up = 0.5f + 0.5f * n.y;
- const glm::vec3 ambient = glm::mix(glm::vec3(0.05f, 0.046f, 0.043f), glm::vec3(0.11f, 0.115f, 0.125f), up);
- const glm::vec3 light = 1.2f * diff * glm::vec3(1.0f, 0.97f, 0.93f) + 0.2f * fd * fd * glm::vec3(0.8f, 0.86f, 1.0f) + ambient;
+ const glm::vec3 ambient = glm::mix(glm::vec3(0.13f, 0.115f, 0.1f), glm::vec3(0.07f, 0.075f, 0.085f), std::sqrt(up));
+ const glm::vec3 light = 1.3f * diff * glm::vec3(1.0f, 0.97f, 0.93f) + 0.3f * fd * fd * glm::vec3(0.9f, 0.93f, 1.0f) + ambient;
const float nh = std::max(glm::dot(n, glm::normalize(key + v)), 0.0f);
- const float sheen = 0.05f * std::pow(nh, 8.0f);
- // Grazing angles fall off a little, like a dry surface, which keeps the silhouette crisp on dark grey.
- const float edge = 1.0f - 0.18f * std::pow(1.0f - std::max(n.z, 0.0f), 2.0f);
- return (m.albedo * light + glm::vec3(sheen)) * edge;
+ const float sheen = (0.03f * std::pow(nh, 8.0f) + 0.09f * std::pow(nh, 30.0f)) * std::min(1.0f, k * 3.0f);
+ // Rim: grazing normals, weighted towards the lower right (the side the key leaves dark).
+ const float grazing = std::pow(1.0f - std::max(n.z, 0.0f), 3.0f);
+ const float len = std::sqrt(n.x * n.x + n.y * n.y);
+ const float side = len > 1e-4f ? std::clamp((n.x * 0.8f - n.y * 0.6f) / len, 0.0f, 1.0f) : 0.0f;
+ const glm::vec3 rim = (0.05f + 0.2f * side) * grazing * glm::vec3(0.82f, 0.88f, 1.0f);
+ return m.albedo * light + glm::vec3(sheen) + rim;
}
glm::vec3 shade(const MatcapStyle& m, const glm::vec3& n) {
@@ -146,6 +154,12 @@ int defaultMatcap() {
return index;
}
+int matcapInListOrder(int k) {
+ if (k < 0 || k >= kStyleCount) return -1;
+ const int d = defaultMatcap();
+ return k == 0 ? d : k <= d ? k - 1 : k;
+}
+
const char* matcapName(int index) { return index >= 0 && index < kStyleCount ? kStyles[index].name : ""; }
MatcapCavity matcapCavity(int index) { return index >= 0 && index < kStyleCount ? kStyles[index].cavity : MatcapCavity{}; }
diff --git a/src/core/Matcap.h b/src/core/Matcap.h
index bd0d89ec..9c7953d0 100644
--- a/src/core/Matcap.h
+++ b/src/core/Matcap.h
@@ -19,6 +19,8 @@ const char* matcapName(int index);
int findMatcap(const std::string& name);
// The material new documents (and thumbnails) start with: Soft Clay, a matte warm clay.
int defaultMatcap();
+// The order the pickers list the MatCaps in: k = 0 is the default, then the others in index order.
+int matcapInListOrder(int k);
// How strongly the viewport darkens creases and lifts ridges on top of this matcap (the
// curvature term in the mesh shader); the Sculpt material leans on it more than the others.
diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp
index 2ea14a48..5d882185 100644
--- a/src/render/Renderer.cpp
+++ b/src/render/Renderer.cpp
@@ -217,8 +217,10 @@ void main() {
vec3 by = cross(v, bx);
vec2 uv = vec2(dot(bx, n), dot(by, n)) * 0.495 + 0.5;
vec3 mc = pow(texture(uMatcapTex, uv).rgb, vec3(2.2));
- float mcrease = smoothstep(0.0, 0.16, curvature);
- float mridge = smoothstep(0.0, 0.2, -curvature);
+ // Starts above the curvature of a smooth sphere's own facets, so only real creases darken and a broad
+ // stroke doesn't pool into a smear.
+ float mcrease = smoothstep(0.03, 0.18, curvature);
+ float mridge = smoothstep(0.03, 0.2, -curvature);
vec3 c = mc * tint * (1.0 - uMatcapCavity.x * mcrease) * (1.0 + uMatcapCavity.y * mridge);
if (uShowMask == 1) c *= 1.0 - 0.75 * clamp(V_MASK, 0.0, 1.0);
fragColor = finish(c);
@@ -293,10 +295,11 @@ const char* kBgFS = R"(#version 330 core
in vec2 vUv;
out vec4 fragColor;
// Neutral charcoal, lightest a little above the middle (behind the model) and falling off in a soft
-// radial vignette, so the model reads against it without a coloured cast. A little noise hides banding.
+// radial vignette down to the shade of the shelves around it, so the model reads against it without a
+// coloured cast and the canvas meets the shell without a darker band. A little noise hides banding.
void main() {
vec3 centre = vec3(0.215, 0.215, 0.222);
- vec3 edge = vec3(0.075, 0.075, 0.08);
+ vec3 edge = vec3(0.106, 0.106, 0.114); // the shell's shade (Theme shellBg #1b1b1d): no step at the seams
float d = length((vUv - vec2(0.5, 0.56)) * vec2(1.0, 1.15));
float t = smoothstep(0.05, 0.85, d);
vec3 c = mix(centre, edge, t);
diff --git a/src/render/Renderer.h b/src/render/Renderer.h
index 87e5c294..7ff8f49b 100644
--- a/src/render/Renderer.h
+++ b/src/render/Renderer.h
@@ -18,7 +18,7 @@ namespace sf {
struct RenderSettings {
bool wireframe = false;
- glm::vec3 baseColor{0.80f, 0.55f, 0.45f}; // clay
+ glm::vec3 baseColor{0.62f, 0.58f, 0.53f}; // Studio's colour: a warm clay grey, like the default Soft Clay
bool showPolypaint = true; // vertex colours replace baseColor when the mesh has them
bool showTexture = true; // with showPolypaint: a SubTool's painted texture (core/Texture.h) multiplies in
bool showMask = true; // masked areas render darker (ZBrush style)
diff --git a/tests/test_polypaint.cpp b/tests/test_polypaint.cpp
index 833c1796..16867866 100644
--- a/tests/test_polypaint.cpp
+++ b/tests/test_polypaint.cpp
@@ -326,6 +326,13 @@ TEST(matcap_builtin_materials) {
for (size_t k = 0; k < clay.size(); k += 4) brightest = std::max(brightest, int(clay[k]));
CHECK(brightest < 225);
CHECK(matcapCavity(-1).crease > 0.0f && matcapCavity(matcapCount()).crease == matcapCavity(-1).crease);
+ // The pickers list the default first, then every other MatCap once, in index order.
+ CHECK(matcapInListOrder(0) == defaultMatcap() && matcapInListOrder(1) == 0);
+ CHECK(matcapInListOrder(-1) == -1 && matcapInListOrder(matcapCount()) == -1);
+ std::vector<int> listed;
+ for (int k = 0; k < matcapCount(); ++k) listed.push_back(matcapInListOrder(k));
+ std::sort(listed.begin(), listed.end());
+ for (int i = 0; i < matcapCount(); ++i) CHECK(listed[size_t(i)] == i);
}
TEST(polypaint_restore_stroke_marks_colors_dirty) {