Hard 3DAnimated

Black hole lensing

A black hole that bends a swirling disc of light around itself.

The target picture for the shader challenge "Black hole lensing"
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 514 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

p
(uv - 0.5) * float2(aspect, 1.0) * 2.0; r = length(p), a = atan2(p.y, p.x)
Horizon
black inside r < 0.25: mask = smoothstep(0.24, 0.26, r)
Lensing
bent radius rr = r - 0.18 / r (pushes disc light outward as it nears the hole); disc = exp(-pow((rr - 0.55) * 6.0, 2.0))
Swirl
spiral = 0.5 + 0.5 * sin(a * 3.0 - rr * 20.0 + time * 3.0)
Disc color
lerp(float3(1.0, 0.4, 0.1), float3(1.0, 0.9, 0.6), spiral) * disc
Photon ring
+ float3(1.0, 0.9, 0.7) * exp(-abs(r - 0.27) * 60.0) * 0.8
Background
float3(0.01, 0.01, 0.03), then multiply everything by mask

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