One Primitive

How a single glyph threads through everything in Universe, and what happens when you make it 16x faster

The Glyph

SINE WAVE · U+223F · The fundamental oscillation
Unicode
U+223F   ∿
Lithos opcode
0x63
ARM64 blob
5th-order Chebyshev, 4-wide NEON
GLSL
sin()
Constants
v30 = -1/6   v31 = 1/120
Performance
16x scalar libm

One glyph. One opcode byte. One font table entry. One NEON blob. The polynomial is five terms: x + x³·(-1/6) + x&sup5;·(1/120). Loaded into NEON registers v30 and v31, it processes four sine values simultaneously in ~12 cycles. Scalar sinf() from libm takes ~40 cycles for one.

Where Sine Lives

Traced across 332 source files. Every layer of the project pulses with sin().

Terrain
fract(sin(dot(p,vec2(127.1,311.7)))*43758.5453)
The hash function. Foundation of ALL procedural generation. Every hill, every ridge, every variation in the ground begins here.
Wind
sin(uTime * f1 + aPhase) * windStr
virgo_grove.mjs — every tree sways, every leaf flutters. Oak, birch, olive. Two sin calls per branch per frame.
Waves
sin(xz.x * 3.5 + t * 0.55) * sin(xz.y * 2.8 - t * 0.43)
cenote_thermocline.mjs — surface ripples. Six sin calls per fragment for three wave harmonics. The cenote wants Gerstner trochoids, which are also sin.
Orbits
Math.sin(angle0) * r
outer_bodies.mjs — planetary orbital mechanics. Every planet, every moon, every asteroid traces sin/cos per frame.
Breathing
const breathe = 1.0 + Math.sin(t * 0.7) * 0.025
taurus_fauna.mjs — the bull's barrel body expands and contracts. The cat breathes at 0.4 Hz. Every living creature oscillates.
Stars
sin(uTime*(h1*4.+2.)+h1*6.28318)*0.35+0.65
virgo_sdf.mjs — star twinkle. Two density layers, each with a sin-driven brightness envelope. The night sky breathes.
Fireflies
sin(uTime*(2.0+hash(vec2(fs,5.5))*3.0)+phase)*0.4+0.6
virgo_sdf.mjs — 14 fireflies, each with unique pulse rate derived from hash. Three sin calls per firefly per frame: position x, position y, pulse envelope.
Camera
float sy=sin(uCamYaw); float sp2=sin(uCamPitch);
Every SDF raymarcher. Yaw/pitch to forward vector. Plus sin(uTime*.60)*.015 for camera bob. You see through sine.
Galaxy
0.5 + 0.5 * sin(ang * 3.0 + 4.0 * log(max(r, 0.04)) * rot)
cosmos_earth.mjs — logarithmic spiral arms. Log-spiral = exp + sin. Differential Keplerian rotation uses sin/cos per star.
Noise hash
fract(sin(dot(p, vec3(127.1, 311.7, 74.7))) * 43758.5453)
glsl/stdlib.mjs, 266 occurrences across the codebase. This single line IS the seed of all procedural content. Terrain, nebulae, star granulation, mineral veins — all rooted in one sin.
God rays
sin(uTime * 0.2 * 6.2832 + uPhase) * 0.5 + 0.5
cenote_deep_rays.mjs — sinusoidal shimmer on volumetric light shafts. 0.2 Hz, underwater cathedral.
Audio
Math.sin(TWO_PI * f * t)
_make_element_ambient.mjs — sinusoidal oscillators for pad synthesis, LFOs, grain envelopes. Sound is sine. Literally.
Texture
sin(p.x * 25.0 + 3.1) * sin(p.y * 25.0 + 7.2) * sin(p.z * 25.0 + 11.3)
octopus_frag.glsl — papillae bumps. Also feather barbs, bark streaks, mineral veins, lichen patterns. Surface detail is high-frequency sin.
Mortar
sin(q.y*12.0)*sin(q.x*7.3)*0.025
virgo_sdf.mjs — stone wall mortar lines. Two sin calls subtracted from the box SDF to create gaps between stones.
Color
sin(uTime * 0.06) * 0.5 + 0.5
cosmos_earth.mjs — ENSO phase oscillation drives Pacific sea surface temperature. Seasonal phase shifts vegetation color. Hue is periodic.

The Cost

How many sin() calls happen per frame in a Virgo SDF render. Trace the call chain from the bottom up.

hash(vec2 p) = 1 sin fract(sin(dot(p,vec2(127.1,311.7)))*43758.5453)
vnoise(vec2 p) = 4 × hash = 4 sin four corners: i, i+x, i+y, i+xy
fbm2(vec2 p) = 2 octaves × vnoise = 8 sin 2 vnoise calls at different scales
terrainH(vec2 xz) = 2 × fbm2 = 16 sin hills + roll, each an fbm2
sceneSDF(vec3 p) = terrain + trees + rocks ~80–120 sin terrainSDF + sdRock vnoise + singleTree terrainH + wall mortar sin

Per frame at 1280×720

Stage Calculation sin() calls
sceneSDF per step ~80–120 (terrain + objects) ~100
March loop 96 steps × sceneSDF ~9,600 per ray
Normals (6× sceneSDF) 6 finite-difference samples ~600 per hit pixel
Soft shadow (8 steps) 8 × sceneSDF ~800 per hit pixel
AO (5 steps) 5 × sceneSDF ~500 per hit pixel
Per pixel total march + normals + shadow + AO + camera + stars + fireflies ~11,500
Per frame 921,600 pixels × ~11,500 ~10.6 billion

Ten billion sin calls. Per frame. At 60fps: 636 billion per second. The GPU's SFU hardware handles each in 1 cycle, but that is still a significant fraction of the frame budget. On CPU (server-streamed mode), it is the dominant cost.

The 16x Opportunity

16.7x
faster than scalar libm
0.06x
ratio vs GCC -O2
4
sin per instruction
~12
cycles for 4 values

How it works

Lithos computes sin via a 5th-order Chebyshev polynomial evaluated in 4-wide NEON SIMD:

fmul  v2.4s, v0.4s, v0.4s   x²
fmul  v3.4s, v2.4s, v0.4s   x³
fmla  v0.4s, v3.4s, v30.4s   x + x³·(-1/6)   // v30 pre-loaded with -0.16667
fmul  v4.4s, v2.4s, v3.4s   x&sup5;
fmla  v0.4s, v4.4s, v31.4s   x + x³·(-1/6) + x&sup5;·(1/120)   // v31 = 0.00833

Five instructions. Four sine values. Constants v30 and v31 are loaded once at kernel entry and stay resident for the entire frame. No function call overhead, no branch prediction misses, no libm.

For comparison: GCC's sinf() at -O2 takes ~40 cycles for a single value. It calls into a scalar libm routine that handles the full IEEE 754 edge cases, range reduction, and a longer polynomial. Lithos's polynomial is tuned for SDF-relevant precision (<1 ULP error in [-π, π]) and skips what it does not need.

What 16x means for a frame

If sin-family operations account for 20% of frame time (conservative, given the hash→vnoise→fbm chain dominates terrain evaluation), then:

Scenariosin fractionSpeedup on sinFrame time reduction
Conservative 15% 16x ~14%
Moderate (terrain-heavy) 25% 16x ~23%
Aggressive (FBM-dominated) 35% 16x ~33%

The savings cascade. Hash calls sin. Vnoise calls hash four times. FBM calls vnoise twice. Terrain calls FBM twice. SceneSDF calls terrain, then rocks call vnoise. March calls sceneSDF 96 times. Accelerating sin at the bottom accelerates every layer above it.

The Deeper Point

Hills are sine. Wind is sine. Orbits are sine.

Breathing is sine. Stars are sine. The galaxy's spiral arms are sine.

Sound is sine. Water is sine. Light through water is sine.

Making sine 16x faster does not optimize one function.

It accelerates the fundamental frequency of reality in this cosmos.

The sine function is the atom of this universe. The hash function — fract(sin(dot(p, k)) * 43758.5453) — appears 266 times in the source. It is the seed of all procedural content: terrain height, nebula density, star granulation, mineral veins, lichen growth, wind direction, rainfall probability. Every natural-seeming variation in the cosmos traces back to a sin call inside a dot product.

In Lithos notation: is one glyph, one opcode byte (0x63), one font table entry, one NEON blob. The entire cosmos pulses through this single symbol.

Sine's Siblings

sin · ∿ · 0x63
16.7x faster — 5th-order Chebyshev
cos · ∾ · 0x64
17x faster — same polynomial family

Cosine is sine phase-shifted: cos(x) = sin(x + π/2). Same polynomial, same NEON blob, one addition. Together they form rotation:

[ cosθ   -sinθ ]
[ sinθ    cosθ ]

Every camera movement. Every orbital calculation. Every wind direction. Every tree twist. Every spiral arm. Every bat wing flap, every bubble wobble, every root sway. All of it is a 2×2 matrix with sin and cos. Accelerating both by 16–17x accelerates all rotation in the universe.

The camera's forward vector is vec3(sin(yaw)*cos(pitch), sin(pitch), cos(yaw)*cos(pitch)). You literally see through a sine/cosine transform. Perception itself is .