<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>Build notes by Sparsh Prakash</title>
  <subtitle>Notes by Sparsh Prakash on data platforms, open-source tools and the things built after hours.</subtitle>
  <link href="https://sparsh.build/blog/feed.xml" rel="self" type="application/atom+xml" />
  <link href="https://sparsh.build/blog/" rel="alternate" type="text/html" />
  <id>https://sparsh.build/blog/</id>
  <updated>2026-11-22T09:00:00+05:30</updated>
  <author>
    <name>Sparsh Prakash</name>
    <uri>https://sparsh.build/</uri>
  </author>
  <entry>
    <title>Ninety thousand points, one draw call</title>
    <link href="https://sparsh.build/blog/ninety-thousand-points/" rel="alternate" type="text/html" />
    <id>https://sparsh.build/blog/ninety-thousand-points/</id>
    <published>2026-11-22T09:00:00+05:30</published>
    <updated>2026-11-22T09:00:00+05:30</updated>
    <summary>The portrait on this site turns into a globe, a helix and a running track as you scroll. Nothing is created or destroyed on the way. Here is how that works.</summary>
    <category term="three.js" />
    <category term="WebGL" />
    <category term="this site" />
    <content type="html">&lt;p&gt;The home page of this site has one object in it. It is a cloud of 90,000 points, and it stays on screen from the first pixel to the last. When you scroll, the points do not fade out and get replaced. They travel. The portrait becomes a stream, the stream becomes a neural network, and sixteen formations later the same points are a portrait again.&lt;/p&gt;
&lt;p&gt;I wanted that because it says the thing I care about in one image: everything I have built is made of the same material.&lt;/p&gt;
&lt;figure class=&quot;demo&quot; data-demo=&quot;{&amp;quot;from&amp;quot;:&amp;quot;portrait&amp;quot;,&amp;quot;to&amp;quot;:&amp;quot;globe&amp;quot;,&amp;quot;controls&amp;quot;:[&amp;quot;mix&amp;quot;,&amp;quot;play&amp;quot;]}&quot;&gt;
&lt;div class=&quot;demo__stage&quot;&gt;&lt;canvas role=&quot;img&quot; aria-label=&quot;Drag the slider, or press Play. These are the same points in both formations. You can also push them around with the pointer.&quot;&gt;&lt;/canvas&gt;&lt;/div&gt;
&lt;div class=&quot;demo__bar mono&quot;&gt;&lt;/div&gt;
&lt;figcaption&gt;Drag the slider, or press Play. These are the same points in both formations. You can also push them around with the pointer.&lt;/figcaption&gt;
&lt;noscript&gt;&lt;p class=&quot;demo__off mono&quot;&gt;This figure is live: it needs JavaScript.&lt;/p&gt;&lt;/noscript&gt;
&lt;/figure&gt;
&lt;h2 id=&quot;one-buffer-in-one-buffer-out&quot;&gt;One buffer in, one buffer out &lt;a class=&quot;anchor&quot; href=&quot;#one-buffer-in-one-buffer-out&quot; aria-label=&quot;Link to the section: One buffer in, one buffer out&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Each formation is a plain function. It takes a count and returns two arrays: where every point should sit, and how it should look (how much accent colour, how big).&lt;/p&gt;
&lt;p&gt;The GPU holds two copies of that data at a time, &lt;code&gt;aFrom&lt;/code&gt; and &lt;code&gt;aTo&lt;/code&gt;. Scrolling never touches them. It only changes a single number, &lt;code&gt;uMix&lt;/code&gt;, between 0 and 1. The vertex shader does the rest:&lt;/p&gt;
&lt;figure class=&quot;code&quot;&gt;&lt;figcaption class=&quot;mono&quot;&gt;&lt;span&gt;glsl&lt;/span&gt;&lt;/figcaption&gt;&lt;pre class=&quot;shiki css-variables&quot; style=&quot;background-color:var(--shiki-background);color:var(--shiki-foreground)&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:var(--shiki-token-comment)&quot;&gt;// every point leaves and arrives on its own schedule&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:var(--shiki-token-keyword)&quot;&gt;float&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-foreground)&quot;&gt; stagger &lt;/span&gt;&lt;span style=&quot;color:var(--shiki-token-keyword)&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-token-constant)&quot;&gt; 0.5&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-foreground)&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:var(--shiki-token-keyword)&quot;&gt;float&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-foreground)&quot;&gt; t &lt;/span&gt;&lt;span style=&quot;color:var(--shiki-token-keyword)&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-token-function)&quot;&gt; clamp&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-foreground)&quot;&gt;(uMix &lt;/span&gt;&lt;span style=&quot;color:var(--shiki-token-keyword)&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-foreground)&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-token-constant)&quot;&gt;1.0&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-token-keyword)&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-foreground)&quot;&gt; stagger) &lt;/span&gt;&lt;span style=&quot;color:var(--shiki-token-keyword)&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-foreground)&quot;&gt; aRand.x &lt;/span&gt;&lt;span style=&quot;color:var(--shiki-token-keyword)&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-foreground)&quot;&gt; stagger&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-token-punctuation)&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-token-constant)&quot;&gt; 0.0&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-token-punctuation)&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-token-constant)&quot;&gt; 1.0&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-foreground)&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:var(--shiki-foreground)&quot;&gt;t &lt;/span&gt;&lt;span style=&quot;color:var(--shiki-token-keyword)&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-foreground)&quot;&gt; t &lt;/span&gt;&lt;span style=&quot;color:var(--shiki-token-keyword)&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-foreground)&quot;&gt; t &lt;/span&gt;&lt;span style=&quot;color:var(--shiki-token-keyword)&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-foreground)&quot;&gt; t &lt;/span&gt;&lt;span style=&quot;color:var(--shiki-token-keyword)&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-foreground)&quot;&gt; (t &lt;/span&gt;&lt;span style=&quot;color:var(--shiki-token-keyword)&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-foreground)&quot;&gt; (t &lt;/span&gt;&lt;span style=&quot;color:var(--shiki-token-keyword)&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-token-constant)&quot;&gt; 6.0&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-token-keyword)&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-token-constant)&quot;&gt; 15.0&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-foreground)&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:var(--shiki-token-keyword)&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-token-constant)&quot;&gt; 10.0&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-foreground)&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:var(--shiki-token-keyword)&quot;&gt;vec3&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-foreground)&quot;&gt; a &lt;/span&gt;&lt;span style=&quot;color:var(--shiki-token-keyword)&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-token-function)&quot;&gt; spinY&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-foreground)&quot;&gt;(aFrom&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-token-punctuation)&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-foreground)&quot;&gt; uAngle.x);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:var(--shiki-token-keyword)&quot;&gt;vec3&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-foreground)&quot;&gt; b &lt;/span&gt;&lt;span style=&quot;color:var(--shiki-token-keyword)&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-token-function)&quot;&gt; spinY&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-foreground)&quot;&gt;(aTo&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-token-punctuation)&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-foreground)&quot;&gt; uAngle.y);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:var(--shiki-token-keyword)&quot;&gt;vec3&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-foreground)&quot;&gt; p &lt;/span&gt;&lt;span style=&quot;color:var(--shiki-token-keyword)&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-token-function)&quot;&gt; mix&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-foreground)&quot;&gt;(a&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-token-punctuation)&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-foreground)&quot;&gt; b&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-token-punctuation)&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-foreground)&quot;&gt; t);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;&lt;code&gt;aRand.x&lt;/code&gt; is a random number baked into each point. Subtracting it means no two points start moving at the same moment, which is the difference between a crossfade and a flock. The third line is an ease, so nothing starts or stops with a jerk.&lt;/p&gt;
&lt;p&gt;Turn the stagger off below and drag again. Every point now moves in step, and the flock turns back into a crossfade.&lt;/p&gt;
&lt;figure class=&quot;demo&quot; data-demo=&quot;{&amp;quot;from&amp;quot;:&amp;quot;helix&amp;quot;,&amp;quot;to&amp;quot;:&amp;quot;terrain&amp;quot;,&amp;quot;controls&amp;quot;:[&amp;quot;mix&amp;quot;,&amp;quot;play&amp;quot;,&amp;quot;stagger&amp;quot;,&amp;quot;ease&amp;quot;,&amp;quot;swirl&amp;quot;],&amp;quot;mix&amp;quot;:0.5}&quot;&gt;
&lt;div class=&quot;demo__stage&quot;&gt;&lt;canvas role=&quot;img&quot; aria-label=&quot;The same morph with its parts switched on and off. Stagger is the random head start, Ease is the third line of the shader, Swirl is the turbulence added while points are in transit.&quot;&gt;&lt;/canvas&gt;&lt;/div&gt;
&lt;div class=&quot;demo__bar mono&quot;&gt;&lt;/div&gt;
&lt;figcaption&gt;The same morph with its parts switched on and off. Stagger is the random head start, Ease is the third line of the shader, Swirl is the turbulence added while points are in transit.&lt;/figcaption&gt;
&lt;noscript&gt;&lt;p class=&quot;demo__off mono&quot;&gt;This figure is live: it needs JavaScript.&lt;/p&gt;&lt;/noscript&gt;
&lt;/figure&gt;
&lt;p&gt;The buffers are rewritten only when you cross from one pair of formations into the next. That is a few megabytes, once per chapter, not once per frame.&lt;/p&gt;
&lt;h2 id=&quot;scroll-is-the-clock&quot;&gt;Scroll is the clock &lt;a class=&quot;anchor&quot; href=&quot;#scroll-is-the-clock&quot; aria-label=&quot;Link to the section: Scroll is the clock&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;There is no timeline. Every section of the page has an anchor, the point where it sits in the middle of the screen. Between two anchors I take how far you are, then squeeze it:&lt;/p&gt;
&lt;figure class=&quot;code&quot;&gt;&lt;figcaption class=&quot;mono&quot;&gt;&lt;span&gt;ts&lt;/span&gt;&lt;/figcaption&gt;&lt;pre class=&quot;shiki css-variables&quot; style=&quot;background-color:var(--shiki-background);color:var(--shiki-foreground)&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:var(--shiki-token-keyword)&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-token-constant)&quot;&gt; m&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-token-keyword)&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-token-function)&quot;&gt; smoothstep&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-foreground)&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-token-constant)&quot;&gt;0.2&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-token-punctuation)&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-token-constant)&quot;&gt; 0.8&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-token-punctuation)&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-foreground)&quot;&gt; raw);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;The first and last fifth of the distance do nothing. That gives each formation a moment to hold still while you read, and puts all the motion in the middle, where you are scrolling anyway.&lt;/p&gt;
&lt;h2 id=&quot;what-went-wrong&quot;&gt;What went wrong &lt;a class=&quot;anchor&quot; href=&quot;#what-went-wrong&quot; aria-label=&quot;Link to the section: What went wrong&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;em&gt;Colours turned to mud.&lt;/em&gt; Each chapter has its own palette, and I first blended them at the same rate as the points. Halfway between the yellow-green of the endurance chapter and the black of the next one, the whole page was olive. The fix was to stop blending. Colours now cut over in a narrow window:&lt;/p&gt;
&lt;figure class=&quot;code&quot;&gt;&lt;figcaption class=&quot;mono&quot;&gt;&lt;span&gt;ts&lt;/span&gt;&lt;/figcaption&gt;&lt;pre class=&quot;shiki css-variables&quot; style=&quot;background-color:var(--shiki-background);color:var(--shiki-foreground)&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:var(--shiki-token-keyword)&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-token-constant)&quot;&gt; cm&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-token-keyword)&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-token-function)&quot;&gt; smoothstep&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-foreground)&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-token-constant)&quot;&gt;0.47&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-token-punctuation)&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-token-constant)&quot;&gt; 0.53&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-token-punctuation)&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:var(--shiki-foreground)&quot;&gt; m);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;p&gt;&lt;em&gt;The frame counter read 30.&lt;/em&gt; I spent a while looking for the slow part of the shader. The laptop was on battery at 16%, and Chrome had halved the frame rate to save power. On the charger it ran at 60. Measure on mains.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Phones could not read it.&lt;/em&gt; On a wide screen the formation sits beside the words. On a phone there is no beside. Each chapter now opens with a clear window onto its formation, and the words arrive on a solid background underneath.&lt;/p&gt;
&lt;h2 id=&quot;what-it-costs&quot;&gt;What it costs &lt;a class=&quot;anchor&quot; href=&quot;#what-it-costs&quot; aria-label=&quot;Link to the section: What it costs&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Device&lt;/th&gt;
&lt;th&gt;Points&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Desktop&lt;/td&gt;
&lt;td&gt;90,000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Four cores or fewer&lt;/td&gt;
&lt;td&gt;60,000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Phone&lt;/td&gt;
&lt;td&gt;42,000&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;It is one draw call whatever the count. If you have asked your system for less motion, the swirl between formations is switched off, but the formations still follow your scroll, because that movement is yours.&lt;/p&gt;
&lt;p&gt;Most formations are one short function. The portrait is the odd one out: it is a photo, cut out from its background, with points dropped more densely where the image is darker. Everything else is arithmetic.&lt;/p&gt;
</content>
  </entry>
</feed>
