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.

Reapply "Merge feat/floor-grid e145fbbd: View > Floor grid, at the model's lowest point and drawn under the model (#115, @fenixpoints)"

islandmed3ae197654146
diff --git a/changes/feat-floor-grid.md b/changes/feat-floor-grid.md
new file mode 100644
index 00000000..1f3d518a
--- /dev/null
+++ b/changes/feat-floor-grid.md
@@ -0,0 +1,15 @@
+---
+whats_new: **Floor grid**: **View > Floor grid** draws a faint grid on the floor the model stands on, for grounding,
+ perspective and lining up Parts. Off by default.
+added: **Floor grid** (#115, **View > Floor grid**, also **Tool > Display** and the command palette): a faint grid on the
+ floor under the model (its lowest point, Y up; it moves when a stroke or a move ends), the X and Z axes through the
+ origin marked, squares stepping by ten with the zoom and fading into the distance. It never draws over the model.
+ Off by default; remembered in the preferences. Suggested by @fenixpoints.
+testers:
+ - Windows at 150% scaling: View > Floor grid; orbit and zoom out and in: the lines stay thin and smooth, the squares
+ step without popping, no shimmering near the horizon, and the sphere stands on the grid.
+ - Any OS: sculpt a long stroke down past the bottom of the model: the floor moves once the stroke ends, not during
+ it. Orbit below the floor: the model shows whole, the grid only around it. Restart: the grid is still on.
+---
+The floor follows the lowest point of the visible Parts (measured when the history or the Parts change, not during a
+stroke or a drag); it is drawn before the Parts, so it never covers mesh pixels. Coordinator review 11-06.
diff --git a/docs/guide/interface.md b/docs/guide/interface.md
index 0e28cdd7..ef9b380a 100644
--- a/docs/guide/interface.md
+++ b/docs/guide/interface.md
@@ -170,7 +170,7 @@ turn on **Edit > Preferences > Interface > Palettes strictly A-Z (strict order)*
| **Generate** | Mesh > Generate 3D (Mesh > From Image while Edit > Preferences > AI is off) | Generate 3D (image or text to 3D), Relief, Inflate and Stamp from an image, and the AI brush provider settings; with AI off only Relief, Inflate and Stamp |
| **Material** | Render > Materials | The Lit Sphere materials (Soft Clay, the default, first), your own (**Load Lit Sphere...**) and Studio, Base colour, Smooth / Flat shading for the scene and the active Part |
| **Preferences** | Edit > Preferences | Config, Interface, Input, Hotkeys, Display, Library, Tablet, Performance, Updates and Autosave sub-palettes (see [Customizing the interface](#customizing-the-interface)) |
-| **Render** | View | Wireframe, Show Mesh, Show Vertex Paint, Show Mask, Show Face Groups, Show Splats, Background, Frame, Fullscreen |
+| **Render** | View | Wireframe, Show Mesh, Show Vertex Paint, Show Mask, Show Face Groups, Floor grid, Show Splats, Background, Frame, Fullscreen |
| **Script** | File > Script | Console, Run script file, Copy session as script, Clear console |
| **Splats** | Render > Gaussian Splats | Gaussian splat tools: show, flip, turn, fit, clean floaters, Make sculptable, sculpt to splats, save, clear |
| **Stroke** | Sculpt > Stroke | The stroke types (Dots, Drag Stamp, Spray, Lazy Stroke) and their settings |
diff --git a/docs/guide/navigation.md b/docs/guide/navigation.md
index 86a14d4c..df9bdcb1 100644
--- a/docs/guide/navigation.md
+++ b/docs/guide/navigation.md
@@ -79,6 +79,12 @@ style, <kbd>Alt</kbd>+left-drag rotates as before. With a pen that has no button
press <kbd>Shift</kbd>+<kbd>L</kbd> to turn it off while you rotate, or turn on Hold Space. Lasso Mask, Rectangle Mask and the
<kbd>Ctrl</kbd>+<kbd>Shift</kbd> hide and show shapes work as before.
+**Floor grid** (**View > Floor grid**, also **Tool > Display**; off by default, remembered) draws a faint grid on
+the floor the model stands on: its lowest point, with the up axis (Y) standing on it. It helps judge perspective and
+tilt and line up Parts; the red line is the X axis, the blue one Z. The floor moves when a stroke or a move ends (not
+during it). The squares step up by ten as you zoom out, and the grid fades into the distance; it never draws over
+the model, even seen from below.
+
"Background" means any part of the canvas where the cursor isn't over the model. A left-drag that starts on
the model sculpts instead, so with a pen or a one-button mouse, start rotations beside the model. When the
model fills the view, zoom out a little or use the right-shelf buttons.
diff --git a/src/app/App.cpp b/src/app/App.cpp
index 10dae94c..c66eab28 100644
--- a/src/app/App.cpp
+++ b/src/app/App.cpp
@@ -4,6 +4,7 @@
#include "app/Pickers.h"
#include "app/BrandMark.h"
#include "io/BridgeProtocol.h"
+#include "core/ThreadPool.h"
#include "core/LayerStack.h"
#include "core/HardwareProfile.h"
#include "app/ShellQuote.h"
@@ -2786,6 +2787,43 @@ AABB App::sceneBounds() const {
return b;
}
+void App::updateFloorHeight() {
+ if (!renderSettings_.floorGrid) {
+ floorKey_ = 0; // (measured again when it is turned on)
+ return;
+ }
+ if (renderSettings_.stroking || drag_ != Drag::None) return; // after the stroke or the drag, not during it
+ // What the lowest point depends on: every Part's history, size and visibility (each history's revision moves
+ // with every step, undo and redo; the size and the list catch a new or opened scene).
+ uint64_t key = 1469598103934665603ull;
+ auto mix = [&key](uint64_t v) { key = (key ^ v) * 1099511628211ull; };
+ mix(uint64_t(doc_.activePart));
+ mix(doc_.undo.revision());
+ for (int i = 0; i < doc_.partCount(); ++i) {
+ const Part& p = doc_.parts[size_t(i)];
+ mix(p.id);
+ mix(p.visible);
+ mix(p.undo.revision());
+ mix(doc_.partMesh(i).vertexCount());
+ }
+ if (key == floorKey_) return;
+ floorKey_ = key;
+ float lowest = std::numeric_limits<float>::max();
+ for (int i = 0; i < doc_.partCount(); ++i) {
+ if (!doc_.parts[size_t(i)].visible) continue;
+ const auto& positions = doc_.partMesh(i).positions;
+ const size_t block = 1 << 16;
+ std::vector<float> low((positions.size() + block - 1) / block, std::numeric_limits<float>::max());
+ poolFor(positions.size(), [&](size_t b, size_t e) {
+ float m = std::numeric_limits<float>::max();
+ for (size_t v = b; v < e; ++v) m = std::min(m, positions[v].y);
+ low[b / block] = m;
+ }, block);
+ for (float m : low) lowest = std::min(lowest, m);
+ }
+ renderSettings_.floorHeight = lowest == std::numeric_limits<float>::max() ? 0.0f : lowest; // (no Part: the origin)
+}
+
void App::processPendingFiles() {
pollPackDialogs(); // Install Pack, New Pack's save and a macro's "?" files (PanelPacks.cpp)
std::vector<PendingFile> files;
@@ -2852,6 +2890,7 @@ Mesh& App::displayedMesh() {
void App::syncScene() {
if (solverBusy()) return; // the solver thread is changing the mesh: the GPU keeps what it has (AsyncStroke.cpp)
+ updateFloorHeight();
// Fill layers: Mesh Maps bakes started and landed (live after sculpting), and a painted mask's tiles evaluated.
updateMeshMaps();
if (paintsTexture(doc_.mesh) && doc_.mesh.texture->fillRevision != doc_.mesh.texture->revision)
diff --git a/src/app/App.h b/src/app/App.h
index d75111b2..e9c42401 100644
--- a/src/app/App.h
+++ b/src/app/App.h
@@ -215,6 +215,11 @@ private:
void openFileDialog();
void saveFileDialog(FileAction action);
AABB sceneBounds() const; // mesh plus the main body of any splats
+ // Floor grid (#115): keeps RenderSettings::floorHeight at the lowest point of the visible Parts. Measured again
+ // only when the history, the Parts or their visibility changed and no stroke or drag is running (so the floor
+ // doesn't follow each dab); App.cpp.
+ void updateFloorHeight();
+ uint64_t floorKey_ = 0;
bool onScreen(const AABB& box) const; // whole box inside the viewport
void processPendingFiles();
diff --git a/src/app/Bench.cpp b/src/app/Bench.cpp
index 3563ceb4..9b313ea4 100644
--- a/src/app/Bench.cpp
+++ b/src/app/Bench.cpp
@@ -94,6 +94,9 @@ int runAppBenchmark(BenchCommandLine cl) {
settings.motionProxy = moving;
// SF_BENCH_CULL=1: Tool > Display > Backface culling on (#68).
settings.backfaceCulling = std::getenv("SF_BENCH_CULL") && std::string(std::getenv("SF_BENCH_CULL")) == "1";
+ // SF_BENCH_FLOOR_GRID=1: View > Display > Floor grid on (#115).
+ const char* grid = std::getenv("SF_BENCH_FLOOR_GRID");
+ settings.floorGrid = grid && std::string(grid) == "1";
renderer.syncScene(scene(m));
const int warmup = 5, frames = 120;
Clock::time_point t;
diff --git a/src/app/Config.cpp b/src/app/Config.cpp
index 759805c8..5fcee6d8 100644
--- a/src/app/Config.cpp
+++ b/src/app/Config.cpp
@@ -137,6 +137,7 @@ Json toJson(const UiPrefs& p) {
j.set("flatShading", p.flatShading);
j.set("viewportCursor", double(p.viewportCursor));
j.set("backfaceCulling", p.backfaceCulling);
+ j.set("floorGrid", p.floorGrid);
j.set("uvPackColumns", double(p.uvPackColumns));
j.set("uvPackRows", double(p.uvPackRows));
j.set("maskDarkness", double(p.maskDarkness));
@@ -231,6 +232,7 @@ void fromJson(const Json& j, UiPrefs& p) {
p.flatShading = j["flatShading"].asBool(p.flatShading);
p.viewportCursor = std::clamp(int(j["viewportCursor"].asNumber(p.viewportCursor)), 0, 1);
p.backfaceCulling = j["backfaceCulling"].asBool(p.backfaceCulling);
+ p.floorGrid = j["floorGrid"].asBool(p.floorGrid);
p.uvPackColumns = std::clamp(int(j["uvPackColumns"].asNumber(p.uvPackColumns)), 1, 10);
p.uvPackRows = std::clamp(int(j["uvPackRows"].asNumber(p.uvPackRows)), 1, 10);
p.maskDarkness = std::clamp(float(j["maskDarkness"].asNumber(p.maskDarkness)), 0.0f, 1.0f);
@@ -1042,6 +1044,7 @@ bool App::readUiConfig(const std::string& path, std::string& err, bool own) {
doc_.sculptor.dyntopo.smoothRemesh = uiPrefs_.dyntopoSmoothRemesh;
renderSettings_.flatShading = uiPrefs_.flatShading;
renderSettings_.backfaceCulling = uiPrefs_.backfaceCulling;
+ renderSettings_.floorGrid = uiPrefs_.floorGrid;
uvPackColumns_ = uiPrefs_.uvPackColumns, uvPackRows_ = uiPrefs_.uvPackRows;
renderSettings_.maskDarkness = uiPrefs_.maskDarkness;
renderSettings_.gradientBackground = uiPrefs_.gradientBackground;
diff --git a/src/app/Config.h b/src/app/Config.h
index 5e27e962..cf4bb457 100644
--- a/src/app/Config.h
+++ b/src/app/Config.h
@@ -96,6 +96,8 @@ struct UiPrefs {
// Tool > Display > Backface culling (#68): skip the back faces of every Part (faster on dense meshes; see
// through open meshes). Off by default; a preference, projects keep their own.
bool backfaceCulling = false;
+ // View > Display > Floor grid (#115): the grid on the ground plane (RenderSettings::floorGrid). Off by default.
+ bool floorGrid = false;
// UV Editor > Pack > Columns x Rows (#135): the UDIM grid the last pack filled, the default for new projects.
int uvPackColumns = 1, uvPackRows = 1;
// Preferences > Interface > Mask darkness (and Tool > Masking): how dark masked areas show, 0-1
diff --git a/src/app/I18nSimplifiedChinese.cpp b/src/app/I18nSimplifiedChinese.cpp
index c5bf7679..f25b95a9 100644
--- a/src/app/I18nSimplifiedChinese.cpp
+++ b/src/app/I18nSimplifiedChinese.cpp
@@ -1499,6 +1499,12 @@ constexpr Entry kSimplifiedChinese[] = {
{"Tool > Remesh", "工具 > 重新网格化"},
{"Cut", "切割"},
{"Selection Sets", "选择集"},
+ {"Floor grid", "地面网格"},
+ {"A faint grid on the floor the model stands on (its lowest point, Y up), fading into the distance: a "
+ "reference for perspective and lining up Parts; the red and blue lines are the X and Z axes. It moves when "
+ "a stroke or a move ends. Off by default; saved automatically.",
+ "模型所站立地面上的淡淡网格(位于模型最低点,Y 轴向上),向远处渐隐:用作透视和对齐部件的参考;红线和蓝线是 X 轴和 "
+ "Z 轴。笔触或移动结束时更新位置。默认关闭;自动保存。"},
{"Backface culling", "背面剔除"},
{"Don't draw the back faces of the model: faster on dense meshes, and you see through the openings of open meshes "
"(a scan, a garment) instead of their inside. Brushes then work only on faces you can see. Off by default; "
diff --git a/src/app/I18nSpanish.cpp b/src/app/I18nSpanish.cpp
index 3a4da3d8..b7651492 100644
--- a/src/app/I18nSpanish.cpp
+++ b/src/app/I18nSpanish.cpp
@@ -1728,6 +1728,14 @@ constexpr Entry kSpanish[] = {
{"Tool > Remesh", "Herramienta > Remallado"},
{"Cut", "Cortar"},
{"Selection Sets", "Conjuntos de selección"},
+ {"Floor grid", "Cuadrícula del suelo"},
+ {"A faint grid on the floor the model stands on (its lowest point, Y up), fading into the distance: a "
+ "reference for perspective and lining up Parts; the red and blue lines are the X and Z axes. It moves when "
+ "a stroke or a move ends. Off by default; saved automatically.",
+ "Una cuadrícula tenue en el suelo sobre el que se apoya el modelo (su punto más bajo, Y hacia arriba), que "
+ "se desvanece a lo lejos: una referencia para la perspectiva y para alinear Piezas; las líneas roja y azul "
+ "son los ejes X y Z. Se mueve al terminar un trazo o un movimiento. Desactivada por defecto; se guarda "
+ "automáticamente."},
{"Backface culling", "Ocultar caras traseras"},
{"Don't draw the back faces of the model: faster on dense meshes, and you see through the openings of open meshes "
"(a scan, a garment) instead of their inside. Brushes then work only on faces you can see. Off by default; "
diff --git a/src/app/I18nTraditionalChinese.cpp b/src/app/I18nTraditionalChinese.cpp
index deab6e0f..d17150af 100644
--- a/src/app/I18nTraditionalChinese.cpp
+++ b/src/app/I18nTraditionalChinese.cpp
@@ -1499,6 +1499,12 @@ constexpr Entry kTraditionalChinese[] = {
{"Tool > Remesh", "工具 > 重新網格化"},
{"Cut", "切割"},
{"Selection Sets", "選取集"},
+ {"Floor grid", "地面網格"},
+ {"A faint grid on the floor the model stands on (its lowest point, Y up), fading into the distance: a "
+ "reference for perspective and lining up Parts; the red and blue lines are the X and Z axes. It moves when "
+ "a stroke or a move ends. Off by default; saved automatically.",
+ "模型所站立地面上的淡淡網格(位於模型最低點,Y 軸向上),向遠處漸隱:用作透視和對齊部件的參考;紅線和藍線是 X 軸和 "
+ "Z 軸。筆觸或移動結束時更新位置。預設關閉;自動儲存。"},
{"Backface culling", "背面剔除"},
{"Don't draw the back faces of the model: faster on dense meshes, and you see through the openings of open meshes "
"(a scan, a garment) instead of their inside. Brushes then work only on faces you can see. Off by default; "
diff --git a/src/app/Palettes.cpp b/src/app/Palettes.cpp
index fddedf08..9468b2ab 100644
--- a/src/app/Palettes.cpp
+++ b/src/app/Palettes.cpp
@@ -742,6 +742,9 @@ void App::drawPalette_Render() {
ui::HelpAction(*this, "view.mask");
ImGui::Checkbox(tr("Show Face Groups##render"), &renderSettings_.showFaceGroups);
ui::HelpAction(*this, "view.facegroups");
+ if (ImGui::Checkbox(tr("Floor grid##render"), &renderSettings_.floorGrid))
+ uiPrefs_.floorGrid = renderSettings_.floorGrid; // (a preference: on in every session until turned off)
+ ui::HelpAction(*this, "view.floor_grid");
bool xray = renderSettings_.xray;
if (ui::Checkbox("X-Ray##render", &xray)) runCommand("xray", {{"on", xray}});
ui::HelpAction(*this, "view.xray");
@@ -998,6 +1001,9 @@ void App::drawPalette_Tool() {
"of open meshes (a scan, a garment) instead of their inside. Brushes then work only on faces you "
"can see. Off by default; saved automatically, projects keep their own.",
"Tool > Display");
+ if (ImGui::Checkbox(tr("Floor grid##display"), &renderSettings_.floorGrid))
+ uiPrefs_.floorGrid = renderSettings_.floorGrid;
+ ui::HelpAction(*this, "view.floor_grid");
ImGui::ColorEdit3(tr("Material colour"), &renderSettings_.baseColor.x, ImGuiColorEditFlags_NoInputs);
ui::HelpText("Material colour", nullptr, "Colour of the Studio material (the clay colour).", "Tool > Display");
drawShadingControls();
diff --git a/src/app/ProofMode.cpp b/src/app/ProofMode.cpp
index 9f53a8e1..0413b829 100644
--- a/src/app/ProofMode.cpp
+++ b/src/app/ProofMode.cpp
@@ -467,6 +467,9 @@ void App::startProofMode() {
return std::none_of(keep.begin(), keep.end(), [&](const std::string& k) { return !k.empty() && std::string(ph.name).find(k) != std::string::npos; });
});
}
+ // SF_BENCH_FLOOR_GRID=1: with View > Display > Floor grid on (#115), whatever the preferences say.
+ if (const char* grid = std::getenv("SF_BENCH_FLOOR_GRID"); grid && std::string(grid) == "1")
+ renderSettings_.floorGrid = true;
p->stage = p->cli ? ProofState::Stage::Announce : ProofState::Stage::Intro;
p->radiusBefore = radiusPx_;
p->strengthBefore = strength_;
diff --git a/src/app/Shell.cpp b/src/app/Shell.cpp
index 5e3d01c4..e0c0fceb 100644
--- a/src/app/Shell.cpp
+++ b/src/app/Shell.cpp
@@ -527,6 +527,12 @@ void App::registerShellActions() {
};
actions_.add(std::move(a));
}
+ add({"view.floor_grid", "Floor grid", ICON_LC_GRID_2X2,
+ "A faint grid on the floor the model stands on (its lowest point, Y up), fading into the distance: a "
+ "reference for perspective and lining up Parts; the red and blue lines are the X and Z axes. It moves when "
+ "a stroke or a move ends. Off by default; saved automatically.",
+ "Render", "", "", [this] { uiPrefs_.floorGrid = renderSettings_.floorGrid = !renderSettings_.floorGrid; },
+ [this] { return renderSettings_.floorGrid; }, nullptr});
flag("view.vertexpaint", "Paint", ICON_LC_PALETTE, "Render", "", &renderSettings_.showVertexPaint,
"Show vertex paint colours (off: plain material).");
// Shading (Material palette, Tool > Display): the scene's, and the active Part's own.
diff --git a/src/app/UiTest.cpp b/src/app/UiTest.cpp
index 3772ed00..9e593c17 100644
--- a/src/app/UiTest.cpp
+++ b/src/app/UiTest.cpp
@@ -114,6 +114,8 @@
// style_window_min (ImGui's minimum window height, unscaled px: 32 in every look),
// tablet_mouse_mode (Preferences > Tablet > Mouse mode),
// ui_mouse_x / ui_mouse_y (where ImGui sees the pointer), backface_culling, drawn_triangles,
+// floor_grid (View > Display > Floor grid), floor_grid_drawn (the 3D view drawn once more
+// now: 1 if it drew the grid), floor_height (the floor's y),
// viewport_cursor (the system cursor: 0 arrow, 1 text, 7 hand, 100 crosshair; #73),
// panel_drag_scrolls (left / middle drags that scrolled a panel, #100), panel_drag_scroll_y,
// drag_cursor (the same, at the end of the last button_drag, before letting go; #88),
@@ -1097,6 +1099,12 @@ double Demo::query(const std::string& name, bool& known) const {
return n;
}
if (name == "backface_culling") return app_.renderSettings_.backfaceCulling ? 1.0 : 0.0;
+ if (name == "floor_grid") return app_.renderSettings_.floorGrid ? 1.0 : 0.0;
+ if (name == "floor_height") return double(app_.renderSettings_.floorHeight); // (the visible Parts' lowest point)
+ if (name == "floor_grid_drawn") { // the 3D view drawn once more now: 1 if it drew the floor grid
+ app_.benchmarkDrawMs(0);
+ return app_.renderer_.floorGridDrawn() ? 1.0 : 0.0;
+ }
if (name == "xray") return app_.renderSettings_.xray ? 1.0 : 0.0;
if (name == "view_resolution") return double(app_.uiPrefs_.viewResolution);
if (name == "light_yaw") return double(app_.renderSettings_.lightYaw);
diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp
index a368ce16..e4712204 100644
--- a/src/render/Renderer.cpp
+++ b/src/render/Renderer.cpp
@@ -706,6 +706,57 @@ void main() {
}
)";
+// The floor grid (#115, View > Floor grid): one quad on the floor (y = RenderSettings::floorHeight) around the eye,
+// its lines drawn in the fragment shader. Three levels of 10x steps, the finest fading out as the view zooms out
+// (uBlend) so a zoom never pops; cells under a few pixels fade too (no moire at grazing angles), and all of it fades
+// with the distance from the eye. X (red) and Z (blue) mark the axes through the origin.
+const char* kFloorVS = R"(#version 330 core
+uniform mat4 uView;
+uniform mat4 uProj;
+uniform vec2 uCentre;
+uniform float uHalf;
+uniform float uFloor;
+out vec3 vWorld;
+void main() {
+ vec2 c = vec2(gl_VertexID & 1, gl_VertexID >> 1) * 2.0 - 1.0;
+ vWorld = vec3(uCentre.x + c.x * uHalf, uFloor, uCentre.y + c.y * uHalf);
+ gl_Position = uProj * (uView * vec4(vWorld, 1.0));
+}
+)";
+
+const char* kFloorFS = R"(#version 330 core
+in vec3 vWorld;
+out vec4 fragColor;
+uniform vec3 uEye;
+uniform float uStep; // the finest level's cell
+uniform float uBlend; // 0..1: how far the view has zoomed out of that level
+uniform float uFade; // the distance from the eye where the grid is gone
+uniform vec3 uLine;
+float lines(vec2 p, float step, float px) {
+ vec2 c = p / step;
+ vec2 w = max(fwidth(c), vec2(1e-6));
+ vec2 g = abs(fract(c - 0.5) - 0.5) / w; // distance to the nearest line, in pixels
+ float l = 1.0 - min(min(g.x, g.y) / px, 1.0);
+ return l * (1.0 - smoothstep(0.08, 0.3, max(w.x, w.y))); // cells under ~12 px fade out
+}
+void main() {
+ vec2 p = vWorld.xz;
+ float a = max(lines(p, uStep, 1.0) * 0.10 * (1.0 - uBlend), lines(p, uStep * 10.0, 1.0) * mix(0.22, 0.10, uBlend));
+ a = max(a, lines(p, uStep * 100.0, 1.2) * 0.22);
+ vec2 w = max(fwidth(p), vec2(1e-6));
+ float onX = 1.0 - min(abs(p.y) / w.y / 1.5, 1.0), onZ = 1.0 - min(abs(p.x) / w.x / 1.5, 1.0);
+ vec3 c = uLine;
+ float axis = max(onX, onZ) * 0.5;
+ if (axis > a) {
+ c = onX >= onZ ? vec3(0.86, 0.36, 0.36) : vec3(0.36, 0.55, 0.92);
+ a = axis;
+ }
+ a *= 1.0 - smoothstep(0.3 * uFade, uFade, distance(vWorld, uEye));
+ if (a < 1.0 / 255.0) discard;
+ fragColor = vec4(c, a);
+}
+)";
+
// The PBR view's environment behind the model: the view ray of each pixel into the prefiltered environment at
// the background's blur, exposed and tone mapped like the shading.
const char* kEnvBgFS = R"(#version 330 core
@@ -1242,6 +1293,8 @@ void Renderer::shutdown() {
envIndex_ = envFailedIndex_ = -1;
deleteProgram(envBgProgram_);
envBgProgram_ = 0;
+ deleteProgram(floorProgram_);
+ floorProgram_ = 0;
gl::DeleteVertexArrays(1, &emptyVao_);
for (MeshProgram& p : programs_) {
deleteProgram(p.id);
@@ -2992,6 +3045,8 @@ void Renderer::draw(const Camera& camera, int targetWidth, int targetHeight, con
previewOnly_ = stillWanted_ = false;
gl::Enable(GL_DEPTH_TEST);
gl::DepthFunc(GL_LEQUAL);
+ floorGridDrawn_ = false;
+ if (settings.floorGrid) drawFloorGrid(camera, view, proj, settings); // (under everything: the Parts paint over it)
if (drawList_.empty() || !settings.showMesh) {
if (settings.showSplats) drawSplats(view, proj, fbWidth, fbHeight, settings.splatOpacity);
gl::UseProgram(0);
@@ -3212,6 +3267,50 @@ void Renderer::cullCoarse(const MeshSlot& s, const CullView& frame, size_t budge
// Draws `clusters` of `s` (the VAO for `part` bound): their triangles, the wireframe's edges, or their motion
// proxies. One multi-draw, or with per-triangle data on a driver whose gl_VertexID lacks the base vertex, one
// draw per cluster with its first drawn triangle in `primBaseLocation`.
+// The floor grid (#115): drawn right after the background, before any Part, with no depth: every Part (and splat)
+// paints over it, so it never shows on the model, from above or below. Its cell is a power of ten of the zoom: 0.1
+// at the default view of a new model, 1 from ten times further out.
+void Renderer::drawFloorGrid(const Camera& camera, const glm::mat4& view, const glm::mat4& proj,
+ const RenderSettings& settings) {
+ if (thumbnailPass_) return;
+ if (!floorProgram_) {
+ std::string error;
+ floorProgram_ = link(kFloorVS, kFloorFS, error);
+ if (!floorProgram_) {
+ SDL_Log("Floor grid: %s", error.c_str());
+ return;
+ }
+ }
+ const glm::vec3 eye = glm::vec3(glm::inverse(view)[3]);
+ const float zoom = std::log10(std::max(camera.distance, 1e-4f)) - 0.3f, level = std::floor(zoom);
+ const float fade = std::max(camera.distance * 6.0f, std::abs(eye.y - settings.floorHeight) * 2.0f);
+ // Lines a little lighter than a dark background, darker than a light one.
+ const glm::vec3 bg = settings.gradientBackground ? settings.gradientCentre : settings.backgroundColor;
+ const float luma = glm::dot(bg, glm::vec3(0.2126f, 0.7152f, 0.0722f));
+ const glm::vec3 line = luma > 0.5f ? glm::vec3(0.08f) : glm::vec3(0.86f);
+ gl::UseProgram(floorProgram_);
+ auto at = [&](const char* n) { return gl::GetUniformLocation(floorProgram_, n); };
+ gl::UniformMatrix4fv(at("uView"), 1, GL_FALSE, glm::value_ptr(view));
+ gl::UniformMatrix4fv(at("uProj"), 1, GL_FALSE, glm::value_ptr(proj));
+ gl::Uniform2f(at("uCentre"), eye.x, eye.z);
+ gl::Uniform1f(at("uHalf"), fade);
+ gl::Uniform1f(at("uFloor"), settings.floorHeight);
+ gl::Uniform3fv(at("uEye"), 1, glm::value_ptr(eye));
+ gl::Uniform1f(at("uStep"), std::pow(10.0f, level - 1.0f));
+ gl::Uniform1f(at("uBlend"), zoom - level);
+ gl::Uniform1f(at("uFade"), fade);
+ gl::Uniform3fv(at("uLine"), 1, glm::value_ptr(line));
+ gl::BindVertexArray(emptyVao_);
+ gl::Disable(GL_DEPTH_TEST);
+ gl::Enable(GL_BLEND);
+ gl::BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ gl::Disable(GL_CULL_FACE);
+ gl::DrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+ gl::Disable(GL_BLEND);
+ gl::Enable(GL_DEPTH_TEST);
+ floorGridDrawn_ = true;
+}
+
void Renderer::drawClusters(const MeshSlot& s, const std::vector<uint32_t>& clusters, GLenum mode, DrawPart part, GLint primBaseLocation) {
drawCounts_.clear();
drawOffsets_.clear();
diff --git a/src/render/Renderer.h b/src/render/Renderer.h
index 5b0c9cb0..a0d5d705 100644
--- a/src/render/Renderer.h
+++ b/src/render/Renderer.h
@@ -49,6 +49,11 @@ struct RenderSettings {
// 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).
bool backfaceCulling = false;
+ // Floor grid (#115, View > Floor grid): a faint grid on the floor under the model (y = floorHeight, Y up; the
+ // app keeps it at the lowest point of the visible Parts), its X and Z axes through the origin, fading with
+ // distance. Drawn under every Part. Off by default.
+ bool floorGrid = false;
+ float floorHeight = 0.0f;
// The view's background: the charcoal radial gradient (default) or one flat display (sRGB) colour (#21).
bool gradientBackground = true;
glm::vec3 backgroundColor{0.168f, 0.168f, 0.168f};
@@ -252,6 +257,7 @@ public:
size_t microPendingShading() const;
// Triangles the last draw() sent to the GPU (after culling), for the benchmark.
size_t lastDrawnTriangles() const { return lastDrawn_; }
+ bool floorGridDrawn() const { return floorGridDrawn_; } // the last draw() drew the floor grid (tests)
// Coarse levels (tests): the clusters the last frame drew at a coarse level, and the edited clusters whose levels
// are still to be updated (drawn in full until then).
size_t coarseDrawnClusters() const { return lastCoarseClusters_; }
@@ -297,6 +303,8 @@ public:
std::vector<uint8_t>& rgba, std::string& error);
private:
+ void drawFloorGrid(const Camera& camera, const glm::mat4& view, const glm::mat4& proj,
+ const RenderSettings& settings);
void drawSplats(const glm::mat4& view, const glm::mat4& proj, int fbWidth, int fbHeight, float opacity);
GLuint wireProgram_ = 0, wireLineProgram_ = 0, bgProgram_ = 0, splatProgram_ = 0;
@@ -492,6 +500,8 @@ private:
bool keepBackfaces_ = false;
GLenum xrayCull_ = 0; // X-Ray's lone Part: the faces this pass culls (GL_FRONT, then GL_BACK) // X-Ray's lone see-through Part: draw its back faces too (cull)
GLuint envTexture_ = 0, brdfTexture_ = 0, envBgProgram_ = 0;
+ GLuint floorProgram_ = 0; // drawFloorGrid's, linked when the grid first shows
+ bool floorGridDrawn_ = false;
struct EnvJob;
std::shared_ptr<EnvJob> envJob_;
std::function<void()> envWake_;
diff --git a/tests/ui/floor_grid.sfui b/tests/ui/floor_grid.sfui
new file mode 100644
index 00000000..7cbf5176
--- /dev/null
+++ b/tests/ui/floor_grid.sfui
@@ -0,0 +1,108 @@
+# Floor grid (#115): View > Floor grid (also Tool > Display and the command palette) draws a faint grid on the floor
+# the model stands on (the lowest point of the visible Parts, Y up), the X and Z axes through the origin marked,
+# fading into the distance. It is drawn before the Parts, so it never shows on the model. Off by default; a preference.
+run ui_look look=forge layout=sculptforge
+run new_sphere subdivisions=4
+camera 30 -20
+wait 0.3
+expect_value floor_grid == 0
+remember drawn_triangles sphere_tris
+shot off
+expect_value floor_grid_drawn == 0
+
+click "View##menu.view"
+expect "Floor grid##render"
+click "Floor grid##render"
+expect_value floor_grid == 1
+shot view-menu
+key escape
+wait 0.3
+shot on
+expect_value floor_grid_drawn == 1
+# The starter sphere (centred on the origin) stands on the grid: the floor is at its bottom, not through its middle.
+expect_value floor_height < -0.9
+remember floor_height sphere_floor
+# The grid adds none of the model's triangles (it draws one quad of its own).
+expect_value drawn_triangles == $sphere_tris
+
+# Seen from above and from far away: the grid steps up by ten, and fades out at the edges.
+camera 30 -60
+wait 0.3
+shot above
+camera_distance 40
+wait 0.3
+shot far
+key f
+wait 0.3
+# From below the floor the whole model still shows: the grid only around it, never over it.
+camera 30 25
+wait 0.3
+shot below
+
+# A model moved below the origin: the floor follows once the move ends.
+camera 30 -20
+run transform translate=0,-3,0 masked=false
+key f
+camera 30 -20
+wait 0.3
+expect_value floor_height < -3.9
+shot below-origin
+key ctrl+z
+key f
+wait 0.3
+expect_value floor_height == $sphere_floor
+
+# A gizmo drag: the floor stays put during the drag and moves when it ends.
+key w
+gizmo_drag move_y 0 70 keep
+wait 0.2
+expect_value floor_height == $sphere_floor
+release
+wait 0.3
+expect_value floor_height < -1.1
+key ctrl+z
+key w
+expect_value gizmo_mode == 0
+wait 0.3
+
+# A plane: the floor is the plane itself, which covers the grid.
+run new_plane resolution=32
+camera 20 -25
+wait 0.3
+shot plane
+
+# A real model at an angle.
+run open path=$SCRIPT_DIR/../data/marble-bust.glb
+key f
+camera 35 -15
+wait 0.5
+shot bust
+
+# HiDPI: the lines stay one pixel wide (they're drawn per pixel, not scaled).
+run new_sphere subdivisions=4
+camera 30 -20
+ui_scale 200
+wait 0.3
+shot on-2x
+ui_scale 100
+
+# Kept after a restart; the command palette turns it off.
+restart
+expect_value floor_grid == 1
+key f3
+type "##Command palette" "floor grid"
+key enter
+expect_value floor_grid == 0
+wait 0.3
+shot palette-off
+expect_value floor_grid_drawn == 0
+restart
+expect_value floor_grid == 0
+
+# Tool > Display has the same switch.
+run ui_look look=classic layout=classic
+click "Tool##palette.tool"
+click "Display##tool.display"
+click "Floor grid##display"
+expect_value floor_grid == 1
+shot tool-display