Hard 3DAnimated

Endless sphere field

Fly forward through an infinite grid of colored spheres that fades into the dark.

The target picture for the shader challenge "Endless sphere field"
Recreate this picture. You pass at a 99% match, then try to write it in fewer characters than the par.

How this challenge works

You write a fragment shader that draws the picture above, live in your browser. A match bar shows how close you are, and the score combines accuracy, code size (the par is 1013 characters in Unity (Built-in)) and GPU speed. Work in HLSL, GLSL, WGSL, Metal or Godot and export the result when you are done.

The numbers you need

Repetition
q = p; q.xz = frac(q.xz * 0.5 + 0.5) * 2.0 - 1.0; map = length(float3(q.x, p.y, q.z)) - 0.35
Camera
ro = float3(0.0, 0.7, time), rd = normalize(float3(p.x, p.y - 0.25, 1.4))
March
80 steps, miss when t > 30
Cell id
id = floor(pos.xz * 0.5 + 0.5)
Color
0.5 + 0.5 * cos(float3(0.0, 2.0, 4.0) + id.x * 1.3 + id.y * 0.9), times (0.15 + 0.85 * diffuse); light normalize(float3(0.6, 0.8, -0.5))
Fog
col = lerp(float3(0.05,0.05,0.12), col, exp(-0.012 * t * t))
Background
float3(0.05, 0.05, 0.12)

Helper functions provided

The toolbox has: calcNormal(). Add them above your frag function with one click.

Solve it in your language

Unity (Built-in), Unity (URP), Unreal, Shadertoy / WebGL, OpenGL (LWJGL, raylib), three.js, GameMaker, LÖVE (Lua), Godot, Apple (iOS, macOS), WebGPU / Bevy.

Start coding