Drawing
Streaming point clouds
A city scanned from the air holds billions of points, far more than a GPU can hold. A view needs only a part of them: every point near the camera, and far away just enough to fill the screen. This page explains the octree of samples that gives each view that part, how its nodes stream in and out of memory without popping, how points grow where the sample is sparse, and the LAS files scans come in. It builds on Point clouds (chunks and splats) and Tile streaming (the cut and the budget). The last part shows how RASM does it.
In short
- An octree of samples: the root keeps an even sample of the whole cloud; each child keeps an even sample of what its parent left in its cube. Drawing a node adds detail to its ancestors.
- A node keeps a point of each cell of a grid over its cube, the one nearest the cell's centre. So its spacing is about the cell's size, and each level is twice as fine.
- The cut: a node's children are wanted while its spacing on screen passes an error of a pixel or two. Near the camera the cut goes deep, far away the root alone fills the view.
- The nodes are tiles of a streamer under a byte budget: parents first, the nodes nobody wants dropped first.
- A node fades in by drawing a growing share of its points, and out before it is dropped, so nothing pops.
- Adaptive points grow where the sample is sparser than their size on screen, so the ground stays closed near the camera, and shrink back where a finer node fills in.
1A cloud bigger than memory
A point of a scan takes 8 to 12 bytes on the GPU (Storage). A billion points take 10 GB: more than most GPUs have, and the frame could not draw them anyway. The view needs much less. Look at the camera's own picture: a screen of 2 million pixels needs about 2 million points to be closed, wherever they come from.
2An octree of samples
An octree cuts a cube into eight, and each part into eight again. In a point cloud octree (Potree, Schütz et al. 2020) each node keeps some of the points of its cube, not all: an even sample. The root keeps a coarse sample of everything. A child keeps a sample of the points its parent left in its cube. Draw a node and its ancestors, and the points add up to a sample twice as fine as the node's parent alone.
A point a cell
A grid over the node's cube; of each cell's points it keeps the one nearest the centre. The rest go to its children.
Its spacing
The distance between its points is about a cell: its size over the grid's (128 cells a side, say). Each level halves it.
Leaves
A node with few points left (a few thousand) keeps them all and has no children. Its spacing is the data's own.
3Building it
The build reads every point once to sort it, then once per level. The trick is the same Morton order the chunks use (Level of detail by prefix), now of the whole cloud's cube: in that order, the points of any node of the octree, and of any cell of its grid, are one run of the list.
- The cube around all points. Each point's cell at the finest level, 221 a side, and its 63-bit Morton code. Sort by it.
- A node is a run of the sorted list. Its grid's cells are runs inside it: a change of the code's next bits starts a new one.
- Of each cell's run keep the point nearest the cell's centre. Move the others to the front, still in order.
- The rest splits into the eight children by the next three bits: eight runs. Build each the same way.
- Store each node's points as offsets from its cube's centre, in floats: exact to a tenth of a millimetre near the node, wherever the cloud is.
No point is copied twice and nothing is searched: the cost is the sort, then one pass per level. A grid that would keep too many points (a volume, like a tree's crown, fills far more cells than a surface) is made coarser, so a node never passes its maximum.
4The cut: spacing on screen
A node's spacing seen from the camera is its error on screen: how far apart its points are, in pixels. A node whose spacing on screen passes the error wants its children. The same rule as for tiles (Tile streaming), with the spacing as the geometric error:
error on screen = spacing × pixels per unit / distance
want the children while error on screen > ε
- spacing
- the node's, in world units; a leaf's error is 0: there is nothing finer
- distance
- from the camera to the nearest point of the node's bounding sphere (any distance for an orthographic view)
- ε
- the error allowed, in pixels: the spacing at which the points drawn just cover the ground
Choose ε so that a node at the edge of the cut is just closed at the points' size: for round points of 2 pixels that must cover the ground twice, ε = 2 × √(π/4 / 2) ≈ 1.25 pixels. A smaller ε draws more points for no visible gain; a larger one shows gaps, unless the points grow (Adaptive point size).
5Streaming under a budget
Each node is a tile of a streamer with additive refinement: drawn with its parents once it is in, its parents drawn while it is on the way. The streamer does the rest as for any tiles: it ranks the wanted nodes by error, loads the largest first, keeps them under the byte budget, and drops the nodes nobody wants, the oldest first.
A node is a chunk
When it is handed out, its points become a chunk (16-bit steps of its box) on a worker thread, and an entity at its cube's centre.
Under the budget
Parents load first and stay longest. What does not fit waits, and its parent covers its place.
Where the bytes are
A node in GPU memory takes 8 B a point, 12 with colors. The octree itself stays in CPU memory, all of it.
Builder threads below the main thread
The main thread hands the new nodes to the builder threads and wakes them. On Windows a woken thread gets a short priority boost, and the scheduler may run it on the core of the thread that woke it: the main thread then waits, ready but not running, until the build ends. So run the builders one step below the main thread's priority: a woken builder then takes a free core, and the main thread goes on.
notify_all. With the builders at THREAD_PRIORITY_BELOW_NORMAL the update's longest is 0.6 ms.6Fading in and out
A node that appears at once adds a whole level of points in one frame: the ground gets finer in a block, and the eye sees it. A node that is dropped at once does the reverse. The fix uses the chunks' prefix order (Level of detail by prefix): any first share of a chunk's points is an even sample, so a node can draw a share that grows from 0 to all of them over a few tenths of a second. Before it is dropped it shrinks back to 0, kept wanted until then.
At once
The density doubles in one frame, over the node's whole cube.
By its prefix
The node draws a share of its points that grows each frame: an even sample, finer each frame.
7Adaptive point size
Points of a fixed size close the ground only where the sample is dense enough on screen. Near the camera a leaf's points may be several pixels apart: the data has no finer level, and fixed points leave gaps. An adaptive point grows with its node's spacing on screen, so the points cover the ground there too, and keeps its size far away, where they already cover it.
Far: fixed size
Spacing on screen under a pixel or two: the points keep their size.
Near: fixed size
The leaf's points are many pixels apart: the background shows through.
Near: adaptive
Grown to the spacing on screen, the same points close the ground.
How large? Random points leave gaps wider than their mean spacing: points that cover the ground c times on average leave a share e−c of it open, 13 % at 2, under 2 % at 4. So the size starts to grow where the points stop covering the ground density times (the level of detail's own rule, How many points a chunk keeps), and grows faster from there, so near the camera they cover it about 4 times:
covering = spacing on screen × √(density / a)
grown = size + √(4 / density) × max(covering − size, 0)
diameter = min(grown, largest)
- a
- a point's area over its diameter squared: 1 for a square, π/4 for a disc
- size
- the points' own size in pixels; points that already cover the ground keep it
- largest
- a clamp in pixels: a sample sparser than that shows its gaps
The spacing is measured as the cell size at which the points take half as many cells as there are points: a little more than the mean spacing for a random sample (1.2 times), as such a sample has gaps wider than its mean. The lab uses that factor.
One more rule keeps grown points from covering detail. A parent's points grow over the parts of its cube where no finer node is drawn, but where a child is drawn the child's points are finer. So each node tells its points, per octant of its cube, how far the child there has faded in, and a point there shrinks back to the base size by that share. Together the child's points and the parent's shrinking ones never cover less than either alone did.
8LAS and LAZ files
Scans come as LAS files (ASPRS): a header, variable length records, then fixed-size point records. LAZ is the same, the points compressed. A position is three 32-bit integers times the file's scale plus its offset, in doubles: millimetres stay exact even for Earth-centred coordinates of six million metres.
| Point format | Bytes | GPS time | RGB | Notes |
|---|---|---|---|---|
| 0 | 20 | — | — | positions, intensity, returns, class |
| 1, 2, 3 | 28, 26, 34 | 1, 3 | 2, 3 | |
| 4, 5 | 57, 63 | yes | 5 | with waveform packets |
| 6, 7, 8 | 30, 36, 38 | yes | 7, 8 | LAS 1.4: a byte of 4-bit return numbers, a full byte for the class; 8 adds near infrared |
| 9, 10 | 59, 67 | yes | 10 | 1.4 with waveform packets |
Colors are 16 bits a channel by the specification, but many files store 8-bit values in them: a reader takes the high byte, or the values as they are when none passes 255. A projected file (UTM and the like) has z up; an Earth-centred one (ECEF) has the Earth's axis as z.
9Pitfalls
- Points pop in a block as the camera moves
- A node shows all its points in one frame. Fade it in by its prefix, and keep it wanted while it fades out.
- Dark specks on the ground near the camera
- Points of a fixed size over a sparse sample. Let them grow with the spacing on screen, or lower the cut's error until finer nodes come in.
- Big blobs over fine detail
- A coarse node's grown points over a place where a finer node is drawn. Shrink a node's points per octant as its child fades in.
- Huge discs at the edge of the data
- A node with a few scattered points measures a large spacing. They are no surface: never let a node's spacing pass its parent's.
- A frame stalls a few milliseconds when loads start
- A worker woken at the main thread's priority took its core. Run the workers below the main thread's priority.
- Everything loads, the budget is always full
- An error too small for the data: every node within view wants its leaves. Raise it, or let adaptive points close the gaps.
- The scene jitters far from the origin
- Points kept in floats in world units. Keep them as offsets from their node's centre, and the node in doubles.
10In RASM
RASM gives the pieces and the application drives them, as for any tiles: AssetLoader::loadPointCloud reads the file, buildPointCloudOctree builds the octree on any thread, each node is a TileStreamer tile with TileRefine::ADD, and the application walks the cut, builds the handed-out nodes' chunks on its threads and sets their fades with Renderer::setPointChunkLod. examples/29_point_streaming does all of it.
| This page | RASM |
|---|---|
| A grid over the node's cube | PointCloudOctreeDesc::cells, 128 a side; coarser for a node that would keep more than maxNodePoints (16 384). A node with no more points left is a leaf with all of them (up to MAX_POINT_CHUNK_POINTS). |
| The spacing | Measured from the node's points: the cell size at which they take half as many cells as there are points (1.2 times a random sample's mean spacing, 1.4 times a grid's step), never more than the parent's (PointCloudNode::spacing). A leaf's geometricError is 0. |
| The cut | The application's: example 29 wants a node's children while TileStreamer::getScreenError passes 1.25 pixels, and while they fade out. |
| The budget | TileStreamer: a point chunk's bytes are its share of the point pool (RendererConfig::geometryPoolPoints), and the pool's units are a limit of their own. Mesh::pointOrder (2 B a point) is in CPU memory and not counted. |
| Fades | PointChunkLod::drawn, through Renderer::setPointChunkLod: the cull keeps that share of the prefix the level of detail chose (selectPointCount). Example 29 fades over 0.35 s. |
| Adaptive size | PointSizeMode::ADAPTIVE with PointMaterial::maxSize; the chunk's spacing is in its header, times the entity's scale. POINT_ADAPTIVE_COVER (4) is the cover near the camera. |
| Shrink per octant | PointChunkLod::finer, per octant of the entity's space, which is the node's cube around its centre. |
| LAS and LAZ | AssetLoader::loadPointCloud: RASM's own reader for LAS 1.0 to 1.4, formats 0 to 10; LAZ through LASzip (Apache-2.0, vcpkg's laszip). |
Measured with example 29 (Release, RTX 3060, a perspective view with TAA and an orthographic one with 4× MSAA): a synthetic scan of 8 M points written as LAS, 1 km across near Paris in ECEF, a flight at 14 m/s and 45 m over the ground.
At 1920 × 1080 the two views take 5.1 ms of GPU frame with adaptive points (5.9 ms when only points of 2 pixels or less took the compute path, P33), 3.3 ms with fixed ones, which leave the ground open. The rest of the difference is the grown points' pixels: near the camera they pass the compute path's 8 pixels, and in the top view, with 4× MSAA, the compute path takes only points of 2 pixels or less, so the coarse nodes' grown points there are triangles. Example 29 sets PointMaterial::density to 3, so the top view's random ground leaves 0.06 % of its pixels open instead of 0.2 %, for 0.4 ms. The images show no pop as nodes come and go: the frames where nodes appear or go change no more pixels than the frames where none do.
Code map
| What | Where |
|---|---|
| The octree and its build | include/rasm/pointCloudOctree.h, src/scene/pointCloudOctree.cpp |
| Spacing, Morton codes | measurePointSpacing, spreadMortonBits in src/scene/pointCloud.cpp (src/scene/pointCloudInternal.h) |
| Fades and finer shares | Renderer::setPointChunkLod (src/scene/entity.cpp), read by getPointDrawnShare and getPointFinerShare in shaders/lib/points.slang |
| Adaptive size | getPointDiameter in shaders/lib/points.slang, used by shaders/passes/points.slang, shaders/passes/pointRaster.slang and the cull (isRasterChunk) |
| The point pool in the budget | TileUnit::POINTS in src/scene/tileResidency.h, src/scene/tileStreamer.cpp |
| LAS and LAZ | src/assets/pointCloudLoad.cpp, cmake/Findlaszip.cmake |
| The example | examples/29_point_streaming/main.cpp |
PointChunkLod::finer are that space's. The octree must outlive every chunk built from it. The streamer's budget must stay under RendererConfig::geometryPoolPoints: the pool is fixed. A change to how a point is sized goes through getPointDiameter alone, so the cull, the triangles and the compute path agree.Further reading: M. Schütz, S. Ohrhallinger, M. Wimmer, Fast Out-of-Core Octree Generation for Massive Point Clouds (2020); ASPRS, LAS Specification 1.4 R15 (2019); M. Isenburg, LASzip: lossless compression of LiDAR data (2013).