Tutorial (iii) - Manual Image Compositing & Focal Blur



I have never been entirely satisfied with Forester's built-in compositing algorithm, and have often resorted to manually processing the various images and masks to achieve a better Forester/Terragen composition. This tutorial is intended as a brief guide to manually compositing Forester objects onto a Terragen scene.

The graphics package I have used is Paint Shop Pro v4, which has all the necessary masking features (and, most importantly, came free on a magazine cover disc)! Most graphics packages offer similar tools, though they may have different names than the ones I use in this tutorial.


1. Render the images

The first step is to render the images needed for the composition. There are 5 required images: Terragen Scene, Forester Scene, + 3 masks:

Terragen Scene

Find a suitable view (using Terragen or Forester), and copy the camera parameters from one program to the other so that the scenes are identical.

Render the full Terragen view, including surface textures, haze, etc. Notice that I haven't included any water in this Terragen image. This is because in order to get reflections of the objects in the scene, the water will be taken entirely from the Forester image.


Forester Scene

Ensure that the camera parameters are the same as those used for the Terragen image, and that the sun heading and altitude are the same.

Use as similar a cloud formation in the Forester image to that in the Terragen image as possible so that the reflection in the water looks believable.

Try and achieve a similar surface texture to the Terragen image so that any reflective objects look acceptable.

NOTE: I have rendered the scene using the main Forester 'Render' window - this gives better results than the 'Main Objects' option in the 'Merge Images with Terragen' window (this render is effectively obsolete).

Mask 1 - Objects Mask

This is the most important of the three masks as it contains the information required to extract the objects from the main Forester scene and overlay them over the Terragen image. It can also contain depth information (by setting the half-height and density parameters to non-zero values). However, for this particular composition this information is not required, so these parameters were set to zero.

The Red, Green and Blue colour information in each pixel is completely independent, with each storing information about Objects, Terrain and Water respectively. Note that if anti-aliasing is used, then a pixel can contain an amount of each colour component, but each can still be treated separately.

NOTE: If depth information is included (by using the half-height and density parameters), then this can be extracted by summing up the Red, Green and Blue components. Due to the way the scene is rendered, the sum of these components will never exceed 255.

(The depth information is actually also related to height as it is created by using a graduated black fog in the scene. To reduce the effect of height, use a large half-height value).

Mask 2 - Shadows Mask

The Shadows Mask contains information about the shadows projected by the objects onto the landscape. This can be extracted by examining the Green or Blue components (which will be the same) of each pixel: a zero (black) amount indicates the pixel is either in shadow or is part of an object, a 255 (white) amount indicates no object or shadow.


Mask 3 - False Shadows Mask

The Shadows Mask (above) actually contains some extra unwanted information: shadow projected by the landscape onto the landscape.

The False Shadows Mask contain only this information, which allows it to be subtracted from the Shadows Mask to give a 'true' object shadows mask.

2. Extract the Shadows Information

As noted above, the Shadows Mask needs to be edited to remove the shadows caused by the terrain itself. The steps are as follows:

  1. Extract the Green or Blue component from the Shadows Mask. (In PSP use the Image/Channels/Splitting command to separate the channels).
  2. Invert this new image.
  3. Invert the False Shadows Mask
  4. Subtract the False Shadows Mask from the Shadows Mask (In PSP use the Image/Arithmetic option to do this).
- =

3. Add the Shadows to the Terragen Image

Now comes the clever bit. The mask created in step 2 above contains information about the objects and their shadows. What we need to do is use this information to darken the areas of the Terragen image which are in shadow from the objects. The mask needs to be applied to the Terragen image. In PSP this is done using the Masks/New/From Image... menu. Ensure that the 'Source Luminence' is selected and the 'Invert Mask data' is unticked.

With the mask applied, any tools that are used on the masked image will only affect those areas where the mask is white.

There are various ways in which the shadows can now be applied to the image. You could either use the Pen or Spray tool with a low opacity to paint a dark colour over the image. Or the Retouch tool with the 'darken' option selected.

I have opted for the simple choice of using the Hue/Saturation/Luminance function to reduce the Luminence of the image (remember though that with the mask applied this will only affect the shadowed areas). In PSP use the Colors/Adjust/HSL function and set the Luminence value to -30%:

4. Extract the Objects/Water layer from the Objects Mask

Now that the Shadows have been applied to the Terragen image, we can concentrate on overlaying the objects on top. The red channel of the Objects Mask contains the necessary information to extract the objects. However, because we also have a water layer to extract from the Forester image, the blue channel of the Objects Mask also needs to be used. The steps are:

  1. Split the Objects Mask into the three RGB components.
  2. Discard the Green channel and add the Red and Blue together.

This gives the following mask:

+ =



The white area indicates the parts of the Forester image that will be overlaid onto the Terragen image.

5. Composite the Objects onto the Terragen Image

Apply the Mask created in step 4 above to the Terragen image (from step 3). We now need to use the Clone tool to copy areas from the Forester image to the Terragen image. In PSP use the Clone tool in 'Aligned' mode. Shift-click on the Forester image at the (0,0) cursor position. This sets the relative point to clone from. Next, click on the Terragen image at the (0,0) cursor position. This set the relative point to clone to.

Now, as the tool is dragged around the Terragen image the respective area will be copied across from the Forester image (and with the mask in place this ensures that only the objects and water are transferred):

6. Final Touches

The composition is pretty much finished. However there are a couple of further touches can could improve the image. In particular the trees in the background look slightly too dark in comparison to the rest of the terrain (due to the haze). By combining the masks created in step 2 and step 4 (use the Arithmetic option with the 'Lightest' function), a third mask can be created to allow these areas to be blended with the surroundings. Use the spray tool with a bluish colour (to mimic the haze) and a very low opacity to selectively adjust these areas.

Slight adjustments to the brightness and contrast, plus an unsharpen mask complete the picture:





Focal Blur

Heres a little trick I've been experimenting with recently:

1. Re-render the Objects Mask in Forester using a higher half-height and density (I used 100 and 20 respectively):


2. Split the image into the 3 component channels.

3. Add the three channel images together - add Red to Green, then add this result to the Blue. (NOTE: This is more accurate than simply converting the image colour-depth to greyscale, as it ensures that the three component colours are added together equally. When converting to greyscale, there is a bias towards the green channel, followed by red and finally blue).

4. Invert the image:

5. (optional) Use the Curves function (in Adobe PhotoShop) to adjust this image so that the darkest part occurs where you want the sharpest focus and the lightest parts where you want the most blurriness. Here I've tried to centre the sharpest areas on the balloon.

6. Apply this image as a mask to the finished image from step 6 above.

7. Apply a Blur filter a couple of times until you achieve the required amount of Focus (or lack of it). :

You can view my final fullsize image here (1280x960 - 230Kb)