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
Timelapse: frames always the full mesh, never the view's coarse levels (PBR timelapse flicker on dense meshes)
islandmed5a3edb382368
diff --git a/changes/fix-timelapse-pbr-flicker.md b/changes/fix-timelapse-pbr-flicker.mdnew file mode 100644index 00000000..a573f626--- /dev/null+++ b/changes/fix-timelapse-pbr-flicker.md@@ -0,0 +1,10 @@+---+whats_new: **Timelapse** videos of dense sculpts no longer flicker (**Edit > Export timelapse...**).+fixed: Timelapse: a PBR timelapse of a high-detail sculpt flickered a little in the video (not in the view): after each+ step of the history the frames switched between the full mesh and its lighter preview levels. Timelapse frames and+ `--render` turntables now always draw the full mesh. Thanks @ebarranco.+testers:+ - Any OS: a dense sculpt (millions of triangles) with a few strokes, Material > PBR, Edit > Export timelapse (4K); the+ video's shading stays steady from frame to frame.+---+Cause: RenderSettings had no offline mode; renderToImage used the view's coarse-LOD choice (still budget, edits pending).diff --git a/src/app/App.cpp b/src/app/App.cppindex 754ad0f1..5571651e 100644--- a/src/app/App.cpp+++ b/src/app/App.cpp@@ -398,6 +398,7 @@ int App::renderHeadless() {settings.showFaceGroups = settings.showFaceGroups || options_.facegroups;settings.showMesh = !options_.hideMesh;settings.dimInactive = false; // a beauty shot: every Part at full brightness+ settings.fullDetail = true; // (never the view's coarse levels: a turntable's frames all alike)syncScene();const std::filesystem::path out(std::u8string(options_.renderPath.begin(), options_.renderPath.end()));for (int f = 0; f < frames; ++f) {diff --git a/src/app/App.h b/src/app/App.hindex 3a40e705..7d979caf 100644--- a/src/app/App.h+++ b/src/app/App.h@@ -2613,6 +2613,7 @@ private:bool timelapseStep(double budgetSeconds); // renders frames for up to the budget; false when finishedbool timelapseBusy() const; // a timelapse is rendering (a few frames each app frame)int runTimelapseCli(); // sculptforge FILE --timelapse out.mp4+ bool renderTimelapseFrame(const Camera& cam, int width, int height, std::vector<uint8_t>& rgba, std::string& err);void startProofMode(); // Help > Benchmark, sculptforge --benchmarkbool proofSkippedScenes() const; // the benchmark skipped a scene: too little free memorybool proofRunning() const; // a benchmark is measuring (not its intro or results): every frame is wanteddiff --git a/src/app/PanelTimeline.cpp b/src/app/PanelTimeline.cppindex fe0962a8..f68c81ae 100644--- a/src/app/PanelTimeline.cpp+++ b/src/app/PanelTimeline.cpp@@ -263,9 +263,6 @@ bool App::timelapseStep(double budgetSeconds) {return false;};if (!t || j.cancelled) return finish(false);- RenderSettings settings = renderSettings_;- settings.dimInactive = false;- settings.motionProxy = false;while (j.frame < j.frames) {// The history plays between the two holds; the camera turns once around the model over the whole video.const int sweep = std::max(1, j.frames - j.hold0 - j.hold1);@@ -278,8 +275,7 @@ bool App::timelapseStep(double budgetSeconds) {}Camera cam = j.camera;cam.yaw = j.yaw0 + 6.2831853f * float(j.frame) / float(j.frames);- syncScene();- if (!renderer_.renderToImage(cam, j.width, j.height, settings, j.rgba, err)) {+ if (!renderTimelapseFrame(cam, j.width, j.height, j.rgba, err)) {j.error = err;return finish(false);}@@ -295,6 +291,19 @@ bool App::timelapseStep(double budgetSeconds) {return finish(true);}+// One frame as the timelapse renders it: the view's look, every Part at full brightness, the full mesh (never the+// view's coarse levels or proxy, which switch with how long the view has been still and with edits waiting for their+// levels: the history's seeks flipped dense meshes between the two from frame to frame).+bool App::renderTimelapseFrame(const Camera& cam, int width, int height, std::vector<uint8_t>& rgba, std::string& err) {+ RenderSettings settings = renderSettings_;+ settings.dimInactive = false;+ settings.motionProxy = false;+ settings.stroking = false;+ settings.fullDetail = true;+ syncScene();+ return renderer_.renderToImage(cam, width, height, settings, rgba, err);+}+int App::runTimelapseCli() {Timeline* t = Timeline::of(doc_.undo);if (!t) t = Timeline::attach(doc_).get();diff --git a/src/app/UiTest.cpp b/src/app/UiTest.cppindex 6faf0f48..54f66af9 100644--- a/src/app/UiTest.cpp+++ b/src/app/UiTest.cpp@@ -1149,6 +1149,37 @@ double Demo::query(const std::string& name, bool& known) const {app_.benchmarkDrawMs(0);return double(app_.renderer_.coarseDrawnClusters());}+ if (name == "timelapse_flicker") {+ // The timelapse's frames on a static camera (320x180, as renderTimelapseFrame draws them): through the+ // history, then a hold on the last step. Held frames show the same model from the same place, so they must+ // match: the largest mean per-pixel luma change (0-255) between consecutive held frames.+ Timeline* t = Timeline::of(app_.doc_.undo);+ if (!t || t->cursor() == 0) return -1.0;+ const size_t last = t->cursor();+ Camera cam = app_.camera_;+ cam.frame(app_.sceneBounds());+ cam.pitch = app_.camera_.pitch;+ cam.distance *= 0.72f;+ cam.aspect = 320.0f / 180.0f;+ std::vector<uint8_t> prev, rgba;+ double worst = 0.0;+ std::string err;+ for (size_t step = 0; step <= last + 6; ++step) {+ const size_t at = std::min(step, last);+ if (at != t->cursor() && !t->seek(app_.doc_, at, &err)) return -2.0;+ if (!app_.renderTimelapseFrame(cam, 320, 180, rgba, err)) return -3.0;+ if (step > last && prev.size() == rgba.size()) {+ double sum = 0.0;+ for (size_t i = 0; i + 3 < rgba.size(); i += 4) {+ const auto luma = [](const uint8_t* p) { return 0.2126 * p[0] + 0.7152 * p[1] + 0.0722 * p[2]; };+ sum += std::abs(luma(&rgba[i]) - luma(&prev[i]));+ }+ worst = std::max(worst, sum / double(rgba.size() / 4));+ }+ prev.swap(rgba);+ }+ return worst;+ }if (name == "stroke_programs") return double(app_.renderer_.strokePrograms()); // compiled before any stroke (warmed)if (name == "render_patch_errors") { // the 3D view drawn once more now: dynamic-topology patch triangles wrong on the GPUapp_.benchmarkDrawMs(0);diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cppindex 6decf6bc..f3379a08 100644--- a/src/render/Renderer.cpp+++ b/src/render/Renderer.cpp@@ -3662,7 +3662,7 @@ void Renderer::drawSlot(const MeshSlot& s, bool active, bool flat, const RenderS// (While a stroke's edits wait for their levels, all of it in full: edited clusters in full beside coarse ones// would leave seams, and squeeze the rest to the coarsest level.)bool coarse = coarseLod_ && coarseAllowed && s.coarse && s.coarse->clusters.size() == s.drawCount.size() &&- s.coarsePending.empty() && (settings.motionProxy || s.drawnTriangles > budget);+ s.coarsePending.empty() && !settings.fullDetail && (settings.motionProxy || s.drawnTriangles > budget);// At rest the real detail, if one full frame fits the still-frame budget (a single slow frame is fine).if (static const bool log = std::getenv("SF_COARSE_LOG") != nullptr; log && coarse)std::fprintf(stderr, "coarse lod: still %.2f s, moving %d, stroking %d, pending %zu, per triangle %.3g ms\n", settings.stillSeconds,@@ -3698,7 +3698,7 @@ void Renderer::drawSlot(const MeshSlot& s, bool active, bool flat, const RenderS// the main draw (same depth: it paints over it), and that cluster's vertices go up once as a stroke upload does.// SF_NO_STROKE_WARM=1 leaves it out (to compare); SF_FRAME_LOG says what it cost.static const bool noWarm = std::getenv("SF_NO_STROKE_WARM") != nullptr;- if (active && !noWarm && !thumbnailPass_ && !textured && !normalMapped && drawAlpha_ >= 1.0f && !xrayCull_ && !drawClusters_.empty() &&+ if (active && !noWarm && !thumbnailPass_ && !settings.fullDetail && !textured && !normalMapped && drawAlpha_ >= 1.0f && !xrayCull_ && !drawClusters_.empty() &&s.strokeWarmed != features && s.strokeWarmFrames++ >= 1) {s.strokeWarmed = features;const auto warmStart = std::chrono::steady_clock::now();diff --git a/src/render/Renderer.h b/src/render/Renderer.hindex 3b1d9145..65947690 100644--- a/src/render/Renderer.h+++ b/src/render/Renderer.h@@ -45,6 +45,10 @@ struct RenderSettings {bool motionProxy = false; // the view is moving (Fast Navigation): draw big meshes' lighter proxy (render/Clusters.h)double stillSeconds = 0.0; // how long the view has been still (0 while it moves): coarse levels give way to full detailbool stroking = false; // a stroke runs (its dabs still landing): coarse levels stay+ // Offline frames (the timelapse, --render): always the full mesh, never its coarse levels. In the view a frame+ // too slow for the still budget stays coarse while edited clusters draw in full until their levels follow, so+ // a timelapse seeking through the history flipped between the two from frame to frame (Discord, 0.11.10).+ bool fullDetail = false;bool flatShading = false; // the scene's shading (Material palette): faceted; Parts can override (core/Document.h)// Backface culling (#68, Tool > Display): back faces are never drawn, on any mesh (closed or not, from any// view). Off: they are skipped only where they can't show (a closed mesh seen from outside, Renderer::cull).diff --git a/tests/ui/timelapse_flicker.sfui b/tests/ui/timelapse_flicker.sfuinew file mode 100644index 00000000..932bb082--- /dev/null+++ b/tests/ui/timelapse_flicker.sfui@@ -0,0 +1,26 @@+# Timelapse frames don't flicker (Discord, 0.11.10: a PBR timelapse of a dense mesh flickered a little). A mesh over+# the triangle budget whose full frame doesn't fit the still-frame budget stays on its coarse levels in the view;+# after each history seek its edited clusters drew in full until their levels followed a frame later, so the+# timelapse flipped between full and coarse detail from frame to frame. Timelapse frames are always the full mesh:+# on a static camera, held frames of the same step must match (timelapse_flicker: the largest mean per-pixel luma+# change, 0-255, between consecutive held frames).+run ui_look look=classic layout=classic+env SF_TRIANGLE_BUDGET 40000+env SF_STILL_FRAME_MS 0.001+run new_sphere subdivisions=6+stroke 0.35 0.40 0.60 0.45+stroke 0.40 0.55 0.62 0.60+stroke 0.30 0.30 0.50 0.35+expect_value timeline_steps == 3+run viewport_shading mode=pbr+wait_value environment_pending == 0+wait 0.6+# (the view itself is on its coarse levels: the case that flickered)+expect_value coarse_clusters > 0+expect_value timelapse_flicker >= 0+expect_value timelapse_flicker < 0.05+expect_value timeline_cursor == 3+# Lit Sphere too.+run viewport_shading mode=lit_sphere+wait 0.3+expect_value timelapse_flicker < 0.05