Rendering true depth of field

Project Page Next project post Post History

In my efforts to continue to make Hyperion physically correct, I've now tackled true depth of field. No fakery or cheap post rendering tricks, but proper adjusted photon casting.

There are a few ways to 'fake' depth of field. One of the more common ways is through some sort of Gaussian blur, based upon the depth of the coloured pixel. While these methods can give pretty good results, they're not technically correct. Often render engines won't do physically correct depth of field, and instead choose traditional fake methods because it's considered too computationally expensive to get a good clean image.

But we won't be faking anything with Hyperion!

When designing the render engine, I knew I was going to need some attributes and object structures that would allow me to add things like depth of field into the engine. This included designing my own camera, sensor and lens structures to house that data, like a real world camera. By adding these from the beginning, it made it easier to implement later on. Thinking ahead.

My first attempt at depth of field didn't quite come out right, though it was pretty close! You can see in the image below, that the whole render is blurred.

First depth of field render. The photon casting position isn't quite right.

I realised that I'd forgotten to adjust the casting position from the camera lens' axis centre correctly. I was adding some numbers together, when I should have been taking them away (subtracting them!). Here's another render with the position and direction vectors corrected.

Depth of field with corrected position and direction vectors.

It didn't take me long to achieve this in the end, because I'd already built quite a bit of the camera and lens structure under the hood. All I had to do, was make the code to use them. Pretty much came to about 7-8 lines of code, with a couple elsewhere just to polish some lens attributes, and voila!

Being physically correct means it should tie in well with the digital cinema camera. I'm still to overcome the camera pose problem, which is another issue I may be at that for a while yet. But we're still etching closer to our final goal.

Here's a slightly 'better' render showing the out of focus background. The image is not without it's problems, you can see there are a few black pixels around the place. I believe we call these ray-acne, so if I'm right on what they are, I'm fairly sure I know what needs to be done to resolve these. But the render itself shows what should be physically correct depth of field and blur.

Render with physically correct depth of field, showing out of focus background, with the lens aperture set at T1.5.