Skip to content
Andrew Voirol
Monday, August 31, 2026terragemini-build

O(1) GPU vertex slicing: 250,000 points without PCIe memory reallocation

WebGLShadersPerformanceVisualization

In planetary particle visualizers, scaling point density dynamically usually incurs a heavy frame penalty — either through CPU-side vertex buffer re-allocations or repetitive gl.bufferData bus uploads.

TerraGemini eliminates this overhead by pre-generating a maximum pool of 250,000 spherical surface points during the initial raster pass. Each point is importance-ranked (evaluating coastline distance and spatial dispersion) and packed into a single static interleaved vertex buffer ([lon, lat, edge_strength, rank], 16 bytes per vertex) uploaded once at startup.

When the user scrubs the point density slider:

  • No CPU memory is allocated.
  • Zero vertex bytes are transferred across the PCIe bus.
  • The WebGL draw loop executes an O(1)O(1)O(1) range slice:
const renderPoints = Math.min(250000, Math.max(50000, Math.floor(targetDensity)));
gl.drawArrays(gl.POINTS, 0, renderPoints);

Visual presets are managed identically: rather than recompiling shaders or modifying preprocessor #ifdef branches, uniform color vectors smoothly lerp toward target presets via exponential decay (α=0.08\alpha = 0.08α=0.08) on every frame. The result is instant, 60fps responsiveness across the entire density range.

← Previous

48 threads got screenshots and the homepage got a real layout

Next →

Blinn-Phong specular ocean glint and raytraced atmospheric scattering


Andrew Voirol

Builder, hacker, shipper. Currently leaving localhost.

Navigate

WorkThreadsBuilder's LogAboutContactRSS Feed

Connect

X / TwitterGitHubLinkedIn

© 2026 Andrew Voirol·Back to top ↑
✦Just one prompt away from figuring it all out.