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.

Floor grid (#115): View > Floor grid draws a faint grid on the ground plane through the world origin

islandmed24663b234268
diff --git a/changes/feat-floor-grid.md b/changes/feat-floor-grid.md
new file mode 100644
index 00000000..de6cd9f5
--- /dev/null
+++ b/changes/feat-floor-grid.md
@@ -0,0 +1,13 @@
+---
+whats_new: **Floor grid**: **View > Floor grid** draws a faint grid on the floor through the world origin, 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
+ ground plane through the world origin (Y up), X and Z axes marked, squares stepping by ten with the zoom and fading
+ into the distance. 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.
+ - Any OS: File > New Plane with the grid on: the plane covers the grid, no flicker. Restart: the grid is still on.
+---
+The grid sits at the world origin (y = 0), not at the model's lowest point: stable while sculpting, and it is the
+plane exports line up to (#115 asks "where the model sits relative to the origin").
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 52a397de..0c4b2bb2 100644
--- a/docs/guide/navigation.md
+++ b/docs/guide/navigation.md
@@ -79,6 +79,11 @@ 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 through the world origin, with the up axis (Y) standing on it: it shows where the model stands, helps
+judge perspective and tilt, and lines up Parts before an export. The red line is the X axis, the blue one Z. The
+squares step up by ten as you zoom out, and the grid fades into the distance; the model always draws in front of it.
+
"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/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 f9a96722..1aac1d88 100644
--- a/src/app/Config.cpp
+++ b/src/app/Config.cpp
@@ -134,6 +134,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));
@@ -226,6 +227,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);
@@ -1033,6 +1035,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 15d308f7..a9c05f83 100644
--- a/src/app/Config.h
+++ b/src/app/Config.h
@@ -93,6 +93,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 16f5f687..5f28ad19 100644
--- a/src/app/I18nSimplifiedChinese.cpp
+++ b/src/app/I18nSimplifiedChinese.cpp
@@ -1480,6 +1480,11 @@ constexpr Entry kSimplifiedChinese[] = {
{"Tool > Remesh", "工具 > 重新网格化"},
{"Cut", "切割"},
{"Selection Sets", "选择集"},
+ {"Floor grid", "地面网格"},
+ {"A faint grid on the floor through the world origin (Y up), fading into the distance: where the model stands, "
+ "and a reference for perspective and lining up Parts. Off by default; saved automatically.",
+ "一个穿过世界原点(Y 轴向上)的淡淡地面网格,向远处渐隐:显示模型站在哪里,也是判断透视和对齐部件的参考。默认关闭;"
+ "自动保存。"},
{"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 2289a7f4..29b96cc4 100644
--- a/src/app/I18nSpanish.cpp
+++ b/src/app/I18nSpanish.cpp
@@ -1709,6 +1709,12 @@ 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 through the world origin (Y up), fading into the distance: where the model stands, "
+ "and a reference for perspective and lining up Parts. Off by default; saved automatically.",
+ "Una cuadrícula tenue en el suelo, por el origen del mundo (Y hacia arriba), que se desvanece a lo "
+ "lejos: dónde se apoya el modelo, y una referencia para la perspectiva y para alinear Piezas. 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 2c4a040c..1695d24e 100644
--- a/src/app/I18nTraditionalChinese.cpp
+++ b/src/app/I18nTraditionalChinese.cpp
@@ -1480,6 +1480,11 @@ constexpr Entry kTraditionalChinese[] = {
{"Tool > Remesh", "工具 > 重新網格化"},
{"Cut", "切割"},
{"Selection Sets", "選取集"},
+ {"Floor grid", "地面網格"},
+ {"A faint grid on the floor through the world origin (Y up), fading into the distance: where the model stands, "
+ "and a reference for perspective and lining up Parts. Off by default; saved automatically.",
+ "一個穿過世界原點(Y 軸向上)的淡淡地面網格,向遠處漸隱:顯示模型站在哪裡,也是判斷透視和對齊部件的參考。預設關閉;"
+ "自動儲存。"},
{"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 542a065f..52bd7d17 100644
--- a/src/app/Palettes.cpp
+++ b/src/app/Palettes.cpp
@@ -713,6 +713,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");
@@ -961,6 +964,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/Shell.cpp b/src/app/Shell.cpp
index 17fc28b7..ce34cd08 100644
--- a/src/app/Shell.cpp
+++ b/src/app/Shell.cpp
@@ -527,6 +527,11 @@ void App::registerShellActions() {
};
actions_.add(std::move(a));
}
+ add({"view.floor_grid", "Floor grid", ICON_LC_GRID_2X2,
+ "A faint grid on the floor through the world origin (Y up), fading into the distance: where the model "
+ "stands, and a reference for perspective and lining up Parts. 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 c1bc0541..bedadb34 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),
// 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),
@@ -1090,6 +1092,11 @@ 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_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 d2e01566..d13aa335 100644
--- a/src/render/Renderer.cpp
+++ b/src/render/Renderer.cpp
@@ -706,6 +706,56 @@ void main() {
}
)";
+// The floor grid (#115, View > Display > Floor grid): one quad on the ground plane y = 0 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 origin.
+const char* kFloorVS = R"(#version 330 core
+uniform mat4 uView;
+uniform mat4 uProj;
+uniform vec2 uCentre;
+uniform float uHalf;
+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, 0.0, 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 +1292,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,7 +3044,9 @@ 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 (drawList_.empty() || !settings.showMesh) {
+ if (settings.floorGrid) drawFloorGrid(camera, view, proj, settings);
if (settings.showSplats) drawSplats(view, proj, fbWidth, fbHeight, settings.splatOpacity);
gl::UseProgram(0);
return;
@@ -3020,6 +3074,7 @@ void Renderer::draw(const Camera& camera, int targetWidth, int targetHeight, con
if (const MeshSlot* s = findSlot(item.id); s && s->drawnTriangles > 0 && !seeThrough(item))
drawSlot(*s, item.active, item.flat, settings);
drawMark(2);
+ if (settings.floorGrid) drawFloorGrid(camera, view, proj, settings); // (over the opaque Parts, under X-Ray's)
if (xray) {
gl::Enable(GL_BLEND);
gl::BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@@ -3212,6 +3267,53 @@ 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): over the opaque Parts (depth tested, never written, pushed a little behind a surface on the
+// plane itself), under see-through ones. 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) * 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::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::Enable(GL_DEPTH_TEST);
+ gl::DepthMask(GL_FALSE);
+ gl::Enable(GL_BLEND);
+ gl::BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ gl::Disable(GL_CULL_FACE);
+ gl::Enable(GL_POLYGON_OFFSET_FILL);
+ gl::PolygonOffset(2.0f, 2.0f); // (the Parts draw at 1, 1: a plane mesh at y = 0 stays in front)
+ gl::DrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+ gl::PolygonOffset(1.0f, 1.0f);
+ gl::Disable(GL_BLEND);
+ gl::DepthMask(GL_TRUE);
+ 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 6667440c..24477467 100644
--- a/src/render/Renderer.h
+++ b/src/render/Renderer.h
@@ -49,6 +49,9 @@ 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 > Display): a faint grid on the ground plane through the world origin (y = 0, Y up),
+ // fading with distance. Off by default.
+ bool floorGrid = false;
// 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 +255,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_; }
@@ -289,6 +293,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;
@@ -481,6 +487,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..afe014a5
--- /dev/null
+++ b/tests/ui/floor_grid.sfui
@@ -0,0 +1,71 @@
+# Floor grid (#115): View > Display > Floor grid (also Tool > Display and the command palette) draws a faint grid on
+# the ground plane through the world origin (y = 0), fading into the distance. 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 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 grid draws over what is above it (a ceiling seen through), still faint.
+camera 30 20
+wait 0.3
+shot below
+
+# A plane on the floor itself stays in front of the grid.
+run new_plane resolution=32
+camera 20 -25
+wait 0.3
+shot plane
+
+# 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