HFC Tutorial

First part: first contact

Image parameters

Here comes a nice cliff, probably coming from Brittany as it was provided by Marc Jacquier, from Lorient. As we are dealing with acknowledgements, let's add that he is the author of the demo scene (except grass), which sky uses ideas first developped by Jaime Vives, and that the sea uses ideas by Gilles Tran.

Well, this scene seriously lacks grass. We are thus going to make it grow. First, the image used as a height_field is 1024x640 pixels, as both dimensions must be multiple of 32. The scale used inside POV-Ray is 40 horizontally, and 5 vertically. It is mandatory to have the same scale for both horizontal scales (lenght, width). Our image not being square, the POV-Ray code should look like this:

height_field{
  png "cliff_1024x640.png"
  smooth
  texture {T_Rock}
  scale <40, 5, 40*640/1024>
  translate <-20, 0, -20>
}

Knowing this, we can import our picture in HFC. First, start the software by double-clicking on the jar file icon, or type java -jar hfc.jar on a command prompt. Click "Open", select the image and click "OK". The field giving the image size displays 1024x640. Now we need to enter the size of the cliff in our scene:

Please always press "enter" after changing a value in the GUI. Now it's done, we can start having fun.

Packing

As the main page explains, the packing algorithm cuts the main image into small squares and then searches for similarities betwwen them, resulting in dramatic memory footprint savings. This packing step is a function of the "threshold" parameter, which is the maximum acceptable relative height difference between two blocks. To avoid flying or underground grass, this value must be lower than the height of the blades. A good value is usually around one quarter to one third of the blades length. We are goind to sow high grass 60 cm (2 feet, 0.6m) long: a threshold value of 0.2 is suitable. Set the slider to 0.195. As most HF images only feature 256 height values, the slider is limited to those available values.

The other packing parameter is the block size. The defalult value of 8x8 pixels is suitable for most uses, and we will use it. Bigger blocks will lead to less repetitive patterns, at the expense of a much higher memory footprint. With 8x8 blocks, the image logically features 10240 blocks.

In this first try, we are not going to tune block choice, so we can check the "basic packing" box. Now click on "start": the progress bar shows the dictionnary building, then the HF packing itself. When it is done, some dictionary information is displayed: it features 52 blocks, 7 of which are used only once. This shows how strong this packing algorithm can be: 52 blocks are needed to describe a 10240 blocks map, which is only 0.5%. The seven lonely blocks are located in critical areas, different enough from the rest to need dedicated blocks.

Export

For this first try, we'll keep it simple. Grass blades will be of the "crossed triangles" kind, and slope will be ignored. We just need to set the blade height to 0.6. Click on "export", enter a file name, like grass.inc, and click "ok".

Integration inside the scene

The exported file is not intended for manual editing. It must be included in a wrapper file, which is quite easy. This file only contains grass blades sets, with no fancy stuff like texturing, declarations, union or the like. To add plain green leaves to your scene, add somewhere like after the HF declaration:

union{
  #include "grass.inc"
  pigment {ForestGreen}
  translate <-20, 0, -20>
  }

Assuming you start with the previous scene, you should obtain the following rendering:

This picture is a bit boring, so we are going to improve it gradually.

 


Table of contents 2. General improvements


© François Dispot 2003