Coastline Foam

Based on horizontal distace to shore


This tutorial deals with the creation of foam along the coast. The traditional way of creating foam in previous versions was based on the concept that objects that are close to the water's surface will form foam. The closer they are to the surface the more foam there will be. This was achieved by utilizing the function editor node 'distance to object below'. The 'object' could be the underwater terrain. (or in fact any object that was positioned in the required place and made transparent). In Vue 7 creating coastline foam was incorporated in the new water editor which made it easier to control.

I decided I wanted a method which is based on the horizontal distance to the coast rather than the distance to the ground (or object) below. I found the concept itself more intuitive and hoped to achieve several practical advantages too. Mainly, I won't have to rely on the shape of the terrain itself under the water surface. For example, it will be possible to have foam above steep underwater coastline cliffs and also shallow water without foam if its further from the coast.

Another technical problems is that currently you either see the abrupt underwater terrain's edges or you need to have the ground plane touching the terrain for continuity, which may not be OK in other areas of the image. In parallel I was hoping to be able to eliminate the crisp continuous white line you get at the intersection of the water and the terrain as by definition the distance to object below is identical to zero there, and not realistically looking.

The method I developed has three stages: extracting the shape of the coastline using Vue; creating a greyscale mask defining the region in which foam can form using a 2d image editing program (I used the free software 'The Gimp' but other programs like phostoshop can be used just as well); using the mask in vue to create the foam material. I created a foam mask meta-node which simplifies the use of this method by those who do not want to get into all the details of the function editor.


Stage 1: VUE


Get a template for defining the coast line.

  1. Add a water plane. In the water editor set coast foam to none. Initially I had wave foam at none too). I positioned the water at z=0 meter.

  2. Make the terrain . Raise or lower relative to the water level so you get the amount of your choice above water. (Mine was z=-6).

  3. Make sea black and terrain contrasting color (but not completely white). (You can use the highlighters in the material editor)

  4. Set camera to a top view (pitch=180). My render size was 512x512 and I set 'blow up render'. Do an area render of the terrain only (I got 513x507, this can be adjusted in the next stage). Save as FoamTemplate1.tif




Stage 2: GIMP (or any other 2d image editing application)


Create a mask for the foam region

  1. Open file FoamTemplate1.tif.


  2. Set canvas size to 512x512 (center image).

  3. Select by color, click on black area, fill with white, invert selection, fill with black .

  4. Grow selection (5px), fill with black.


  5. Grow selection (5px), fill with dark grey(value=35).

  6. Select by color dark grey, grow selection (5px) fill with middle grey(Value=70)

  7. Select by color middle grey, grow selection (5px) fill with pale grey(Value=90)


  8. Filter->blur->gaussian blur(5px)


  9. Save – FoamMaskGmp.tif



Stage 3:VUE-


Create foam material and final scene

This is my simple scene, just the islands-terrain, a foam plane, a ground plane and the sea.



  1. Terrain: Clip minimum of the terrain in the terrain editor so that the square edges arnt visible, or just below the water leve if you don't need to see any of the underwater terrain. l(I set it to 12 which corresponded to water level, note the terrain editor units are not in meters!)

    As material I applied two layers – 'rock and grass' and 'wet stones'. The 'rock and grass' appear at altitudes 0.1 to 1, bottom fuzziness of 48%. This of course has nothing to do with the foam, you can use any material.

    You can still adjust the vertical (z) position of the terrain to be somewhat lower and it will still work because the foam extends below the island as well. (Although the mask is uniformly black there, no grey.)

  2. Sea: You can set the waves and their foam using the water editor. I set the color to dark'ish blue to get a nice contrast with the foam, and I turned the tranparency down to 90%.

    Coast foam in the water editor will still work but may not be compatible with the special foam we are creating.

  3. The ground is barely visible, just set the color to something 'reasonable'.

  4. I made the foam plane by duplicating the islands-terrain and flattening it. (In the terrain editor or by scaling down in the z direction). Make sure these two terrains are aligned in the x,y plane.

    I grouped the islands and foam object because their alignment is important.In the z direction, position foam plane just slightly above water plane. (so that it isn't hidden if you add displacement waves.)

  5. Apply the foam material to the foam plane. (see scene image above)

    If you have my coast foam material, select the plane, double click on the material icon on the top right[1]. The (advanced) material editor will open. Double click the material thumbnail [2] and find the foam material on your disk. The mapping should be 'object-parametric' [3].

    You can customize the material in the function editor.

    Alternatively you can costruct the material yourself as shown in the images below. (Dont forget to chose 'object parametric' mapping)

  6. Open the function editor by right-clicking the icon in the lower panel [4]. Three output nodes are used, Color, alpha and bump.

    -Color: Traditionally a constant white color is assigned to the output color node, I asigned a pale blue color (paler tone of the water color) because useually I find the white too stark.

    -Alpha: This is the important node. It will determine where the plane is opaque and you see the white(pale blue) color of the foam and where it is transparent and you see the water plane underneath. Most of the work is done by the meta node 'mask and base foam pattern'. I added an additional noise node between it and the position input node, to show that you can further modify/refine your foam. You could add as many more noise nodes as you see fit, comine them and then connect to the meta-node.

    -Bump: In most foam materials I've seen, there are no bumps. I added a combination of two prelin noise patterns here just to demonstrate the possibility of adding them for close ups. (They

would need to be connected to the 'position' node to be activated)


The meta node:

    You can use the meta-node without knowing its inner-working. Just chose values for the parametrs in the pannel in the lower part of the image above.


    Coastline:

    Map- To load your own mask click the arrow on the left, under the map thumbnail, and browse to the location of your mask on your disk.

    Amount of foam- try adjusting this number to get less or more foam.

    Foam pattern: ( same parameters that define prelin noise.)

    Wavelength- smaller numbers result in closer spacing of the foam segments.

    Largest/smallest features – biggest/smallest size of foam segments

    Roughnes – cant find better words to discribe it, experiment!

    Gain- the contrast between the whitest and blackest regions in the map.

    The following is an explanation of how the meta-node works, but it should work even if you dont understand it :)




    Combining the mask region with the foam pattern requires keeping the foam pattern(base+external pattern) in regions the mask is black, discarding it in regions the mask is white, and attenuating it in regoins were the mask is grey. This can be achieved mathematically by having values in the range 0 to 1 for white(discard) and black (keep) respectively. As this isnt the standard definition of grey scale maps, we need to use the mapping node to convert the values.

    (Note that for the foam pattern we want to keep the white and thus a different map is used)

    After applying the maps to the mask and the foam pattern, they are combined using the multiply combiner.

    The multiply filter is used to adjust the amount of foam, and then a mapping node is used to convert the values back to the standard definitions for a transparency grey scale map [-1,1]




The final renders:

Just to point out a few features:

-The foam follows the cosat line.

-Overall it fades with the increasing distance from the shore

-There is no uniform white line at the intersection of the water and the terrain.

-The distribution of foam patches is varied in location, shape and size. Even right next to the terrain there are some foam-less regions. This seems like a natural behaviour to me.



Thank you for reading my tutorial, I hope you find it useful.

You can send comments/questions to

art.pearls@yahoo.com


If you want to see some of my work (computer graphics, watercolors and some photography) please visit

http://ArtPearl.redbubble.com/