Drawing

Point clouds

A laser scanner (LiDAR) or a photo survey gives millions of points: a position each, often a color or a value such as height or intensity. There are no triangles to draw. This page explains how to draw such a cloud fast: small splats on the screen, compact storage, a cheap level of detail, and colormaps that turn values into colors. The last part shows how RASM does it.

In short

  • Each point is a splat: a small square, disc or sphere on the screen, a few pixels or a few centimetres wide.
  • Points come in chunks of up to 65 536 near each other. A chunk stores each position as three 16-bit steps of its box: 8 bytes a point with a value, 12 with a color.
  • A point is one triangle around its square; the pixel stage cuts it to its shape.
  • Small points skip the triangle (up to 6 pixels in a perspective view, 4 in an orthographic one, 2 under MSAA): a compute pass writes each pixel with a 64-bit max of depth and point, two (6 pixels) to twelve (1 pixel) times faster per point, and a resolve puts them into the scene. Both paths take the same pixels, in every shape.
  • The builder puts a chunk's points in an order where every prefix is an even sample. A chunk small on screen draws only its first points: level of detail with no extra data.
  • A colormap turns a value into a color through a range (linear or logarithmic) and a 256-entry texture.

1Splats: what a point looks like

A point has no size. To see it, the renderer draws a small shape at its place, a splat. Three shapes cover most uses.

Square

The cheapest. At 1 or 2 pixels every shape looks like this anyway.

Round

A disc. Its edge is smooth with several samples per pixel.

the overlap follows the spheres

Sphere

A disc that writes a sphere's depth: overlapping points meet along a curve, as solid balls would.

The size is in pixels (the same on screen at every distance) or in metres (smaller when far away). A splat is never less than one pixel wide, so a far point neither vanishes nor flickers.

2One triangle a point

The usual splat is a quad: two triangles, four corners. But for points of one or two pixels the cost is per point (the corners and the triangle setup), not per pixel. One triangle that holds the square costs one setup instead of two; the pixel stage cuts it back to the square or the disc.

a quad: 2 triangles 4 corners, 2 triangle setups one triangle, cut to the shape (-1, -1) (3, -1) (-1, 3) cut: outside the square or the disc 3 corners, 1 triangle setup
Corner c of point p is vertex 3p + c. The shaded part of the triangle is drawn and cut; at 1 or 2 pixels that is almost nothing.
12–16 %faster than a quad3.3 M and 6.8 M points a frame, RTX 3060
1.07 nsper point drawnalmost the same for 1 and 2 pixel points
3 %for writing the depththe sphere shape's cost, measured on every point

3Small points by compute

A triangle costs the same setup whether it covers 4 pixels or 400. For points of 1 or 2 pixels almost all the time goes there, not into the pixels. A compute shader can skip the triangle: one thread takes a point, finds the pixels its shape covers, and writes them itself (Schütz, Kerbl and Wimmer, 2021). For bigger points the pixels take over, and at about 7 pixels the triangles win (below).

The hard part is the depth test, which the triangle path gets for free. Many threads write the same pixel at once, in any order. The trick: put the depth and the point in one 64-bit word and keep the largest with a 64-bit atomic max (InterlockedMax in Slang). With reversed-Z a nearer point has a larger depth, so the max is the nearest point, whatever order the threads ran in.

a pixel's word, 64 bits depth (float bits, reversed-Z) instance row point bits 63 – 32: compared first bits 31 – 0: a tie goes to the larger, as a later triangle A 0.40 B 0.62 C 0.30 three points, 2 pixels wide atomicMax a thread a point, any order A A A B each pixel keeps the nearest C is behind A wherever they meet, A behind B; a pixel no point reached keeps 0: the far plane
The word holds the point, not its color: the color is found once per pixel, after the last write, instead of once per point.

Then a resolve draws a quad over the pixels the points can reach. Each pixel reads its word, finds the point, and writes its color, its depth and its motion into the scene's targets, with the normal depth test. So meshes in front of a point still hide it, and everything drawn later (labels, the grid, see-through draws, TAA) sees the points like any other surface.

time, one view Cull 1 reset, add early batches Scene 1 meshes Hi-Z Cull 2 late batches, then clear + raster Scene 2 meshes, resolve, then the sky Labels, Transparent a word a pixel compute passes on top, draw passes below; a frame without the late half (no Hi-Z) rasters in Cull 1 and resolves in Scene 1

Which chunk takes which path

The cull pass decides per chunk, after it chose the chunk's prefix. A chunk goes to compute when both hold:

perspective view: sc ≤ 6 and sn ≤ 8 pixels

orthographic view: s ≤ 4 pixels

view with MSAA: sn ≤ 2 pixels

and k × max(sc² / 4, 1) ≥ 0.125 × (its rect on screen, in pixels)

sc, sn
the points' size at the chunk's centre, and at its point nearest the camera: the largest they get (in an orthographic view the two are the same)
k
the points the chunk draws (its prefix)
rect
its box's corners on screen, and sn pixels more (at least 2): where its points can land

The first rule is measured. A thread writes its point's pixels one after another, so the compute path pays for every pixel of every point; the triangle path pays a setup per point, and its early depth test throws away a hidden pixel cheaply. The cost of one more point, every point drawn (no LOD, so many points cover each pixel), one perspective view of 1920 × 1080 with one sample a pixel (28_point_cloud --all-points, 10 M against 20 M points, RTX 3060):

point size1 px2 px3 px4 px6 px8 px
triangles, round1.03 ns1.07 ns1.39 ns1.99 ns3.58 ns5.53 ns
compute, round0.088 ns0.26 ns0.45 ns0.79 ns1.73 ns3.02 ns
triangles, square1.44 ns2.09 ns3.75 ns5.84 ns
compute, square0.58 ns1.02 ns2.20 ns3.88 ns

Per point the compute path's lead shrinks from 12 times at 1 pixel to under 2 times at 8. Under 3 pixels every shape is a square; a disc has fewer pixels than its square, and a SPHERE point costs what a disc does (its depth at each pixel is a square root and a division more). But at the LOD's density each pixel holds few points, the triangles' depth test has less to throw away, and the compute path also clears and resolves its rect. A whole frame of points of one size decides:

perspective view: a frame of points of one size 3 px 4 px 5 px 6 px 7 px 8 px 2.2 ms 2.7 ms 3.2 ms takes up to 6 orthographic view (looking down) 3 px 4 px 5 px 6 px 7 px 8 px 2.5 ms 3.1 ms 3.7 ms takes up to 4 compute pathtrianglesGPU frame, 28_point_cloud, 1920 x 1080, RTX 3060; the other view by triangles
The perspective view is cheaper by compute up to 6 pixels (0.8 ms less at 4) and costs the same at about 7; the orthographic view looking down at the ground, where every point of a chunk has one size and most lie on one surface, costs the same at about 5. So a chunk takes the compute path up to 6 pixels at its centre (8 at its nearest point) in a perspective view and up to 4 in an orthographic one.

Under MSAA the triangles' edges cover samples by their distance, and the compute path has one sample a pixel: there it takes only the points that cover whole pixels on both paths, of 2 pixels or less, so an MSAA view draws bigger points as before.

The second rule is the cost per pixel: once the compute path runs it also clears and resolves every pixel of the rect its chunks cover, so a sparse chunk spread over the screen is cheaper as triangles. A point of sc pixels counts as (sc / 2)² points of 2 pixels: it covers as many pixels. A chunk the camera is inside of, or that is partly behind it, stays triangles too.

Step the points in and change the order the threads ran in: the pixels end the same, each holding the nearest point (4 and 5 tie, and 5 wins as the later triangle would). The orange triangle is the one the triangle path draws for the chosen point; it keeps the pixels whose centre is in the dashed square, the same ones.

Why the two paths draw the same pixels

A chunk can switch paths from one frame to the next as the camera moves, so the two must agree to the pixel, or the switch would show. Both cut a point to the same shape (getPointShape: a square under 3 pixels, from 3 pixels its style's square, disc or sphere) and take a pixel when its centre lies in that shape, edges included, and both place the shape at the same centre: the compute path snaps it to 1/256 of a pixel, as the rasterizer snaps a triangle's corners. A SPHERE point's centre is its front's, as its triangle's, and its depth at each pixel is its surface's, from the same function on both paths (getSphereDepth). A pixel whose centre falls exactly on the shape's border goes as the rasterizer sends it: kept on the left and right sides and on the top, left out on the bottom, which is the triangle's own bottom side (the top-left rule). With the hole fill off, the compute path's perspective view in 28_point_cloud then differs from the triangles' in 0.012 % of its pixels for squares of 2 pixels, 0.016 % for squares of 3, 2 pixels for discs of 4 and for spheres of 5: centres a rounding away from a border. Under MSAA the compute path has one sample a pixel and the resolve writes it into all of the pixel's samples; in a view that also has the compute path, the triangle path covers whole pixels the same way, its triangle reaching half a pixel past the square so no sample of a covered pixel falls outside it. (A view drawn by triangles only keeps the smaller triangle, which is a fifth cheaper under MSAA; see Not yet.)

Filling the LOD's holes

The LOD keeps about as many points as the pixels a chunk covers, so a few pixels of a surface stay empty, and with whole pixels each shows as a single black dot (0.04 % of the top view of 28_point_cloud). The resolve fills them: an empty pixel takes the nearest of its 8 neighbours' points when at least 6 of them hold one, their depths are within 5 % of each other, and that point's chunk was thinned by the LOD.

8 neighbours, one depth: filled past an edge, 3 neighbours: left empty two depths (near, far): left empty
So a hole inside a surface closes, a silhouette does not grow, and a gap between two surfaces stays. A chunk that draws all its points shows the data's own gaps, as the triangles do. It costs 0.025 ms for the two views of 28_point_cloud; the top view ends with no hole (main: 0.001 %, its alpha-to-coverage dimmed them), the perspective view with 0.025 % (main: 0.027 %).
10.6×faster per point, 1 pixel0.081 ns against 0.86 ns by triangles, all of 33.5 M points a frame
4.1×faster per point, 2 pixels0.28 ns against 1.14 ns by triangles
2.1×faster per point, 6 pixels1.73 ns against 3.58 ns by triangles, round, every point, one view
8 Ba pixel, per view16.6 MB at 1920 × 1080, cleared only in the rect

4Storage: 16 bits in a chunk's box

Points near each other share a box. Inside it, a position needs far less than three 32-bit floats: 16 bits per axis is a step of 1/65 535 of the box, 0.5 mm for a 32 m box. A value (height, intensity, temperature) gets 16 bits too, in steps of the chunk's range of values.

header, 48 B box, value range, count x y z v 8 B a point, 16 bits each … RGBA8 colors 4 B a point, if any position = corner + step × (x, y, z) The same point as floats: 12 B for the position and 4 for the value or the color, 16 B in all.
8 Ba point with a valueagainst 16 B as floats
12 Ba point with a colorthe color as RGBA8, sRGB
0.5 mmstep in a 32 m box32 m / 65 535

The box also gives the chunk's bounding sphere, so a chunk is culled like any object: out of the view, or behind something in the depth of the frame before. The chunk is placed in the world by a transform in doubles, so a cloud far from the origin keeps its precision (large worlds).

5Level of detail by prefix

A chunk far away covers few pixels, and drawing all its points would put many on the same pixel. The cheap fix: draw only its first k points. That works only if the first k points are spread over the whole chunk, for every k. A scanner writes points line by line, and a random shuffle clumps. The builder sorts the points along a Morton curve (a path that visits every small square before the next one), then reads that list in bit-reversed steps.

  1. Quantize the positions to 16 bits in the box.
  2. Interleave the bits of x, y and z: the Morton code. Sort by it.
  3. For i = 0, 1, 2, … take sorted[reverse(i)], the bits of i reversed (0, P/2, P/4, 3P/4, …).
  4. The first 2j points are every P/2j-th point along the curve: one in each region.
Slide the prefix down to 64 points in each order. Only the Morton order read in bit-reversed steps keeps a point in every cell; rows leave most of the chunk out and random points clump.

The level of detail costs no memory: no second copy of the points, no tree. Its limit is that a chunk is one unit: a very large chunk near the camera draws all of its points even where part of it is far. Small chunks (tens of metres) keep that error small; for whole datasets the chunks become the nodes of an octree (Streaming point clouds).

6How many points a chunk keeps

The chunk keeps enough points to cover its square on screen a few times. With D the diameter of its sphere on screen and a a point's area in pixels:

k = min(N, ⌈density × D2 / a⌉)

a = s2 (square), or π/4 × s2 (round, sphere)

D
pixels per unit at the sphere's nearest point × its diameter
s
the point's size in pixels, at least 1; a size in metres is converted at the same depth, so it cancels the distance
density
how many times the points should cover the chunk's square; 0 keeps them all
Move the chunk away (a smaller D) and watch it keep fewer points. Set the density to 1 and to 0.5 to see holes open, and switch to one sample per pixel: a hole is a pixel whose samples no point covers.

Measured on a synthetic scan (4 M points, chunks of 32 m, round points of 2 pixels, a top view at 4× MSAA, RTX 3060), all by triangles:

densitypoints drawn a framescene passempty pixels on the ground, top view
0.51.49 M1.63 ms6.5 %
12.44 M2.60 ms0.3 %
2 (default)3.76 M3.99 ms0 %
45.44 M5.81 ms0 %
0 (all)7.02 M7.65 ms0 %

The π/4 matters: a disc covers less than its square. Without it, a density of 1 keeps as many points as 0.785 does with it, and leaves 1.3 % of the ground empty.

7Colormaps: values to colors

A value becomes a color in two steps: the range turns it into t from 0 to 1, and a 256 × 1 texture turns t into a color, read with linear filtering between its entries.

minmax value t = (value − min) / (max − min) log: the same with ln of each 256 texels, sRGB, read at (t × 255 + 0.5) / 256 t = 0 and 1 are the first and last texels' centres

Perceptually even

viridis, magma, inferno, plasma and cividis change lightness evenly, so equal steps of the value look like equal steps. cividis also reads for color-blind viewers.

Turbo

A smooth rainbow: more distinct hues, good for heights, but its lightness goes up and down.

Gray

Lightness only, for intensity scans.

8Anti-aliasing and motion

MSAA: coverage from the distance

The shader turns the distance to the disc's edge into a coverage (alpha-to-coverage): half the samples of an edge pixel, a smooth rim. Points of 2 pixels or less have no rim to smooth: they cover whole pixels, all samples, on both paths, so a dense cloud shows no background through partly covered pixels.

TAA: the centre's motion

the centre's motion, every pixel

The projection's jitter moves the splat; every pixel of it writes the motion of the point's centre, so the history follows the point. The compute path projects with the same jittered matrix, and its resolve writes the same motion.

9Pitfalls

A far chunk is a stripe or a corner of itself
Its points are in scan order, so a prefix is a part. Build the chunk in a Morton order read in bit-reversed steps.
Holes in a surface at a distance
Too few points for the chunk's size on screen. Raise the density, or the point size.
Holes close to the camera
The data is that sparse: every point is drawn. Use a size in metres about the points' spacing.
A chunk changes look when it changes path
The compute path and the triangles take different pixels, or round a centre differently. Use one rule for both: a pixel whose centre is in the square, the centre snapped as the rasterizer snaps corners.
A small cloud costs more by compute
The clear and the resolve cost per pixel. Send a chunk to compute only when it draws enough points for the pixels it covers, and clear and resolve only that rect.
Round points vanish at 1 or 2 pixels
A disc that small misses the pixel centres it covers. Draw points under 3 pixels square.
Steps in the positions far from the origin
The points were floats in world space. Keep them as small offsets in their chunk, and the chunk's place in doubles.
Colors look washed out or too dark
The colormap's entries are sRGB; store them in an sRGB texture so the read gives linear color.

10In RASM

A chunk is a mesh made by buildPointCloudChunk, on any thread, and uploaded by Renderer::createMesh. An entity draws it with a MaterialType::POINTS material, whose PointMaterial gives the size, the shape, the colors and the density. The entity's transform places the chunk; culling, render space far from the origin and picking work as for any entity. Each view sends its small, dense chunks to the compute path where the GPU has 64-bit buffer atomics (shaderBufferInt64Atomics); RendererConfig::computePoints or Renderer::setComputePoints(false) draws every point by triangles.

Pixel sizes in an export In a tiled export's pipelines (RASM_EXPORT_VIEW) sizes given in pixels are multiplied by SceneData::pixelScale (getPixelScale), its ExportDesc::pixelScale, which also divides the LOD's pixels per unit; in every other view it is 1 and the shaders do no work for it. Sizes in metres do not change.
any thread buildPointCloudChunk 16-bit steps, Morton order, bit-reversed: a MeshBuild createMesh point pool: header + points geometry row: sphere, 3 shared indices a point GPU, every view Cull: frustum, Hi-Z, selectPointCount then the path: isRasterChunk triangles: points.slang or compute: pointRaster.slang, atomics, then the resolve The point run comes after the opaque and MASK runs and before the blend run. It has its own pipeline per sample count; the depth-only views of shadows draw no points. Glyph chunks ride in it too.
This pageRASM
SplatsPointShape SQUARE, ROUND (default), SPHERE; PointMaterial::size in VectorUnit::PIXELS or METRES, at least a pixel; round points under 3 pixels are drawn square (getPointShape, the same on both paths). Unlit. PointSizeMode::ADAPTIVE grows them where the chunk's spacing on screen leaves gaps, up to PointMaterial::maxSize (Adaptive point size).
One triangle a pointgfx::POINT_INDICES (3). The chunks share one index range 0, 1, 2, …, taken from the index pool with the first chunk. One pipeline for every shape writes its depth with SV_DepthLessEqual, so the early depth test still works.
16 bits in the boxgfx::PointChunkHeader (48 B, with the chunk's spacing, given or measured) in the point pool (RendererConfig::geometryPoolPoints, 8 B units, 8 MiB by default); the chunk's GeometryData::vertexOffset is its first unit.
Prefix LODselectPointCount in shaders/lib/points.slang, called by the cull pass for the point run (SceneData::pointRun), the one place that decides what a chunk draws. PointMaterial::density is 2 by default. lodErrorPixels 0 draws every point; the forced LOD k (F2) draws N / 2k.
ColormapsRenderer::createColormap from 1 to COLORMAP_SIZE linear colors or a ColormapPreset; PointColorMode::SCALAR reads it through PointMaterial::range (ScalarRange); COLOR takes the points' own colors.
Small points by computeThe cull pass sends a chunk to shaders/passes/pointRaster.slang when isRasterChunk (shaders/lib/points.slang) holds: in a perspective view points of POINT_RASTER_MAX_SIZE (6) pixels or less at the chunk's centre and POINT_RASTER_MAX_NEAR (8) at its nearest point, in an orthographic view POINT_RASTER_MAX_ORTHO (4), under MSAA (SceneData::depthSamples) POINT_PIXELS_MAX_SIZE (2); at least POINT_RASTER_MIN_DENSITY (0.125) drawn points of 2 pixels per pixel of its rect, instance row under 65 536. rasterPoint cuts each point to getPointShape's shape, a SPHERE point's depth per pixel from getSphereDepth, as points.slang does. appendPointBatches adds batches of POINT_BATCH_POINTS (1024) and grows the rect. After the last cull: clearMain, rasterMain (indirect); the resolve quad in the last draw pass, before the sky. A view's buffer (SceneView::pointRaster, getPointRasterLayout): a 48 B header, 8 B a batch, 8 B a pixel.
MSAA and TAAAlpha-to-coverage with more than one sample, but points of 2 pixels or less (POINT_SHAPE_PIXELS) cover whole pixels on both paths (the compute path's resolve writes every sample); the centre's motion with TAA, on both paths.
PickingAlways by triangles, which take the same pixels as the compute path. A pick pipeline of the point run: PICK_HIT_POINT, and PickHit::feature is the point's index in the arrays given to the builder (Mesh::pointOrder maps it back). PICK_SKIP_POINTS looks through them.
The point run's other chunksGlyph chunks (a GLYPHS material) sit in the same run, so no draw run was added for them. The cull pass sends them to the glyph cull (appendGlyphChunk), they take no slot, and the point pipeline never draws them (Instanced glyphs). The same colormaps and ScalarRange color glyphs and data lines.
8 Ba point, 12 with colors+ 48 B a chunk; 2 B a point on the CPU for picks
3.6 Mpoints a frame from 50 M28_point_cloud --points 50000000, two views at 1920 × 1080
0.081 nsper small point, by computeRTX 3060, Release: 33.5 M points of 1 pixel in 3.31 ms; 0.86 ns by triangles

Code map

WhatWhere
The APIPointCloudChunkDesc, buildPointCloudChunk, MAX_POINT_CHUNK_POINTS in include/rasm/pointCloud.h; PointMaterial in include/rasm/material.h; ScalarRange, ColormapPreset in include/rasm/colormap.h; rasm_build_point_cloud_chunk, rasm_create_colormap in C
The buildersrc/scene/pointCloud.cpp
Colormapssrc/scene/colormap.cpp: the preset tables and createColormap
StorageGeometryPool::allocate and GeometryPool::write for a chunk (src/renderer/geometryPool.cpp)
The point runDrawRun::points, ShadedPipelines::pointPipeline, rebuildDrawList, drawSceneView in src/renderer/gpuScene.cpp
The compute pathpreparePointRaster, recordPointReset, recordPointRaster, drawPointResolve, getPointRasterLayout in src/renderer/pointRaster.cpp; the buffers made in createSceneView where RenderContext::hasBufferInt64Atomics
Shadersshaders/lib/points.slang (header, padding, selectPointCount, isRasterChunk, appendPointBatches), shaders/passes/points.slang (the draw and the pick), shaders/passes/pointRaster.slang (reset, clear, raster, resolve), shaders/passes/cull.slang; getPointDiameter sizes a point for the cull and both paths
Exampleexamples/28_point_cloud/main.cpp: a synthetic scan 6 000 km out, colored by height, a perspective and an orthographic view; --adaptive for adaptive points
Teststests/pointCloudTests.cpp (round trip, prefixes); image tests points, points_msaa4, points_taa, points_ortho, far_points, and points_triangles, points_msaa4_triangles, points_taa_triangles (the same scene by triangles only, against the compute path's image), points_adaptive, points_large and points_large_triangles (discs of 5 pixels, spheres of 4, squares of 3 on both paths)
Rules to keep

A chunk's order is part of its data: every prefix must stay an even sample. The cull pass decides each chunk's count in selectPointCount only, and its path in isRasterChunk only. The two paths must take the same pixels: a change to one's coverage, size or depth changes the other. PointData, PointChunkHeader and PointRasterHeader are kept in step on both sides (struct layout).

Not yet

Further reading