The trouble with this is that you need light to "bend" in a continuous arc around the black hole.
The reason why this bending is problematic is that cycles assumes light always travels in straight lines. Light does travel only in straight lines, but it can be bent by gravity.
Gravity is a distortion of spacetime around objects. The more massive the object, the more distortion.
So light is always going straight (from it's point of view), but to us it appears to bend as it follows the "straight lines" of distorted space.
Normally these distortions are very small, even with such big and massive objects like the sun. However with such a ridiculously massive object as a black hole, this effect can be quite extreme.
I don't know of any render engines which take into account such corner-case complications like the bending of spacetime near gravitational bodies :P
This is why a special render engine had to be written to render the effects in Interstellar.
TL;DR: Light is bent around black holes the same way the paths of planets around the sun are bent. Cycles doesn't have any support for simulating this kind of phenomenon.
So, how can we render it with cycles anyway?
In cycles the only way we can "bend" light is via refraction, which occurs when light exits one medium and/or enters another. It should be noted that refraction a completely different phenomenon from gravitational lensing.
This is really the same problem as Is it possible to change the IOR inside a volume?.
can only bend light at a surface, via the refraction shader.
We need to make light bend continuously, sort of as if it's in a medium with a changing IOR. However we can only change it's direction at a surface.
To visualize the difference, take this example image.
The inner circle represents the event horizon, from which no light can escape (i.e. the black part).
The outer circle represents the approximate distance at which the bending of light becomes noticeable. In the version on the left this circle represents a refracting sphere as described by Nightshade.
The lines represent the paths of light rays as they travel near the black hole.
Note: While thinking of how to set up some kind of material or effect, it's often useful to think of the scene in the same way that the render engine does. Cycles is a backwards path tracer, meaning it traces rays from the camera out into the scene. So try thinking of these rays in the same way.
See How is Cycles different from Blender Internal? for more info on the workings of cycles.
Example is only a rough hand made visualization, not accurate.
As you can see, rays which hit the refracting sphere are bent all at once at a single point, then continue going straight. It's more like a "direction change" than a curve.
One way to get around this problem is to use a lot of refracting surfaces (black lines) which change the direction the ray (yellow line) a little bit at a time, resulting in an approximation of a smooth curve:
To procedurally create such an object:
- Create a single edge.
Add a plane (⇧ ShiftA > Mesh > Plane), then switch to edit mode (↹ Tab), rotate it 90° around the X axis (RX90), and scale it to 0 on the Z (SZ0). Remove doubles by pressing W> Remove Doubles(R).
In object mode (↹ Tab), add an empty (⇧ ShiftA> Empty) and rotate it a small amount around the Z (I rotated mine by -2°).
Add an Array modifier to the line object:
The number for the array modifier Count can be determined like this:
360 / absolute_value(empty_rotation) / 4 + 1
empty_rotation = 3.
To add more surfaces and increase the accuracy (and rendertimes!) of the approximation, rotate the empty less and adjust the array count accordingly.
- Add a Screw modifier:
It should look like a strange sort of half-sphere.
- Add the hole itself by adding a sphere at the center of the front most surface of the half-sphere (⇧ ShiftA> Sphere):
For the material, give it a diffuse shader set to black. This will totally absorb any light which hits it, so zero light will be reflected off of it, making it completely black.
- Add a material to the half-sphere.
I've used a spherical gradient texture to control the IOR in order to make light bend more when closer to the center, and less when farther from the center.
This is a very approximate and artistic approach, not very accurate by any means.
If the scale of your object is (
1,1,1), the Scale of the mapping node should be set to the diameter of the half-sphere object in BU. This way the gradient texture just fades to black before the edge of the half-sphere object:
To quickly preview nodes in a material, enable the Node Wrangler addon in User preferences > Add-ons, then ⎈ Ctrl⇧ Shift LMB on any node to quickly connect it to a "preview" emission shader.
In my case the diameter is 5 BU, as can be seen with Length enabled in 3D view > Properties region (N) > Mesh display while in edit mode:
The Map Range node is a node-group which I created based on the implementation in the compositor:
The To Max and To Min values can be adjusted to control the maximum and minimum amounts of refraction. Setting To Max to a higher value will result in more distortion.
Remember to set the color of the refraction node to pure white, so light doesn't get absorbed while bending through the refraction object.
- As each ray will have to go through many surfaces, make sure the maximum bounces is set high enough in Render settings > Light paths.
- You may want to disable the effects of the refraction object on other objects, as they won't be correct. Light is only bent the way we want it when it enters through the front (thinking in terms of backwards tracing). If a ray bounces off another object and then hits the refraction object from the side, it won't bend anywhere near how it should.
Of course, it's not any more correct to just disable it, but this should help with rendertimes a bit if there are lots of other objects in your scene.
See the manual for more detail on ray types.
- Make the black hole always face the camera.
Now our light bending setup is almost complete, but for it to work properly it must rotate so only the front is visible to the camera.
To do this, add another empty (⇧ ShiftA> Empty > Sphere) and parent the refraction object, array empty, and diffuse sphere to it with ⎈ CtrlP:
Add a Copy Rotation constraint to the empty, with your camera object as the target. You may need to enable Offset and rotate the empty in order to get the flat side of the half-sphere face the camera:
If you're wondering why we're not using a Track To constraint, see Planes rotating to face the camera, but only along one axis
Note that this only covers the lensing part of the black hole. I'll leave the high-energy matter and the accretion disk to you, as I wouldn't want to take all the fun away ;)