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.

Guide pages for material painting and export presets; texture memory in Performance and perf_info; phase 0 scaffolding headers

islandmed5ce7e8814d35
diff --git a/docs/guide/export-presets.md b/docs/guide/export-presets.md
new file mode 100644
index 00000000..02384d02
--- /dev/null
+++ b/docs/guide/export-presets.md
@@ -0,0 +1,80 @@
+# Export presets
+
+**Export Maps** writes a texture's channels ([Material painting](pbr-painting.md)) as the image files a game engine
+or DCC expects: which files, what they are called and how channels are packed into them come from an **export
+preset**. SculptForge has presets for the common targets, and you can write your own as a small JSON file.
+
+## Export maps
+
+1. Open **Tool > Texture Map**. Under **Material Channels**, choose a preset in the list next to **Export
+ Maps...** (hover a preset for what it writes).
+2. Click **Export Maps...** and pick a folder. The files are named after the SubTool.
+
+From a script or the console: `export_maps preset=unreal folder=/path/to/maps name=Rock`.
+`export_maps list=true` lists the presets and their maps.
+
+Channels you haven't turned on export their default value (roughness 0.65, metallic 0, flat normal, AO 1), so a
+preset always writes a complete set. Maps marked optional below are written only when one of their channels is on.
+
+## Built-in presets
+
+| Preset | Files (for a SubTool called Rock) | Normal |
+| --- | --- | --- |
+| `unreal` | `T_Rock_BC` (base colour; opacity in alpha when painted), `T_Rock_N`, `T_Rock_ORM` (R occlusion, G roughness, B metallic); optional `T_Rock_E` (emissive), `T_Rock_H` (16-bit height) | DirectX |
+| `unity_urp` | `Rock_BaseMap`, `Rock_Normal`, `Rock_MetallicSmoothness` (R metallic, A smoothness = 1 - roughness); optional `Rock_Occlusion`, `Rock_Emission`, `Rock_Height` | OpenGL |
+| `unity_hdrp` | `Rock_BaseMap`, `Rock_Normal`, `Rock_MaskMap` (R metallic, G occlusion, B detail mask = white, A smoothness); optional `Rock_Emission`, `Rock_Height` | OpenGL |
+| `gltf` | `Rock_baseColor`, `Rock_normal`, `Rock_occlusionRoughnessMetallic` (R, G, B as glTF expects); optional `Rock_emissive` | OpenGL |
+| `godot` | `Rock_albedo`, `Rock_normal`, `Rock_orm`; optional `Rock_emission`, `Rock_height` | OpenGL |
+| `blender` | One file per channel: `Rock_BaseColor`, `Rock_Roughness`, `Rock_Metallic`, `Rock_Normal`; optional `Rock_Height` (16-bit), `Rock_AO`, `Rock_Emission`, `Rock_Alpha` | OpenGL |
+| `usd` | One file per UsdPreviewSurface input: `Rock_diffuseColor`, `Rock_roughness`, `Rock_metallic`, `Rock_normal`; optional `Rock_occlusion`, `Rock_emissiveColor`, `Rock_opacity`, `Rock_displacement` | OpenGL |
+
+All files are PNG at the texture's size: 8-bit, except height maps, which are 16-bit greyscale. The normal map is
+the effective normal: the Normal channel with the height's normal combined in. DirectX presets flip green.
+
+**Send to Unreal** ([Exporting](exporting.md#send-to-unreal)) uses the `unreal` preset and then builds a material
+`M_<Name>` in Unreal from the maps: BC to Base Color, ORM's R / G / B to Ambient Occlusion, Roughness and Metallic,
+N to Normal, E to Emissive. It is an ordinary Unreal material you can edit.
+
+## Material slots in model files
+
+You don't need Export Maps to get the material into a model file: when the texture has material channels,
+exporting a model writes the maps beside it (or inside it) and wires them into its material.
+
+| Format | What the material gets |
+| --- | --- |
+| glTF / GLB | Base colour (alpha from opacity, `alphaMode` BLEND), `metallicRoughnessTexture` and `occlusionTexture` from one packed map, `normalTexture`, `emissiveTexture` |
+| USD / USDZ | A UsdPreviewSurface whose `roughness`, `metallic`, `normal`, `occlusion`, `emissiveColor` and `opacity` inputs each read their own map (raw colour space; the normal with scale 2, bias -1) |
+| OBJ | The MTL's PBR keys: `map_Pr` (roughness), `map_Pm` (metallic), `norm` / `map_Bump` (normal), `map_Ke` (emission), `map_d` (opacity) |
+| FBX | Textures on the material's NormalMap, ShininessExponent (roughness), ReflectionFactor (metallic), EmissiveColor and TransparencyFactor, as Blender reads them |
+
+A texture without material channels exports exactly as before: just the colour.
+
+## Your own presets
+
+A preset is a JSON file. Point `export_maps preset=` at it:
+
+```json
+{
+ "label": "Studio packed",
+ "file": "{name}_{map}",
+ "normal": "directx",
+ "maps": [
+ {"map": "albedo", "channels": ["base_color.r", "base_color.g", "base_color.b", "opacity?"]},
+ {"map": "rma", "channels": ["roughness", "metallic", "ao"]},
+ {"map": "nrm", "channels": ["normal.r", "normal.g", "normal.b"]},
+ {"map": "disp", "channels": ["height"], "bits": 16, "optional": true}
+ ]
+}
+```
+
+- **file**: the file name pattern; `{name}` is the object name, `{map}` the map's name (required). `.png` is added.
+- **normal**: `opengl` (green up, the default) or `directx` (green down).
+- **maps**: 1 to 32 maps. Each has a **map** name (letters, digits, `-` and `_`) and 1 (grey), 3 (RGB) or 4
+ (RGBA) **channels**.
+- A channel source is a channel name (`roughness`, `metallic`, `ao`, `height`, `opacity`), a component
+ (`base_color.r`, `normal.g`, `emissive.b`), `smoothness` (1 - roughness), a constant (`0`, `1`, `0.5`) or
+ `1-` in front of any of them to invert it.
+- A `?` after a source drops that component when its channel isn't on (an RGBA map becomes RGB).
+- **optional**: write the map only when one of its channels is on. **bits**: 8 (default) or 16.
+
+A preset with a mistake is refused with a message saying what is wrong.
diff --git a/docs/guide/exporting.md b/docs/guide/exporting.md
index 7d679cbb..079c14e8 100644
--- a/docs/guide/exporting.md
+++ b/docs/guide/exporting.md
@@ -132,6 +132,7 @@ Python remote execution.
| Several visible SubTools | One FBX model per SubTool, combined into one asset on import |
| Any | A material slot `M_Clay`, and the real-world size from **Height** |
| A baked normal map ([Tool > Bake](baking.md)) | The texture `T_<Name>_N`, set up as a normal map (Unreal on this computer only) |
+| A texture with [material channels](pbr-painting.md) | `T_<Name>_BC`, `T_<Name>_N` (DirectX) and `T_<Name>_ORM` (occlusion, roughness, metallic), plus `T_<Name>_E` when emissive is painted, and a material `M_<Name>` built from them and assigned to the mesh (Unreal on this computer only; see [Export presets](export-presets.md)) |
Sending the same asset again updates it in place (same name and folder), so references in your levels stay
intact.
diff --git a/docs/guide/images/pbr-brush-material.jpg b/docs/guide/images/pbr-brush-material.jpg
new file mode 100644
index 00000000..231047a0
Binary files /dev/null and b/docs/guide/images/pbr-brush-material.jpg differ
diff --git a/docs/guide/images/pbr-solo-roughness.jpg b/docs/guide/images/pbr-solo-roughness.jpg
new file mode 100644
index 00000000..82599615
Binary files /dev/null and b/docs/guide/images/pbr-solo-roughness.jpg differ
diff --git a/docs/guide/index.md b/docs/guide/index.md
index 6a712cab..2045c79c 100644
--- a/docs/guide/index.md
+++ b/docs/guide/index.md
@@ -30,37 +30,39 @@ You can read it inside SculptForge (**Help > User Guide**, or <kbd>Shift</kbd>+<
12. [ZSpheres](zspheres.md)
13. [Polypaint and materials](polypaint.md)
14. [Texture painting](texture-painting.md)
-15. [Sculpt layers and blend shapes](layers.md)
-16. [Facial shapes and live face](facial-shapes.md)
-17. [Subdivision levels](subdivision-levels.md)
-18. [Dynamic topology](dynamic-topology.md)
-19. [Moving, rotating and posing (Gizmo 3D)](gizmo.md)
-20. [Subdivide, remesh, decimate and LODs](geometry.md)
-21. [Quad retopology and detail projection](retopology.md)
+15. [Material painting (PBR)](pbr-painting.md)
+16. [Sculpt layers and blend shapes](layers.md)
+17. [Facial shapes and live face](facial-shapes.md)
+18. [Subdivision levels](subdivision-levels.md)
+19. [Dynamic topology](dynamic-topology.md)
+20. [Moving, rotating and posing (Gizmo 3D)](gizmo.md)
+21. [Subdivide, remesh, decimate and LODs](geometry.md)
+22. [Quad retopology and detail projection](retopology.md)
## AI and capture
-22. [Image and text to 3D](generate-3d.md)
-23. [Gaussian splats](splats.md)
-24. [Scan an object into a splat](scan-to-splat.md)
-25. [From scan to sculptable mesh](scan-to-sculptable.md)
-26. [Phone capture and AR](phone-capture.md)
+23. [Image and text to 3D](generate-3d.md)
+24. [Gaussian splats](splats.md)
+25. [Scan an object into a splat](scan-to-splat.md)
+26. [From scan to sculptable mesh](scan-to-sculptable.md)
+27. [Phone capture and AR](phone-capture.md)
## Files and pipelines
-27. [Baking normal and displacement maps](baking.md)
-28. [Exporting, Unreal and ZBrush](exporting.md)
-29. [Working with Blender](blender.md)
-30. [Projects, autosave and QuickSave](projects.md)
-31. [Scripting and automation](scripting.md)
-32. [SculptForge for studios](studios.md)
+28. [Baking normal and displacement maps](baking.md)
+29. [Exporting, Unreal and ZBrush](exporting.md)
+30. [Export presets](export-presets.md)
+31. [Working with Blender](blender.md)
+32. [Projects, autosave and QuickSave](projects.md)
+33. [Scripting and automation](scripting.md)
+34. [SculptForge for studios](studios.md)
## Reference
-33. [Keyboard and mouse](shortcuts.md)
-34. [Performance and big meshes](performance.md)
-35. [Troubleshooting and FAQ](troubleshooting.md)
-36. [Glossary](glossary.md)
+35. [Keyboard and mouse](shortcuts.md)
+36. [Performance and big meshes](performance.md)
+37. [Troubleshooting and FAQ](troubleshooting.md)
+38. [Glossary](glossary.md)
## Getting help
diff --git a/docs/guide/pbr-painting.md b/docs/guide/pbr-painting.md
new file mode 100644
index 00000000..a0f765a6
--- /dev/null
+++ b/docs/guide/pbr-painting.md
@@ -0,0 +1,113 @@
+# Material painting (PBR)
+
+A painted texture can carry more than colour. Turn on **material channels** and the Paint brush paints how rough,
+how metallic, how bumpy and how bright the surface is, all in one stroke, the way game engines and renderers
+describe materials (physically based rendering, PBR). Every channel lives on the same UVs and paint layers as the
+colour from [Texture painting](texture-painting.md), and goes out to Unreal, Unity, Godot, Blender, glTF and USD
+with [Export presets](export-presets.md).
+
+![Solo roughness view: a glossy horizontal stroke on Base and a rough vertical stroke on a layer](images/pbr-solo-roughness.jpg)
+
+## The channels
+
+| Channel | What it holds | Stored as |
+| --- | --- | --- |
+| Base Color | The surface colour. Always there. | 8-bit sRGB (the texture you already paint) |
+| Roughness | 0 is mirror-like, 1 fully matte. Starts at 0.65. | 8-bit |
+| Metallic | 0 for paint, stone, skin, plastic; 1 for bare metal. Starts at 0. | 8-bit |
+| Normal | Fine surface direction, a tangent-space normal map (OpenGL, green up). Starts flat. | 8-bit RGB |
+| Height | Painted relief, 0.5 = none. Also adds to the normal ("height to normal"). | 16-bit |
+| Ambient Occlusion | How much light reaches crevices, 1 = open. | 8-bit |
+| Emissive | Light the surface gives off, black = none. | 8-bit sRGB |
+| Opacity | 1 = opaque. Exported in the base colour's alpha. | 8-bit |
+
+A channel you turn on costs no memory until you paint it: channels are stored as 64 x 64 tiles, and a tile nobody
+painted is not stored at all (a tile of one value is stored as that one value). Turning a channel off discards
+what was painted in it; **Undo** brings it back.
+
+## Turn channels on
+
+1. Give the SubTool a texture ([Texture painting](texture-painting.md)).
+2. Open **Tool > Texture Map**. Under **Material Channels**, tick the channels you want (for a typical game asset:
+ Roughness, Metallic and Normal; add Height to paint relief, Ambient Occlusion to paint dirt into crevices).
+3. **Channel memory** below the ticks shows what the painted tiles use; the same number, for every SubTool, is in
+ **Preferences > Performance** under Memory.
+
+## Paint a material
+
+Open the **Color** palette. With a material texture, a **Material** section appears under the swatches:
+
+![Color > Material: material swatches, and per channel a tick, value swatches and a slider; Material Channels in Tool > Texture Map](images/pbr-brush-material.jpg)
+
+
+- **Material swatches** set the colour, roughness and metallic at once (bare metal, gold, copper, rust, gloss
+ paint, rubber, stone, clay) and make the brush paint those channels.
+- One row per channel: the tick says whether the brush paints that channel; the five grey squares pick 0, 25,
+ 50, 75 or 100%; the slider sets any value. Normal has two tilt sliders (0, 0 paints a flat normal). Emissive
+ has a colour.
+
+Untick Base Color to paint only roughness (a wet patch, a polished edge) without touching the colour. Every
+stroke is one undo step for all the channels it painted. The brush's falloff, alpha, pen pressure, symmetry and
+mask apply to every channel alike; erasing (<kbd>Alt</kbd>) paints Base back to each channel's default and makes
+layers transparent.
+
+**C over the model picks the whole material**: the colour and every channel under the cursor become the brush
+material, and the brush then paints all of the texture's channels.
+
+## Layers and channels
+
+Paint layers ([Texture painting](texture-painting.md#paint-layers-on-a-texture)) hold every channel. In **Tool >
+Paint Layers**, each layer row gets a row of **channel chips** (BC, R, M, N, H, AO, E, Op):
+
+- **Click** a chip to turn that channel of the layer on or off. A rust layer can carry colour and roughness but
+ leave metallic alone; a scratches layer can affect only the normal.
+- **Right-click** a chip for the channel's **blend mode** and **opacity**. The ten paint-layer blend modes work
+ per channel (Multiply on roughness halves it where you paint, Screen brightens AO...). The Normal channel adds
+ **Normal Combine**, which lays the layer's normal detail onto the normals below instead of replacing them.
+ A chip with a `*` uses a blend mode other than Normal or less than full opacity.
+- The layer's own opacity, visibility and lock apply to all its channels.
+
+Merge down and Flatten keep the look of every channel. Duplicate copies a layer with its channels.
+
+## See one channel on its own
+
+**Tool > Texture Map > Normal view** opens a list: pick **Solo Roughness** (or any enabled channel) and the model
+shows just that channel, in grey for roughness, metallic, height, AO and opacity, as colours for the normal (with
+the height's normal in it) and in colour for emissive. Painting updates it live. Pick **Normal view** to go back.
+The viewport doesn't yet render the channels together as a lit PBR material; the solo view is how you check
+them for now.
+
+## Height and normals
+
+Height is stored with 16 bits, so slow ramps don't band. Its slope becomes a normal that is combined onto the
+Normal channel (Normal Combine) wherever a normal is shown or exported, so painting height also gives the shading
+detail. `texture_channels height_normal_strength=4` sets how steep that normal is (0: height adds no normal).
+
+## Carrying channels through geometry changes
+
+Auto UV, Voxel Remesh, QRemesh and merging SubTools move every channel and every layer's channels onto the new
+UVs, as they do the colour. A part without a channel takes that channel's default when SubTools merge.
+
+## Projects
+
+Projects with material channels are saved as format 7 (SculptForge 0.10 and later opens them). A project without
+material channels is still saved as format 6, so older versions keep opening it. Older projects open as they did.
+
+## Commands
+
+| Command | What it does |
+| --- | --- |
+| `texture_channels enable=roughness,metallic,normal` | Turn channels on (`disable=...` off; no arguments lists them) |
+| `paint_material roughness=0.2 metallic=1 color=c0c0c8` | Set the brush material; `channels=all` / `channels=roughness` say exactly what it paints |
+| `texture_layer_channel channel=normal blend=normal_combine` | A layer's channel settings (`enabled`, `blend`, `opacity`; `layer` or `index`) |
+| `channel_view channel=roughness` | Solo a channel in the viewport (`off` to go back) |
+| `export_maps preset=unreal folder=...` | Write the maps ([Export presets](export-presets.md)) |
+
+## Limitations
+
+- The viewport shows one channel at a time (solo view); a lit PBR preview with environment lighting is planned.
+- Fill layers, generators (edge wear, dirt), mesh-map bakes as layer inputs, filters and material recipes are
+ planned; today the stack is paint layers.
+- One texture per SubTool (no UDIM tiles yet).
+- Memory: a fully painted 8K channel set is large (see Performance); paint at 4K and export at 4K unless you need
+ 8K.
diff --git a/docs/guide/texture-painting.md b/docs/guide/texture-painting.md
index 4a74c009..9927c48c 100644
--- a/docs/guide/texture-painting.md
+++ b/docs/guide/texture-painting.md
@@ -8,6 +8,9 @@ symmetry, mask and paint layers with blend modes.
![Texture painting: a sharp texture stroke above a soft polypaint stroke, with the UV view in Tool > Texture Map](images/texture-painting.jpg)
+> The texture can also carry roughness, metallic, normal, height, AO, emission and opacity, painted in the same
+> strokes: see [Material painting (PBR)](pbr-painting.md).
+
## Start in one click
Press <kbd>P</kbd> for the Paint brush (or turn on **Rgb**). While the SubTool has no texture, **New Texture**
diff --git a/src/app/PanelPerformance.cpp b/src/app/PanelPerformance.cpp
index 12609854..e72d414c 100644
--- a/src/app/PanelPerformance.cpp
+++ b/src/app/PanelPerformance.cpp
@@ -169,12 +169,14 @@ void App::drawPerformanceSection() {
ImGui::TextUnformatted("Memory");
ui::HelpText("Memory", nullptr,
"What the scene holds: the meshes with their topology, the BVHs, the subdivision levels kept for "
- "stepping between them, the undo history (Edit keeps up to 1 GB, dropping the oldest steps) and the "
+ "stepping between them, the undo history (Edit keeps up to 1 GB, dropping the oldest steps), painted textures "
+ "with their layers and material channels (only painted 64x64 tiles of a channel use memory), and the "
"GPU buffers of the visible SubTools.",
kPath);
const MemoryUse m = documentMemory(doc_);
const std::string mem = "Meshes " + megabytes(m.mesh) + " BVH " + megabytes(m.bvh) + "\nSubdivision levels " +
megabytes(m.levels) + "\nUndo " + megabytes(m.undo) + " of " + megabytes(doc_.undo.byteBudget) +
+ "\nTextures " + megabytes(m.textures) + " (material channels " + megabytes(m.channels) + ")" +
"\nGPU buffers about " + megabytes(m.gpu);
ImGui::TextUnformatted(mem.c_str());
ImGui::LogText("%s", mem.c_str());
diff --git a/src/core/Benchmark.cpp b/src/core/Benchmark.cpp
index 393722e5..9952dbe8 100644
--- a/src/core/Benchmark.cpp
+++ b/src/core/Benchmark.cpp
@@ -9,6 +9,7 @@
#include "core/Polypaint.h"
#include "core/Primitives.h"
#include "core/Project.h"
+#include "core/Texture.h"
#include "core/ThreadPool.h"
#include "core/UploadOrder.h"
@@ -66,11 +67,17 @@ size_t peakResidentBytes() {
MemoryUse documentMemory(const Document& doc) {
MemoryUse u;
+ std::vector<const PaintTexture*> seen; // textures shared between SubTools count once
for (int i = 0; i < doc.subtoolCount(); ++i) {
const bool active = i == doc.activeSubtool;
const SubTool& st = doc.subtools[size_t(i)];
const Mesh& m = doc.subtoolMesh(i);
u.mesh += m.memoryBytes();
+ if (m.texture && std::find(seen.begin(), seen.end(), m.texture.get()) == seen.end()) {
+ seen.push_back(m.texture.get());
+ u.textures += m.texture->bytes();
+ u.channels += channelBytes(*m.texture);
+ }
u.bvh += (active ? doc.bvh : st.bvh).memoryBytes();
u.levels += subdivBytes(m);
u.undo += (active ? doc.undo : st.undo).undoBytes();
@@ -96,7 +103,8 @@ void registerPerformanceCommands(CommandRegistry& registry) {
(ThreadPool::shared().serial() ? " (multithreading off)" : "") + "; " +
millions(double(u.triangles)) + " triangles; memory " + mb(u.total()) + " (meshes " +
mb(u.mesh) + ", BVH " + mb(u.bvh) + ", subdivision levels " + mb(u.levels) +
- ", undo " + mb(u.undo) + "), GPU buffers about " + mb(u.gpu);
+ ", undo " + mb(u.undo) + ", textures " + mb(u.textures) + " of which material channels " +
+ mb(u.channels) + "), GPU buffers about " + mb(u.gpu);
return {true, msg};
}});
registry.add({"set_multithreading",
diff --git a/src/core/Benchmark.h b/src/core/Benchmark.h
index 985d040d..73b106e9 100644
--- a/src/core/Benchmark.h
+++ b/src/core/Benchmark.h
@@ -83,8 +83,10 @@ struct MemoryUse {
size_t levels = 0; // subdivision level stacks (subdivBytes)
size_t undo = 0; // undo history (UndoStack::undoBytes)
size_t gpu = 0; // vertex and index buffers the renderer keeps for the visible SubTools (an estimate)
+ size_t textures = 0; // painted textures (core/Texture.h): colour, layers, material channels (each texture once)
+ size_t channels = 0; // of `textures`, the material channel tiles (core/TextureChannels.h)
size_t triangles = 0, vertices = 0;
- size_t total() const { return mesh + bvh + levels + undo; }
+ size_t total() const { return mesh + bvh + levels + undo + textures; }
};
MemoryUse documentMemory(const Document& doc);
diff --git a/tests/test_texture_channels.cpp b/tests/test_texture_channels.cpp
index f4cd6794..a4af2bb4 100644
--- a/tests/test_texture_channels.cpp
+++ b/tests/test_texture_channels.cpp
@@ -7,6 +7,7 @@
// what a 5-channel dab costs next to a base-colour dab.
#include "TestHarness.h"
+#include "core/Benchmark.h"
#include "core/Commands.h"
#include "core/Primitives.h"
#include "core/Texture.h"
@@ -17,6 +18,7 @@
#include <cmath>
#include <cstdio>
#include <cstdlib>
+#include <filesystem>
using namespace sf;
@@ -484,3 +486,107 @@ TEST(material_dab_cost_against_base_colour_dab) {
CHECK(ms[0] > 0 && ms[1] > 0);
if (std::getenv("SF_BENCH_LIMITS")) CHECK(ms[1] <= 2.5 * ms[0]);
}
+
+TEST(material_dense_mesh_benchmark) {
+ // Dense meshes (SF_BENCH_DENSE=1; minutes and several GB): 4K and 8K textures on a 330k, a 5.2M and a 21M
+ // triangle sphere with UVs; per size the base-colour dab and the 5-channel dab (small and big brush, X
+ // symmetry), export_maps with the unreal preset, and the memory of 5 channels on Base plus 3 layers.
+ if (!std::getenv("SF_BENCH_DENSE")) {
+ std::printf(" (set SF_BENCH_DENSE=1 to run the dense-mesh material benchmark)\n");
+ return;
+ }
+ const uint32_t five = channelBit(Channel::BaseColor) | channelBit(Channel::Roughness) | channelBit(Channel::Metallic) |
+ channelBit(Channel::Height) | channelBit(Channel::AO);
+ auto now = [] { return std::chrono::steady_clock::now(); };
+ auto ms = [](auto a, auto b) { return std::chrono::duration<double, std::milli>(b - a).count(); };
+ std::printf(" tris / tex / radius: colour dab ms, 5-channel dab ms (ratio)\n");
+ for (int level : {7, 9, 10}) {
+ const auto tb = now();
+ // One mesh per size, shared by every measurement (a 21M copy would cost gigabytes).
+ Document doc;
+ {
+ Mesh made = makeIcosphere(level);
+ sphericalUvs(made);
+ doc.setMesh(std::move(made));
+ }
+ doc.syncBvh();
+ Mesh& base = doc.mesh;
+ const BVH& bvh = doc.bvh;
+ std::printf(" %zu triangles (built in %.1f s, RSS %.2f GB)\n", base.triangleCount(), ms(tb, now()) / 1000.0,
+ double(residentBytes()) / 1e9);
+ for (int size : {4096, 8192}) {
+ for (float radius : {0.05f, 0.35f}) {
+ double t[2] = {0, 0};
+ for (int pass = 0; pass < 2; ++pass) {
+ Mesh& m = base;
+ m.texture = makeTexture(size, size);
+ m.paintToTexture = true;
+ BrushMaterial mat = rustyMetal();
+ mat.channels = pass ? five : channelBit(Channel::BaseColor);
+ if (pass)
+ for (Channel c : {Channel::Roughness, Channel::Metallic, Channel::Height, Channel::AO}) setChannelEnabled(*m.texture, c, true);
+ TexturePainter painter;
+ CHECK(painter.begin(m, mat.channels));
+ DabParams p = dab(glm::vec3(0, 0, 1), radius, 0.5f);
+ p.viewDir = glm::vec3(0, 0, -1);
+ painter.dab(m, bvh, p, mat, Symmetry{true, false, false}); // warm-up (first touch of the tiles)
+ for (int i = 0; i < 10; ++i) {
+ p.center = glm::normalize(glm::vec3(-0.15f + 0.03f * float(i), 0.2f, 1.0f));
+ const auto t0 = now();
+ painter.dab(m, bvh, p, mat, Symmetry{true, false, false});
+ t[pass] += ms(t0, now());
+ }
+ UndoRecord rec;
+ painter.end(rec);
+ t[pass] /= 10.0;
+ }
+ std::printf(" %5.1fM / %dK / %.2f: %7.2f ms, %7.2f ms (%.2fx)\n", double(base.triangleCount()) / 1e6, size / 1024,
+ radius, t[0], t[1], t[1] / t[0]);
+ }
+ // Memory: 5 channels, Base plus 3 layers, each with a big stroke on every channel; then one layer painted
+ // everywhere (its tiles all dense), and export_maps of the result.
+ doc.mesh.texture.reset();
+ const size_t rss0 = residentBytes();
+ doc.mesh.texture = makeTexture(size, size);
+ doc.mesh.paintToTexture = true;
+ for (Channel c : {Channel::Roughness, Channel::Metallic, Channel::Height, Channel::AO}) setChannelEnabled(*doc.mesh.texture, c, true);
+ for (int layer = -1; layer < 3; ++layer) {
+ if (layer >= 0) addTextureLayer(*doc.mesh.texture, "Layer " + std::to_string(layer + 1));
+ TexturePainter painter;
+ BrushMaterial mat = rustyMetal();
+ mat.channels = five;
+ CHECK(painter.begin(doc.mesh, five));
+ DabParams p = dab(glm::vec3(0, 0, 1), 0.35f, 0.5f);
+ p.viewDir = glm::vec3(0, 0, -1);
+ for (int i = 0; i < 8; ++i) {
+ p.center = glm::normalize(glm::vec3(-0.3f + 0.08f * float(i), 0.1f * float(layer), 1.0f));
+ painter.dab(doc.mesh, doc.bvh, p, mat, Symmetry{true, false, false});
+ }
+ UndoRecord rec;
+ painter.end(rec);
+ }
+ const PaintTexture& tex = *doc.mesh.texture;
+ const size_t strokes = channelBytes(tex), all = tex.bytes(), rss1 = residentBytes();
+ // One layer fully painted: every tile of its four channels dense.
+ PaintTexture& wt = *doc.mesh.texture;
+ for (int c = 1; c < kChannelCount; ++c) {
+ TileImage& img = wt.layers[0].channels[size_t(c)].image;
+ if (!img.valid()) continue;
+ for (size_t ti = 0; ti < img.tileCount(); ++ti) img.writableTile(ti);
+ }
+ const size_t full = channelBytes(wt), rss2 = residentBytes();
+ const auto e0 = now();
+ CommandRegistry reg;
+ const auto dir = std::filesystem::temp_directory_path() / "sf_dense_export_maps";
+ const CommandResult r = reg.execute(doc, "export_maps", {{"preset", std::string("unreal")}, {"folder", dir.string()}});
+ const double exportMs = ms(e0, now());
+ CHECK(r.ok);
+ std::filesystem::remove_all(dir);
+ doc.mesh.texture.reset();
+ std::printf(" %dK, 5 channels x (Base + 3 layers), strokes: channels %.0f MB, texture %.0f MB, RSS +%.0f MB; "
+ "one layer fully painted: channels %.0f MB, RSS +%.0f MB; export_maps unreal %.0f ms\n",
+ size / 1024, double(strokes) / 1e6, double(all) / 1e6, double(rss1 - std::min(rss0, rss1)) / 1e6,
+ double(full) / 1e6, double(rss2 - std::min(rss0, rss2)) / 1e6, exportMs);
+ }
+ }
+}