On this site

Galaxy

A shader star field with depth, twinkle and drift.

OGL · GLSL

The dark-mode hero needed depth without imagery. A procedural star field gives an endless backdrop for a few kilobytes of shader code, tuned to stay under a strict pixel budget.

The whole field is one fragment shader on a full-screen triangle. Four depth layers each tile the plane into a grid; every cell hashes its coordinates into a star with its own size, colour, drift and twinkle phase, and a 3x3 neighbour loop lets glows cross cell borders. The pointer pushes the UV space away with an inverse-distance term, and the resolution is scaled to a pixel budget so large screens stay cheap.

vec3 StarLayer(vec2 uv) {
  vec3 col = vec3(0.0);
  vec2 gv = fract(uv) - 0.5;
  vec2 id = floor(uv);

  for (int y = -1; y <= 1; y++) {
    for (int x = -1; x <= 1; x++) {
      vec2 offset = vec2(float(x), float(y));
      vec2 si = id + offset;
      float seed = Hash21(si);
      float size = fract(seed * 345.32);
      float glossLocal = tri(uStarSpeed / (PERIOD * seed + 1.0));
      float flareSize = smoothstep(0.9, 1.0, size) * glossLocal;

      vec2 pad = vec2(
        tris(seed * 34.0 + uTime * uSpeed / 10.0),
        tris(seed * 38.0 + uTime * uSpeed / 30.0)
      ) - 0.5;

      float star = Star(gv - offset - pad, flareSize);
      float twinkle = trisn(uTime * uSpeed + seed * 6.2831) * 0.5 + 1.0;
      star *= mix(1.0, twinkle, uTwinkleIntensity);

      col += star * size * base;
    }
  }
  return col;
}