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.
C++ 3d3d-sculptingcppdear-imguidigital-sculptingfbxgame-developmentgaussian-splattinggltfimage-to-3dmcpopenglopenusdsculptingtext-to-3dunreal-engine
Vertex paint follows the brush alpha (#152): Drag Stamp, Dots, Spray painted a round blob
islandmeda9a411065107
diff --git a/changes/fix-paint-dragstamp-alpha.md b/changes/fix-paint-dragstamp-alpha.mdnew file mode 100644index 00000000..0428d074--- /dev/null+++ b/changes/fix-paint-dragstamp-alpha.md@@ -0,0 +1,13 @@+---+whats_new: **Paint with alphas**: vertex paint now follows the brush alpha with every stroke (Drag Stamp, Dots, Spray), so a Cracks stamp paints cracks instead of a soft round spot. Thanks @fxrtst.+fixed: Vertex paint ignored the brush alpha: Drag Stamp, Slide Stamp, Dots and Spray painted a soft round blob with any+ alpha (texture painting already followed it). The paint dab now samples the alpha on the view plane, turned as sculpt+ dabs turn it, and reaches into the stamp's corners (#152, thanks @fxrtst).+testers:+ - Windows: Paint, Rgb, stroke Drag Stamp, alpha Cracks, X symmetry, on the default sphere: drag a stamp; both sides show the crack pattern, not a round red spot.+ - Any OS: same with Dots and Spray; Alt still paints back to white in the alpha's shape.+---+Root cause: paintDab (core/VertexPaint.cpp) only used brushFalloff and never read DabParams::alpha; the 0.11.8 Drag+Stamp pressure change (#146) was unrelated. Vertex density is not the limit: on the 163.8K sphere a 60 px+ stamp spans+dozens of vertices per side, enough to show Cracks (finer detail than the vertex spacing still blurs; texture paint or+Divide for that).diff --git a/src/core/VertexPaint.cpp b/src/core/VertexPaint.cppindex 5fcb320e..60353b42 100644--- a/src/core/VertexPaint.cpp+++ b/src/core/VertexPaint.cpp@@ -1,6 +1,7 @@// SculptForge - open source digital sculpting// SPDX-License-Identifier: GPL-3.0-or-later#include "core/VertexPaint.h"+#include "core/BrushAlpha.h"#include "core/LayerStack.h"#include "core/MaterialRecipe.h"#include "core/MeshMaps.h"@@ -125,14 +126,24 @@ size_t paintDab(Sculptor& sculptor, Mesh& mesh, const BVH& bvh, const DabParams&static thread_local std::vector<uint32_t> verts;auto clock = std::chrono::steady_clock::now();size_t changed = 0;+ // An alpha shapes the dab as it does a sculpt dab and a texture dab (#152): on the view plane, turned by alphaUp,+ // reaching into its square's corners.+ const bool useAlpha = p.alpha && !p.alpha->empty();for (const SymCopy& m : Sculptor::copies(sym)) {const glm::vec3 center = m.point(p.center), viewDir = m.dir(p.viewDir);+ glm::vec3 aUp = m.dir(p.alphaUp);+ aUp -= viewDir * glm::dot(aUp, viewDir);+ aUp = glm::length(aUp) > 1e-6f ? glm::normalize(aUp) : glm::vec3(0, 1, 0);+ const glm::vec3 aRight = glm::cross(aUp, -viewDir);static thread_local ConnectedScratch connected;- brushRegion(mesh, bvh, center, viewDir, p.radius, p.connectedOnly, p.viewFalloff, verts, connected);+ brushRegion(mesh, bvh, center, viewDir, p.radius * (useAlpha ? kAlphaReach : 1.0f), p.connectedOnly, p.viewFalloff,+ verts, connected);for (uint32_t v : verts) {if (p.frontFacesOnly && v < mesh.normals.size() && glm::dot(mesh.normals[v], viewDir) > 0.0f) continue;- const float w = brushFalloff(brushDistance(mesh.positions[v], center, viewDir, p.viewFalloff), p.radius, p.focal) * s *- vertexInfluence(mesh, v);+ const glm::vec3 o = mesh.positions[v] - center;+ const float f = useAlpha ? p.alpha->stamp(glm::dot(o, aRight) / p.radius, glm::dot(o, aUp) / p.radius, p.focal)+ : brushFalloff(brushDistance(mesh.positions[v], center, viewDir, p.viewFalloff), p.radius, p.focal);+ const float w = f * s * vertexInfluence(mesh, v);if (w <= 0.0f) continue;sculptor.recordColor(mesh, v);paintVertex(mesh, v, color, w, p.invert); // Alt paints Base back to white, erases a layerdiff --git a/tests/test_ai_link.cpp b/tests/test_ai_link.cppindex a518f72c..35913b22 100644--- a/tests/test_ai_link.cpp+++ b/tests/test_ai_link.cpp@@ -18,6 +18,9 @@#include <random>#include <sstream>#include <thread>+#ifndef _WIN32+#include <unistd.h>+#endifusing namespace sf;using namespace sf::link;@@ -288,7 +291,9 @@ TEST(ai_link_long_runtime_folder_still_listens) {TEST(ai_link_attach_end_to_end) {// sculptforge-cli --mcp --attach against a stand-in app: live_connect waits, the code pairs, tools are forwarded.const std::string run = scratchDir("sf_ai_link_attach");- const std::string endpoint = run + "/live.sock";+ // (a long worktree's test folder overflows sun_path, 108 bytes: then a short name, as liveEndpoint falls back)+ std::string endpoint = run + "/live.sock";+ if (endpoint.size() >= 100) endpoint = "/tmp/sf-attach-" + std::to_string(::getpid()) + ".sock";AiLinkListener listener;std::string err;CHECK(listener.open(endpoint, err));@@ -322,6 +327,8 @@ TEST(ai_link_attach_end_to_end) {CHECK(o.find("ran mesh_info") != std::string::npos);CHECK(o.find("notifications/tools/list_changed") != std::string::npos);CHECK(o.rfind("Not connected to SculptForge") > o.find("ran mesh_info")); // after Disconnect, refused again+ std::error_code ec;+ std::filesystem::remove(endpoint, ec);}#endifdiff --git a/tests/test_vertexpaint.cpp b/tests/test_vertexpaint.cppindex 715b4b7c..32a45313 100644--- a/tests/test_vertexpaint.cpp+++ b/tests/test_vertexpaint.cpp@@ -5,6 +5,7 @@// export) and the built-in Lit Sphere materials.#include "TestHarness.h"+#include "core/BrushAlpha.h"#include "core/Commands.h"#include "core/Image.h"#include "core/LitSphere.h"@@ -551,3 +552,46 @@ TEST(vertexpaint_restore_stroke_marks_colors_dirty) {CHECK(m.dirtyBegin <= centre && centre < m.dirtyEnd);doc.undo.push(doc.sculptor.endStroke());}++TEST(vertexpaint_dab_follows_the_alpha) {+ // #152: a paint dab with an alpha (Drag Stamp, Dots, Spray) is shaped by it, not a round blob, on both sides.+ Document doc = makeDoc(makeIcosphere(6));+ Mesh& m = doc.mesh;+ BrushAlpha half; // white on its left half, black on its right+ half.name = "Half";+ half.width = half.height = 8;+ for (int y = 0; y < 8; ++y)+ for (int x = 0; x < 8; ++x) half.values.push_back(x < 4 ? 1.0f : 0.0f);+ DabParams p = paintParams({1, 0, 0}, 0.4f);+ p.alpha = ½+ p.alphaUp = {0, 1, 0};+ const glm::vec3 right = glm::cross(p.alphaUp, -p.viewDir); // the stamp's right on the view plane+ CHECK(doc.sculptor.beginStroke(m, "Paint"));+ CHECK(paintDab(doc.sculptor, m, doc.bvh, p, kRed, Symmetry{}) > 0);+ const uint32_t left = nearestVertex(m, glm::normalize(glm::vec3(1, 0, 0) - right * 0.15f));+ const uint32_t rightV = nearestVertex(m, glm::normalize(glm::vec3(1, 0, 0) + right * 0.15f));+ CHECK(m.colors[left].y < 0.5f); // under the white half: painted+ CHECK(m.colors[rightV] == glm::vec3(1.0f)); // under the black half: untouched (a round dab paints it)+ // The X mirror copy is shaped too (oriented as the sculpt and texture dabs orient it): one side painted, one not.+ const glm::vec3 a = m.colors[nearestVertex(m, glm::normalize(glm::vec3(-1, 0, 0) - right * 0.15f))];+ const glm::vec3 b = m.colors[nearestVertex(m, glm::normalize(glm::vec3(-1, 0, 0) + right * 0.15f))];+ CHECK((a.y < 0.5f && b == glm::vec3(1.0f)) || (b.y < 0.5f && a == glm::vec3(1.0f)));+ doc.undo.push(doc.sculptor.endStroke());++ // Cracks on a dense sphere: a pattern of painted and unpainted vertices inside the dab, not a solid blob.+ Document d2 = makeDoc(makeIcosphere(6));+ BrushAlpha cracks;+ CHECK(BrushAlpha::builtin("Cracks", cracks));+ DabParams c = paintParams({0, 0, 1}, 0.5f);+ c.alpha = &cracks;+ CHECK(d2.sculptor.beginStroke(d2.mesh, "Paint"));+ paintDab(d2.sculptor, d2.mesh, d2.bvh, c, kRed, Symmetry{false, false, false});+ size_t inside = 0, painted = 0;+ for (uint32_t v = 0; v < d2.mesh.vertexCount(); ++v) {+ if (glm::distance(d2.mesh.positions[v], glm::vec3(0, 0, 1)) > 0.25f) continue;+ ++inside;+ painted += d2.mesh.colors[v].y < 0.95f;+ }+ CHECK(inside > 100 && painted > inside / 20 && painted < inside * 9 / 10);+ d2.undo.push(d2.sculptor.endStroke());+}