deniz.in

Markets

Weather

Loading weather

· via Hacker News – Front Page (native)

A Voronoi shader, one stuttering RTX 4070, and a trail leading to fract

A week-long debugging write-up traces a Voronoi shader's stutter to a single machine with an RTX 4070, and into the fractional-part function at the heart of its noise.

A Voronoi shader, one stuttering RTX 4070, and a trail leading to fract

A Voronoi background built from three ideas

The project started small: the author wanted an animated Voronoi pattern as the backdrop for a music video promoting a recently finished project. The resulting write-up, published on crocidb.com and picked up on the Hacker News front page, breaks the shader into three stacked concepts.

The first is a variant of Worley, or Voronoi, noise. Space is divided into equal tiles, a random point is placed inside each tile, and every pixel measures its distance to the nine candidate centers in the surrounding three-by-three neighborhood of tiles. Whichever center is closest decides which cell the pixel belongs to, which alone produces the familiar monochrome honeycomb of a Voronoi diagram.

The second concept is UV wrapping: before the space is tiled, the coordinates are distorted by a noise field, bending the otherwise rigid cells into something more organic. The third is a palette lookup. Cells are colored by their inverted distance to the center, then indexed into a fixed seven-color palette, with a small shading term added so the limited palette does not band. The final shader runs on Shadertoy, the post points beginners to The Book of Shaders as an introduction, and the music, credited to stuffy knows, is on the streaming platforms.

The stutter that only one machine showed

Overnight, the story turned into a debugging mystery. Opening the shader on a second computer the next morning revealed a stutter the first machine never showed. It reproduced in Firefox, Chrome and Edge, which ruled out the browser. Stripping the shader down, by removing the UV warping, freezing the palette cycling and enlarging the cells, isolated the fault to the loop that generates the Voronoi centers, and specifically to the lines that compose the noise input and offset each center.

Then came the device matrix. Two Linux laptops with integrated Intel graphics rendered normally. So did a Pixel 9 Pro and a Linux desktop with an RTX 2070. The only machine that stuttered was a Windows PC with an RTX 4070, one out of five devices tested, across multiple browsers.

Inside the noise function

For readers new to the field, the post offers a compact primer: a fragment shader runs once per pixel, per frame, holds no state and behaves like a pure function of its inputs, here the pixel coordinate and a time uniform. Randomness has to be manufactured from hash functions and then smoothed into procedural noise.

The noise in question is a value-noise variant taken from Inigo Quilez's article on procedural noises. Quilez created Shadertoy, and the author reports reusing this code in nearly every shader written since 2019. Its core is hash1, a one-liner built from two nested fract calls, whose hashed corner values are interpolated with a quintic falloff.

The trail leads to fract

With graphics-programmer friends too busy to help, the author turned to an LLM, Kimi K3. Its first instinct was to hunt for a continuity flaw in the hash function itself, a direction the author rejected on the grounds that the code ships in thousands of Shadertoy shaders. Steered away from that dead end, the model flagged the fract call at the very start of the noise function instead, reporting that it had found people online complaining about a problem with fract in Nvidia 40-series drivers.

The fetched text of the post cuts off mid-sentence at this point in the narrative, so the full resolution is not included here. The title, however, signals where the story lands: when the fractional part of a float fixes your shader. What began as an art project becomes a week of stripping effects, testing hardware combinations and disassembling compiled shaders, all circling one of the most primitive operations in graphics code.

Why it matters

This is a concrete, reproducible case of shader non-determinism across hardware. The same GLSL source produced visibly different animation on otherwise comparable machines, and the divergence traced toward how a single floating-point function is evaluated on a specific GPU and driver combination. Functions like fract are not guaranteed to behave identically across vendors, and when they diverge the symptom is a visual artifact, not an error message.

The debugging playbook is also worth stealing: reduce the effect until the fault is unmistakable, keep a device matrix to separate code from hardware, and distrust any hypothesis that implicates widely battle-tested code. Finally, it is an interesting datapoint on LLM-assisted debugging. The model produced one wrong lead and one promising one, and it took the author's domain judgment to know which was which.

  • #shaders
  • #gpu
  • #debugging
  • #graphics-programming
  • #webgl