Technology

How Blackhole renders a cinematic black hole in real time

Blackhole is a native macOS app built with SwiftUI and Metal. It combines per-pixel lensing, procedural accretion-disk emission, panoramic NASA sky maps, and adaptive quality controls to keep the scene responsive while preserving the recognizable black hole look.

The app is designed as a cinematic visual simulator. It uses physically inspired approximations rather than a full scientific general-relativity or radiative-transfer solver.

Render Loop

  1. SwiftUI settings become compact Metal uniforms.
  2. Each pixel launches a camera ray through the scene.
  3. The ray bends near the black hole and samples disk emission.
  4. The remaining ray direction samples the stitched sky map.
  5. Overlays and UI are composited separately.

SwiftUI interface

The app shell, helper menu, settings, background picker, clock overlay controls, and video export panel are written in SwiftUI.

Metal renderer

The simulation view is backed by Metal, allowing the black hole scene to be rendered directly on the GPU at interactive frame rates.

AVFoundation export

Offline MP4 export renders frames with a fixed timestep, then writes them through AVFoundation using HEVC or H.264.

Local-first design

NASA images, custom folders, thumbnails, settings, and generated video exports stay on the user's Mac.

Rendering Model

What happens inside a frame

1. Camera and scene state

Mouse-look, auto-hover, flyby, zoom, disk rotation, selected background, and computation mode are packed into a small uniform block for the GPU.

2. Per-pixel ray tracing

The fragment shader traces a ray from the camera through the black hole field. Near the center, the ray curves enough to reveal the far-side accretion disk and the lensed sky behind it.

3. Accretion disk sampling

The disk is rendered procedurally with density falloff, noise, Doppler-style brightness asymmetry, color ramps, and optional higher-detail turbulence for more chaotic structure.

4. Sky-map lookup

Curated NASA images are stitched into panoramic sky maps. After a ray exits the black hole region, its final direction samples the background texture so the backdrop appears gravitationally bent.

Performance Strategy

How the app stays fast

  • Computation presets tune render scale, trace steps, and disk noise detail.
  • Dynamic render scale can step down when the drawable becomes expensive.
  • Low-load modes reduce work away from the visually important lensing region.
  • Zoomed-out views preserve far-side disk visibility with targeted ray reach.
  • Background thumbnails are prebuilt so the picker stays responsive.
  • Image metadata and previews are separated from full-resolution textures.
  • Simulation overlays are kept separate from the heavy black hole pass.
  • Offline export can spend more time per frame than real-time playback.

Quality Modes

Real-time versus export

Real-time simulation

Optimized for interaction. The app balances image quality, latency, GPU time, and battery use while the user drags, zooms, opens menus, or changes backgrounds.

Offline video export

Optimized for smooth final output. Export can render frames one by one with a stable camera path, selected background queue, and higher quality settings before encoding the MP4.

Visual Honesty

What it is, and what it is not

Blackhole aims to make gravitational lensing and accretion disks feel vivid on a desktop Mac. It is inspired by black hole physics, but it is not a replacement for scientific simulation tools used in astrophysics research. The binary black hole mode is experimental and intentionally tuned for visual exploration.