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.

Fast Big Brushes: no ring walk for the cavity term of a scale-adaptive dab

islandmed5261e75b0b4c
diff --git a/src/core/Sculpt.cpp b/src/core/Sculpt.cpp
index a8a61b9f..ddb46df9 100644
--- a/src/core/Sculpt.cpp
+++ b/src/core/Sculpt.cpp
@@ -1173,7 +1173,7 @@ void Sculptor::dabSingle(Mesh& mesh, BVH& bvh, BrushType type, const DabParams&
const glm::vec3 x = pos[v];
if (curvatureStamp_[v] != stamp) {
curvatureStamp_[v] = stamp;
- curvature_[v] = mesh.curvatureAt(v);
+ curvature_[v] = kKeepCurvature; // (the GPU keeps its cavity term: no ring walk here)
}
const glm::vec3 n = normals[v];
if (analytic) { // (no mask here: such regions take the exact path)
diff --git a/src/core/Sculpt.h b/src/core/Sculpt.h
index e761e5a3..342c61cb 100644
--- a/src/core/Sculpt.h
+++ b/src/core/Sculpt.h
@@ -13,6 +13,7 @@
#include <algorithm>
#include <chrono>
+#include <limits>
#include <functional>
#include <memory>
#include <span>
@@ -168,6 +169,10 @@ float alphaFalloff(float dist, float radius, float focal);
// Where brush time goes (core/Benchmark.h, Help > Performance): milliseconds summed over dabs since the
// counters were last zeroed. kernel = finding the vertices and moving / masking / painting them.
+// A stroke curvature entry meaning "send the cavity term the GPU already has" (Renderer::prepareStrokeUpload): a
+// scale-adaptive dab moves a vertex without walking its ring, and the exact term follows with the exact normals.
+inline constexpr float kKeepCurvature = std::numeric_limits<float>::quiet_NaN();
+
struct SculptTimings {
double kernelMs = 0.0, normalsMs = 0.0, bvhMs = 0.0;
double remeshMs = 0.0; // dynamic topology (core/Dyntopo.h)
diff --git a/src/core/SculptBatch.cpp b/src/core/SculptBatch.cpp
index c7272d44..64635b25 100644
--- a/src/core/SculptBatch.cpp
+++ b/src/core/SculptBatch.cpp
@@ -332,7 +332,7 @@ void Sculptor::flushBatch(Mesh& mesh, BVH& bvh) {
if (glm::dot(o, o) >= k->r * k->r) continue;
if (curvatureStamp_[v] != stamp) {
curvatureStamp_[v] = stamp;
- curvature_[v] = mesh.curvatureAt(v);
+ curvature_[v] = kKeepCurvature;
}
PlaneKernel::tangents(normals[v], t1, t2);
reached = true;
diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp
index f1a7a7d2..6c489341 100644
--- a/src/render/Renderer.cpp
+++ b/src/render/Renderer.cpp
@@ -20,6 +20,7 @@
#include <atomic>
#include <bit>
#include <chrono>
+#include <cmath>
#include <thread>
#include <unordered_map>
#include <cstdlib>
@@ -1437,6 +1438,8 @@ void Renderer::uploadVertices(MeshSlot& s, const Mesh& mesh, bool full) {
std::atomic<bool> outside{false};
const bool normals = mesh.normals.size() == mesh.vertexCount();
const uint32_t nv = uint32_t(mesh.vertexCount());
+ s.sentCurvature.resize(nv);
+ uint16_t* sent = s.sentCurvature.data();
// Per block, hashes of what it last sent (positions; normals and curvature): a block a dab marked but didn't
// change (paint, mask) isn't sent again, and a cluster whose positions didn't move keeps its bounds and proxy.
s.blockHash.resize(nb * 2, 0);
@@ -1455,6 +1458,7 @@ void Renderer::uploadVertices(MeshSlot& s, const Mesh& mesh, bool full) {
if (v < nv) { // (else a vertex dynamic topology removed, which only patched clusters named)
inside &= packVertex(s.grid, mesh.positions[v], normals ? mesh.normals[v] : glm::vec3(0.0f, 0.0f, 1.0f),
curvatureAt(mesh, v), pv);
+ sent[v] = uint16_t(pv.normal >> 22);
box.expand(mesh.positions[v]);
}
out[i - b] = pv;
@@ -2065,6 +2069,7 @@ void Renderer::uploadPatches(MeshSlot& s, const Mesh& mesh, bool wireframe) {
const uint32_t v = p.verts[i];
const glm::vec3& pos = mesh.positions[v];
outside |= !packVertex(s.grid, pos, normals ? mesh.normals[v] : glm::vec3(0.0f, 0.0f, 1.0f), curvatureAt(mesh, v), packed[i]);
+ if (v < s.sentCurvature.size()) s.sentCurvature[v] = uint16_t(packed[i].normal >> 22);
lo = glm::min(lo, pos);
hi = glm::max(hi, pos);
}
@@ -3422,6 +3427,8 @@ bool Renderer::prepareStrokeUpload(uint32_t id, Mesh& mesh, StrokeUpload& out, c
s.blockBox.resize(nb);
PositionGrid grid = s.grid;
bool everything = false;
+ // The cavity bits each vertex last went up with: kKeepCurvature (a scale-adaptive dab) sends them again.
+ uint16_t* sent = s.sentCurvature.size() == nv ? s.sentCurvature.data() : nullptr;
const auto pack = [&] {
poolFor(pieces.size(), [&](size_t i0, size_t i1) {
for (size_t pi = i0; pi < i1; ++pi) {
@@ -3434,7 +3441,14 @@ bool Renderer::prepareStrokeUpload(uint32_t id, Mesh& mesh, StrokeUpload& out, c
const uint32_t v = order[i];
PackedVertex pv{};
if (v < nv) {
- inside &= packVertex(grid, mesh.positions[v], mesh.normals[v], curvature ? curvature[v] : curvatureAt(mesh, v), pv);
+ float c = curvature ? curvature[v] : curvatureAt(mesh, v);
+ const bool keep = std::isnan(c);
+ if (keep && !sent) c = curvatureAt(mesh, v);
+ inside &= packVertex(grid, mesh.positions[v], mesh.normals[v], keep && sent ? 0.0f : c, pv);
+ if (sent) {
+ if (keep) pv.normal = (pv.normal & 0x003FFFFFu) | uint32_t(sent[v]) << 22;
+ else sent[v] = uint16_t(pv.normal >> 22);
+ }
box.expand(mesh.positions[v]);
}
dst[i - pc.begin] = pv;
diff --git a/src/render/Renderer.h b/src/render/Renderer.h
index 94460b27..1c6dfa99 100644
--- a/src/render/Renderer.h
+++ b/src/render/Renderer.h
@@ -358,6 +358,7 @@ private:
std::vector<uint32_t> drawnOrder; // the mesh triangle of each drawn triangle (meshes with UVs only)
size_t drawnTriangles = 0;
size_t vertexCapacity = 0;
+ std::vector<uint16_t> sentCurvature; // per vertex, the cavity bits it last went up with (kKeepCurvature)
std::vector<uint64_t> blockHash; // per UploadOrder block: hashes of its packed positions, and the rest
std::vector<AABB> blockBox; // per UploadOrder block: its vertices' box as last packed
// Clusters whose culling bounds a stroke upload set from blockBox (a sphere round the box, no normal cone,