A Real-time High-quality Black Hole Shader

Eric Bruneton, 2020

A black hole near Orion, with 2 opposite images of a star around it [demo].

Introduction

We propose a real-time method to render high-quality images of a non-rotating black hole with an accretion disc and background stars. Our method is based on beam tracing, but uses precomputed tables to find the intersections of each curved light beam with the scene in constant time per pixel. It also uses a specific texture filtering scheme to integrate the contribution of the light sources to each beam.

Gallery

Here are some images obtained with our method.

The Large Magellanic Cloud forming an Einstein ring around the black hole [demo].



Near the speed of light lengths are contracted in the direction of motion (from left to right), colors are blue-shifted ahead and red-shifted behind (due to relativistic Doppler effects) and their intensity increases ahead and decreases behind (due to relativistic beaming effects) [demo].



Same conditions as above, but with an accretion disc too [demo].



A static observer represented with a rocket. To keep its position fixed instead of falling into the black hole, the rocket engine must be on [demo].



A freely falling observer orbiting around the black hole, represented with a rocket. By definition of free fall, the rocket engine must be off [demo].

Usage

A demo illustrating our method is available online. To recompile it and precompute all the data from the source code, clone the git repository, init the submodules, and type make (this requires GNU make, the GNU C++ compiler, the sed, curl and gunzip command line tools, and the libcurlpp-dev, libpng-dev, zlib1g-dev libraries).

Structure

The source code is organized as follows:

It consists of a small generic part (in bold), together with a more specific demo (everything else) showing how the generic model can be used in practice.

The generic part does not depend on the rest of the code, and is divided in two subparts: preprocessing and rendering. The preprocessing, in black_hole/preprocess/, implements the Precompute procedure in Algorithm 1 of our model. The rendering part, in the black_hole/*.glsl files, provides a library of GLSL functions implementing the TraceRay procedure in Algorithm 1 of our model, but also our custom texture filtering method for stars, our accretion disc shading model, the gravitational lensing effect, and the relativistic Doppler and beaming effects.

The demo is also divided in a preprocessing part and a rendering part. The preprocessing code is used to generate

The rendering part, in black_hole/demo/, is a WebGL 2 application organized into several UI components interacting via a shared model:

Documentation

The documentation of the generic black hole shader functions consists of a general overview of our method and algorithms, and a detailed description of their implementation:

The demo code is simpler and is documented with inline comments.