This Terragen plugin gives you access to some effects that simulate a real camera lens. Currently the only effect is a depth of field plugin that mimics the foreground or background blurring that you can get, either by design or by accident, when using a real camera.

Downloading and Installation

Right-click on the link below and choose "Save target as" from the pop up menu. Save it into your Terragen or Terragen\Plugins folder (both will work, it's up to your own preference).

LensFX.tgp (100Kb)

This plugin only works with Terragen for Windows. If there's enough demand I might be convinced to port it to Mac. It has only been tested with version 0.8.68 but should also work fine with earlier (and later) versions. If you don't have Terragen yet, you will need to go to Planetside Software to download the feature-limited free beta version.

Once you have the plugin, you just start or restart Terragen, and the plugin will be automatically found and loaded by Terragen.

Within Terragen's Rendering Control dialog, click on the Camera Settings button, then Effects, then the "+" button. If installation was successful then you will see two new entries in the effect list: "LensFX - Depth of Field" and "LensFX - Export Depth Buffer".

Depth of Field Effect

The Depth of Field effect is used to simulate a camera lens so that you can focus on some parts of the scene and have the rest out of focus. You may want to blur out the foreground to emphasise distant features, or to focus very near and have the background blurred.

Choose the effect from the list and click the Edit button on the Photo Effects dialog to get the Depth of Field settings window.

The first thing you will see at the top left is that it's asking you for some Terragen settings you already entered elsewhere, why? Unfortunately at present this information is not available internally to plugins, so we have to ask you to repeat yourselves. The information is needed so that the plugin can re-draw the scene as a "depth buffer". Version 0.9 of Terragen is planned to make this information unnecessary.

The other settings control the effect itself. What you do is select the near and far focus distance limits. Between these two limits the scene is acceptably in focus. The actual focus point will always be somewhere between these two values. The plugin calculates the appropriate focal length, aperture size, and focus distance for the limits you specify, and then processes the image according to these lens settings. Ticking the infinite box for far focus will do exactly what you expect, everything between the near focus limit and the edge of the universe will be sharp!

The science part

Depth of field is the photographic name for the distance between these near and far focus limits. When you focus a camera at a certain point, everything nearer or farther is out of focus and blurred. But, anything that is below a certain threshold of blurring is said to be acceptably sharp and in focus. In photography this acceptable sharpness is about 0.02 millimetres on an 8x10 inch print. In computer graphics we have to think in terms of pixels instead of millimetres so we define acceptable sharpness as a blur amount of less than one pixel (actually, a circle with a radius of half a pixel) on a 1024x768 image. The near and far planes define the distance where the blurring is right on the threshold of acceptable sharpness.

Hints and tips

As you can see from the diagram above, the level of blurring settles down to a certain level the further away you get. The good news is that you can control this level if you want to. The same thing applies to the amount of blurring close up, you can control how much you get. The trick is in the distance between the near and far focus limits. The closer together they are, the more blurring you will get at the edges of the field. For subtle effects keep them far apart, but be careful, you can get almost no effect at all if they are far enough apart!

Think carefully about the final image size. The acceptable limits of focus are based on a 1024x768 image size. If you are rendering smaller or larger than this, the amount of blurring will be scaled up or down accordingly. What is considered acceptable with an image width of 1024 is four times less acceptable at 4096!

At detail settings lower than maximum, you can get artifacts around the edges of hills, where small sections of background or foreground get the wrong amount of blurring. This is normal and will disappear at the maximum detail level. It occurs because the depth buffer is always calculated at maximum detail (see the Hints and Tips section of the Export Depth Buffer Effect below)

Export Depth Buffer Effect

The Depth of Field plugin needs to create a new version of the image called a depth buffer. A depth buffer is a picture where the brightness of each pixel tells you how far away the scene is at that point. Dark is near, bright is far away. You can see what a depth buffer looks like below, next to a render of the scene it represents.

Programmers or artists can do some interesting things with a Terragen scene and its corresponding depth buffer, so this plugin effect can help them out by providing the missing depth buffer that Terragen cannot give them.

The top left of the settings dialog asks you for some terrain settings. The reason for this is explained above in the Depth of Field Effect section. The remaining two options are to replace the image and to output to a file.

Replacing the image means that the final Terragen render will be replaced by the black & white depth buffer picture. Obviously you only want to do this if you either want to see what it looks like, or to save it as a BMP picture.

Outputting the depth buffer to a file will save it as a raw array of 32-bit single precision floating point numbers. Each number represents the distance in metres to that pixel in the scene. The file is not saved with any extra information, so its size will be width x height x 32 bits. The pixels are saved from left to right and from top to bottom, so pixel 0 is at the top left.

Hints and tips

The depth buffer is always rendered at maximum resolution because it is drawn independently of the scene. This means that if you are only interested in the depth buffer then you can simply set the detail level to minimum and cancel the render as soon as possible, and then the depth buffer will be drawn correctly after that. This can save you a lot of time with large renders. For the same reason, if your image is rendered with a lower detail setting than maximum the depth buffer will not match up with it properly.

This website and its contents are copyright © 2003 Alistair Milne,
Terragen is a trademark of Planetside Software,