It’s no secret I am fascinated by space. I mean, I’ve made multiple games about spaceships, I religiously watch every space launch that happens whenever I can get away with being awake. I am an insufferable pile of space facts, waiting to come out.
I’m also Good At Computers™ and currently know enough about shaders to make myself a danger to those around me. I was working on some artwork for Solar Dominion when I realised that my work on creating a relatively scientific depiction of both wormholes and warp fields could easily become a black hole.
Of course as anyone who has watched Interstellar (part of the Matt Damon has a Bad Day In Space trilogy) will know, a black hole isn’t just a black hole in space. There’s the accretion disk to contend with. A giant, swirling donut of plasma and dust superheated by gravitational tidal forces, impacts and radiation from the poor matter unfortunate enough to fall into the event horizon.
This rendition isn’t perfectly physically accurate. The scale of the warping effect is off, it can’t perfectly display objects behind the black hole, nor can it reflect anything in front of it properly (or anything at all behind the camera). It also makes mistakes for objects inside the warping effect. But it’s close enough, and you can get something approximating the famous shot from the film at highly oblique angles.
The effect is composed of two shaders, one for the event horizon and one for the accretion disk. The disk is simple and converts the distance from the centre to a gradient that runs from white to black through red, a poor approximation of the black-body colour curve. There’s then some noise applied and the whole thing gets spun to produce the trail effect. This gets applied to a thin donut shaped mesh and it’s done.
The event horizon is more complicated by far. At it’s core, it’s measuring the distance from the centre, and then replacing that pixel with a pixel further along the line towards the centre to simulate the effect of light bending around the singularity. When used as a wormhole, it takes a texture for the other side and does the opposite, selecting a pixel further away from the centre.
On both sides, it is possible for this to select a pixel that is off-screen. In this case it wraps around to a reflected version of the screen which gives a convincing illusion that it can actually refract behind the camera. The side of the event horizon and the severity of the lensing are both configurable, and in theory it is possible to show items moving through the wormhole although there’s still some bugs to work out with that.