Drawing

Instanced glyphs and data lines

A simulation gives a velocity at each point of a grid; a sensor network gives a reading at each station; a particle system gives a position for each particle. To see such data, draw one small shape per data point: an arrow along the velocity, a sphere sized by the reading, a marker. That shape is a glyph. This page explains how to draw millions of them fast: little data per glyph, one draw for all of them, culling and level of detail per glyph on the GPU, and colors from values. Lines through the same data (streamlines, tracks) get their colors the same way. The last part shows how RASM does it.

In short

  • A glyph is one shape (arrow, sphere, cube, any mesh) drawn once per data point, moved, turned and stretched by that point's data.
  • Each glyph stores a position (12 B), a value (a color or a scalar, 4 B), and only if needed a rotation (8 B) and a scale (8 B). The positions are floats from a chunk's origin, which is a double: exact far from the world's origin.
  • Instancing draws the shape N times in one draw. The vertex stage reads its glyph and builds translate · rotate · scale.
  • A compute pass culls every glyph (frustum, Hi-Z), picks its shape's LOD by its size on screen, and writes the visible ones, grouped by LOD, into a list. One indirect draw with a GPU count draws them.
  • A value becomes a color through a colormap. On a line, interpolate the value and look it up per pixel, not the colors.

1One shape, many data points

Glyphs show data where it is. The shape and the way it changes with the data say what the data is.

Vector fields

An arrow per sample: turned along the vector, as long as its magnitude, colored by it.

Particles

A sphere per particle, sized by its mass or age. No rotation needed.

Markers

A cube per station, stretched along one axis by its reading: a bar chart in 3D.

Each glyph is a copy of the same mesh. Only a few numbers differ between copies. That is what makes millions cheap: the mesh is stored once, and each glyph adds a few bytes.

2What a glyph stores

A glyph needs a place, a value, and often a direction and a size. Each is stored as small as its precision allows.

One glyph, 32 bytes x y z: 3 floats value rotation: 4 × snorm16 scale: 3 × half + 1 12 B 4 B 8 B, if turned 8 B, if stretched RGBA8 or a float A chunk of n glyphs header position + value × n rotation × n scale × n 16 B a glyph for particles and markers that do not turn; 24 or 32 B with a rotation and a scale. A stream that is not there costs nothing, and the shader skips its read.
A rotation is a unit quaternion: four numbers from −1 to 1, so 16 bits each keep it to 1/32767. A scale is a size, where three significant digits are plenty: a half float. The position needs more, and gets 32-bit floats.

Far from the world's origin

A float has 24 bits of mantissa. 6 000 km from the origin, the step between two floats is half a metre: glyphs would sit on a coarse lattice and shake as the camera moves. So a chunk keeps its origin in doubles, and each glyph only its offset from it, a few hundred metres at most, where a float is exact to a tenth of a millimetre.

world origin 6 000 km: doubles chunk origin offsets: floats
The renderer moves the chunk's origin into camera-relative space in doubles; the offsets are then added in floats close to the camera, where floats are fine (Large worlds).

3Instancing: one draw for every copy

A draw call can repeat a mesh: instancing. The GPU runs the vertex stage for every vertex of every instance, and gives it the instance's number. The vertex stage reads that instance's glyph and places the shape's vertex.

the shape's verticesstored once the glyphsa few bytes each instance i vertex stage glyph = glyphs[i] p = T · R · S · v chunk matrixthen view, projection
One draw, N instances: the CPU sends one command whatever N is. The shape's vertices stay in the cache, as every instance reads the same ones.

pchunk = position + R(q) · (s ∘ v)

nchunk = R(q) · (n ∘ 1/s)

v, n
the shape's vertex position and normal
q, s
the glyph's quaternion and its scale per axis; ∘ multiplies axis by axis
1/s
a normal is turned by the inverse transpose: the rotation is its own, the scale is divided. Stretch a sphere along y and its normals lean toward the flat sides.

4Cull every glyph, then draw only the visible ones

A field of a million glyphs seldom shows all of them: some are behind the camera, some outside the sides, some behind a wall. Culling one draw of the whole field would keep or drop everything. So the culling runs per glyph, on the GPU, and the draw then reads only the glyphs that passed: the visible ones are compacted into a list. Glyphs come in chunks, and a chunk outside the view is dropped first, without reading its glyphs.

1. Test the chunks

camera A kept B kept C dropped A chunk's sphere holdsits glyphs, grown by theshape's reach × thelargest scale.

The chunk test is the usual sphere test (Frustum culling). A kept chunk gets a slot, and its glyphs are split into batches: a thread group per batch of 256.

2. Count: test each glyph and pick its LOD

glyphresultplace 0LOD 00 1culled 2LOD 10 3LOD 01 4culled 5LOD 11 6culled 7LOD 12 The group counts per LOD in shared memory (LOD 0: 2, LOD 1: 3), then adds each count to the chunk's with one atomic.

Each thread tests its glyph's sphere against the frustum and, if a depth pyramid exists, against it (Occlusion culling). A visible glyph picks the LOD of its shape and takes a place among the group's glyphs of that LOD: a shared-memory counter. Then one thread per LOD adds the group's count to the chunk's counter with one atomic, which says where the group's places start.

3. Write: each visible glyph at its offset

list 0 3 2 5 7 01234 LOD 0: 2 glyphs LOD 1: 3 glyphs offset = (counts of the LODs before) + place glyph 7: LOD 1, place 2 → 2 + 2 = 4

A second pass, once every count is final, writes each visible glyph to the list at its offset. The list is dense: no gaps, no culled glyph in it.

4. One indirect draw with a GPU count

LOD 0: the shape's LOD 0 indicesinstances 2, first instance 0 LOD 1: the shape's LOD 1 indicesinstances 3, first instance 2 one indirect draw: the commandsand their count from GPU memory

The same pass writes a command per chunk and LOD: the LOD's index range, its glyph count as the instance count, and its first entry in the list as the first instance. The vertex stage reads the list at its instance number. The CPU never learns how many glyphs are visible.

Drag the camera's aim to turn the view, and move the camera. Each glyph is kept or culled by the wedge, and gets LOD 0, 1 or 2 by its distance. The readouts are the numbers of the three draw commands, one per LOD.
Order is not kept

The places come from atomics, so the order inside a LOD changes from frame to frame. For opaque glyphs that does not matter: the depth test decides, and two glyphs tie only where they meet at the same depth. See-through glyphs would need a sort (GPU sorting).

5A LOD for each glyph

A glyph far away covers a few pixels, yet its shape may have hundreds of vertices. The draw then costs per vertex, not per pixel: it is vertex-bound. So each glyph picks the coarsest LOD of its shape whose error stays under a pixel, as a mesh does (LOD selection), but measured with the glyph's own size.

16 segments

Close up. Error 0.

8 segments

Every other vertex of the rings. Error r (1 − cos(π/8)).

4 segments

A square shaft, a pyramid head. Error r (1 − cos(π/4)).

No caps

A third fewer vertices. Its error is the head's radius: a hole only when the head is under a pixel.

errorn = r · (1 − cos(π / n))

pixels = error · scale · k / depth

n
segments around: a polygon of n sides falls inside its circle by at most this
r
the widest ring's radius, in the shape's units
scale
the glyph's largest scale times the chunk's
k / depth
pixels per unit at the glyph's depth: k at depth 1; an orthographic view has the same k everywhere

A mesh simplifier stops at small meshes, since a 300-triangle mesh is cheap once. Drawn a million times it is not, so glyph shapes build their LODs by hand: halving the segments keeps every coarser LOD on the finest one's vertices, so they share one vertex buffer.

6Values through a colormap, on glyphs and on lines

A glyph's value becomes its color through a colormap and a range (Colormaps). A glyph has one value, so one lookup per glyph is enough. A line is different: its points have different values, and the pixels between them need values too.

look up 0.1look up 0.9 blend the two colors

Interpolate the colors

The middle gets a mix of the two end colors. The colormap's colors in between never show.

0.10.50.9 look up per pixel

Interpolate the value

Each pixel looks up its own value. The line shows the colormap as it is.

Change the two end values. The top strip blends the end colors; the bottom one looks up the blended value at each pixel. They differ most when the ends are far apart in the colormap.

A line with a value per point (a streamline colored by speed, a track by time) passes it to every vertex its point makes: the two corners of each segment, a join's fan, a cap. Where the line is cut into pieces (to lie on terrain), a new point takes the value between its segment's ends.

Outside the range

A value outside the range takes the nearest end of the colormap when the range clamps. Without clamping it is not drawn: a glyph disappears, a line has a gap. That shows where data leaves the range, which a clamp would hide.

7Picking a glyph

A pick renders object ids under the mouse (Picking). The whole chunk is one object, so the id alone says only "this chunk". A glyph adds its index in the chunk, which the vertex stage knows: the list gives it. The answer is the index in the arrays the glyphs were built from, so the application finds its own data point. A pick culls the glyphs again through its small rect, so it draws only the few glyphs under it.

8Pitfalls

Stripes and stars across a dense field in perspective
A regular lattice lines up along some directions of view: you see the gaps between its rows, not the data. Jitter each glyph inside its cell (a fixed random offset of up to a third of the spacing), and sample the field at the jittered place.
The draw is slow although few pixels change
It is vertex-bound: far glyphs of hundreds of vertices each. Give the shape LODs down to a few vertices, and drop the caps last.
The draw is slow up close
Dense volumes overdraw: many glyphs on one pixel, each shaded, in no particular order. Smaller glyphs, fewer of them in view, or a cheaper material.
Far glyphs flicker
A glyph thinner than a pixel hits a pixel centre in one frame and misses it in the next. Temporal anti-aliasing or MSAA, or glyphs at least a pixel wide where they matter.
Glyphs jitter far from the origin
Their positions are floats in the world. Store floats from a chunk origin in doubles.
Lighting looks wrong on stretched glyphs
The normal was turned by the glyph's matrix. Use the rotation, and divide by the scale (the inverse transpose).

9In RASM

A glyph chunk is a mesh made by buildGlyphChunk (include/rasm/glyphs.h), drawn by an entity with a MaterialType::GLYPHS material placed in doubles. Its shape is any mesh (GlyphChunkDesc::shape; buildGlyphShape makes an arrow, a sphere or a cube with LODs). The chunk rides in the draw list's point run, so the frame's culling tests it like any draw; the glyph cull then culls its glyphs one by one, and the view's last draw pass draws them with one indirect draw.

any thread the renderer's thread, GPU memory compute passes draw
any thread buildGlyphChunk16 to 32 B a glyph buildGlyphShapea shape with LODs renderer createMeshpoint pool + a row syncGpuScenewaits for the shape;row → shape's row each shaded view cull.slang countMainappendGlyphChunk glyphCull.slang, after the last cullcountMain, writeMain drawViewGlyphsone drawIndexedIndirectCount,rasm.slang with RASM_GLYPHS
The glyph cull runs inside the view's cull pass, after its last cull, so it sees the Hi-Z of the early draws; the glyphs draw in the last draw pass, before the point resolve and the sky.
This pageRASM
ChunksUp to MAX_GLYPH_CHUNK_GLYPHS (65 536) glyphs a chunk. The chunk's data goes into the point pool (RendererConfig::geometryPoolPoints, shared with point clouds); its geometry row has lodCount 0, which marks it as a glyph chunk for the shaders, and no indices. Its entity's instance row names the shape's geometry row in meshletVisibility (a chunk has no meshlets).
The bytesgfx::GlyphChunkHeader (32 B: count, flags GLYPH_CHUNK_COLORS, GLYPH_CHUNK_SCALARS, GLYPH_CHUNK_ORIENTED, GLYPH_CHUNK_SCALED, the largest scale, the sphere around the positions), then the streams; loadGlyph reads them, decodeHalf the half floats by hand (Slang's own conversion asks for the Float16 capability, which RASM does not enable).
Chunk testThe chunk is a draw of the point run (POINT_RUN_GLYPHS), so no draw run was added and SceneData keeps its offsets. getWorldSphere grows it by the shape's reach times maxScale; countMain of cull.slang appends a kept chunk (appendGlyphChunk: a gfx::GlyphChunkSlot, batches of GLYPH_BATCH_GLYPHS, a command per LOD) and marks it CULL_RASTER: no slot in the visible draws.
Count and writeshaders/passes/glyphCull.slang: resetMain before the first cull, countMain and writeMain after the last, both indirect, a group a batch. A glyph's place is glyphSlotsPtr's word, place | LOD << GLYPH_LOD_SHIFT or GLYPH_CULLED; the list entry is chunk slot << 16 | glyph.
Hi-ZThe glyph cull runs after the late cull, so it tests each glyph against the Hi-Z of the early draws. Glyphs do not hide glyphs: they draw after the Hi-Z.
The drawdrawViewGlyphs: ShadedPipelines::glyphPipeline, culled by back face unless a chunk is double-sided or mirrored (SceneDrawList::glyphCullMode). vertMain reads the list at getInstanceIndex (Vulkan's InstanceIndex, which counts from the command's first instance), and getVertexOutput multiplies the entity's matrix by the glyph's (getGlyphMatrix, getGlyphNormalMatrix). fragMain shades GLYPHS as PBR, the glyph's color as the vertex color.
ColorsGlyphMaterial (colorMode, colormap, range) goes into the material row's gfx::PointData, which points use too; getGlyphColor looks the scalar up once per vertex, uniform over a command. Data lines: addVectorLines' colors or scalars, and VectorMaterial::colorMode SCALAR: getVertexScalar passes the scalar, getVectorColor looks it up per pixel.
See-through glyphsA GLYPHS material with AlphaMode::BLEND is always weighted (weighted blended transparency): its alpha is the glyph's color alpha times the material's albedo alpha. The cull puts its chunks' draw commands after the opaque chunks' room (GlyphCullHeader::weightedCommandCount), and drawWeighted draws them with ShadedPipelines::weightedGlyphPipeline; a pick tests their alpha against PickDesc::minAlpha.
PickingA pick of a view that drew glyphs culls them into the pick's own glyph buffer (PickSlot::glyphCull) and draws them with RASM_PICK and RASM_GLYPHS: PICK_HIT_GLYPH, the feature is the glyph's index. PICK_SKIP_GLYPHS looks through them.
ShadowsGlyphs cast no shadow, and debug views draw them shaded (D52): a depth-only view leaves the point run out.

Measured with examples/30_glyphs and --bench: 295 K arrows of 16 segments in 36 chunks of 8192 and 768 streamlines, a perspective TAA view and an orthographic 4× MSAA view at 1920 × 1080, RTX 3060, Release.

0.59 Mglyphs tested a frame0.26 M drawn, 56 % culled
0.20 msthe glyph cull0.33 ns a glyph tested
4.7 msthe glyph draw18 ns a glyph drawn; 11.4 ms with no shape LODs
32 Ba glyph in the point pool+ 8 B per view and frame slot

The 8 B per view and frame slot are the cull's places and the list. More glyphs are smaller on the screen and take the coarse LODs: 2.36 M arrows (192 × 64 × 192) draw 2.05 M a frame in 15.9 ms (7.8 ns each) after a 0.83 ms cull; 5.24 M draw 4.55 M in 31 ms after a 1.9 ms cull. The Hi-Z test costs nothing measurable. It pays where a mesh hides glyphs: with --wall, a wall in front of the box, it drops 7 % more of them (0.241 M drawn instead of 0.258 M) and the frame takes 6.10 ms instead of 6.26.

Code map

WhatWhere
The APIGlyphChunkDesc, buildGlyphChunk, GlyphShape, buildGlyphShape, getGlyphOrientation, MAX_GLYPH_CHUNK_GLYPHS in include/rasm/glyphs.h; GlyphMaterial, VectorMaterial in include/rasm/material.h; addVectorLines in include/rasm/vector.h; PICK_HIT_GLYPH, PICK_SKIP_GLYPHS in include/rasm/picking.h
The builderssrc/scene/glyphs.cpp; the data lines' values in src/scene/vector.cpp
Storage and rowsGeometryPool::allocateGlyphs (src/renderer/geometryPool.cpp); syncGpuScene, writeInstanceRows, updateDrawModes, rebuildDrawList in src/renderer/gpuScene.cpp
The glyph buffer and passesgetGlyphCullLayout, writeGlyphCullPointers, prepareGlyphCull, recordGlyphReset, recordGlyphCull, drawViewGlyphs, drawGlyphs in src/renderer/glyphCull.cpp
Shadersshaders/lib/glyphs.slang (loadGlyphChunk, loadGlyph, getGlyphMatrix, getGlyphColor, appendGlyphChunk), shaders/passes/glyphCull.slang, shaders/passes/rasm.slang (RASM_GLYPHS), shaders/passes/cull.slang
The C API (1.14)rasm_build_glyph_chunk, rasm_build_glyph_shape, rasm_get_glyph_orientation in src/c/cGlyphs.cpp; rasm_vector_add_data_lines in src/c/cVector.cpp
Exampleexamples/30_glyphs/main.cpp: the ABC flow as arrows and streamlines 6 000 km out, a perspective and an orthographic view, a scripted pick
Teststests/glyphsTests.cpp (the chunk's bytes, the shapes' LODs, orientations, the buffer layout, data lines); image tests glyphs, glyphs_msaa4, glyphs_taa, glyphs_ortho, far_glyphs
Rules to keep

A glyph chunk's geometry row has lodCount 0, and its row names its shape's row: every shader that meets a GLYPHS draw relies on both. The chunk takes no slot in the visible draws: its glyphs reach the screen only through the glyph list. The places and the commands are written after every count is final: writeMain runs after a barrier. A new pipeline that draws glyphs goes into the warm-up list with the same name and defines (Shader warm-up).

Further reading