Tutorial 6

Displacement Mapping a Texture

Bumping Up a Surface - How to Create a Waving Flag

What is Texture Mapping?

LightWave allows you to generate surface texture and colour in several different ways. For example, the application of a Texture Map to a Surface is achieved by clicking the 'T' button alongside the Surface Color selector on the Surfaces Panel. This allows you to apply a variety of procedural textures to the selected Surface, via the pop up Textures Panel. You can also apply an image as a brush map using this panel. You can also modify the surface transparency and/or reflectivity in a mathematically controlled way. More comprehensive details on Texture Mapping can be found in the WaveGuide Manual.

Things that go Bump

At the bottom of the Surfaces Panel, there's another 'T' button to activate the Bump Mapping system. Bump Mapping further modifies the appearance of the Surface via a subtle control of lighting. It creates the appearance of a displaced surface by applying light and shade. So, while the rendered Surface appears to be rippled, rutted, veined, lumpy, creased, etc., it actually remains the same shape it was in the original Object. It's a very powerful system, but sometimes you need more.

What is Displacemant Mapping?

Sometimes, the Surface itself needs to be shifted around to create the desired effect. For example, consider a flag waving in the breeze. Let's say you wish to create this as a scene for an animation sequence. Though it's possible to use light and shade to create the appearance of waves, the flag object will render as a flat rectangle. Not very convincing. So, if you want realism, you need the real thing. You need the flag itself to be animated with a wave motion.

Make no Bones about It!

Now you could attempt this effect using Bones. LightWave's Bones system is a powerful way of displacing surface Polygons to make a new shape for the Object. There's a comprehensive Tutorial on the use of Bones in the WaveGuide Manual. However, a situation like a waving flag needs a complete surface displacement, progressing across it in a controlled and fluid manner. That's not so easy with Bones. I've tried Bones as suggested in a waving flag Tutorial from another LightWave site and it proved exceedingly difficult. I don't recommend it. However, Displacement Mapping is real easy!

Real Bumps!

Displacement Mapping creates real bumps! Bumps are made by moving the surface polygons above or below their default position. They actually move 'up' or 'down' their Normals. For information on Polygon Normals, refer to Tutorial 1. The resulting bumps may be perfectly regular or completely random. They can be derived internally using one of LightWave's procedural routines or they can be derived from an image applied to the Surface as a Displacement Map. In that case, Polygons are displaced according to the luminance (brightness) of the image pixels 'located' within them. You can use any sort of image providing it has a reasonably wide brightness range. You can also create Displacement Maps with a paint package. A greyscale image is best, so you can control the highs and lows very easily. White areas raise the Polygons, black areas depress them. The 'Dune' image shown on the Gallery page was rendered using a Displacement Map created in a few minutes with Photogenics.

I Wanna Make Waves!

So how do you go about applying a Displacement Map? The starting point for this is the Objects Panel, which pops up when you click the Objects button on the Layout interface. Go to the centre right of the panel, where you'll see another of those 'T' buttons, labelled Displacement Map. If you click that, the Displacement Map panel pops up. Well it does if there's an Object loaded into Layout, but we don't have one yet. So let's not get ahead of ourselves. We need a flag to wave!

The Flag Object

Well, a flag's pretty simple isn't it? It's just a rectangular Polygon isn't it? Well, no, it's more complicated than that, especially because we require it to 'wave'. To get a really smooth, wavy surface, the polygon count should be pretty high and they ought to be triangular for optimal results. The reason why triangles are the preferred form for animated Polygons is discussed at length in the WaveGuide manual, so I'll not dwell on it here.

OK, pop over to Modeler and we'll create the Flag Object. There are a couple of ways to create the basic rectangular shape of the flag. You could establish (Make) Points at each corner location and then Make these into a rectangular polygon using the Polygon menu. You would do this after first selecting the Points in a clockwise (or anti-clockwise) order. If you wanted an irregularly shaped flag, using a large number of peripheral Points, this may be the best approach. For a regular, rectangular flag, the quickest method is to create a flat Box Object. The Box is a native Object format located within Modeler under the Objects/Create/Box buttons. But before we do any creating, let's make sure that the Polygons we generate are appropriate to the job in hand.

Single-Sided, Fewer Problems

First off, click the Options button on the left hand side of the Modeler screen. This button is available after the Objects menu is selected at the top. The pop up panel allows you to control the type of polys created by your excursion into Modeler. Make 'em Single-Sided and Triangles, as shown in the following grab. You can leave all the other settings at their defaults. Using the Single-Sided setting avoids the creation of duplicate polys on the 'backside' of the Box object we'll use for the flag. It's no big deal, but if you forget that the Box object is has a front and a back face, you could end up with hundreds of polygons you don't need and that adds up to slow rendering. Triangles are best for reasons already noted.

OK, now that's sorted, click the Box button. This puts the cursor into Box creation mode, so you can now draw a suitable Box outline in one or other of the View windows using the LMB. Logically, the outline of our flag should be seen in the Face window. I've dragged out a 2x1 rectangle 'cos that's the shape of the Union Jack image I intend to use on the flag surface. (There's more on the sizing aspect later.) You don't need any other dimension to the Box, so the other View windows show a simple line. The Box has no depth, it's just a flat plane.

OK, click the Make button to complete the job. You should have something like the following screen. Remember that we specified Triangles, so the flag is split into two. Perfick!

We now need to Subdivide these triangles into much smaller ones. The required wave motion will not be very lifelike if the flag has only two large triangular polys to do its stuff. So, click the SubDiv button under the Polygon menu. This pops up the Subdivide Polygons panel as shown below.

Leave all the settings at their defaults and click OK. The triangles will be divided into smaller ones. Here's what you get.

However, there are still not enough Polygons in the Flag Object to render a smooth, wavey surface. So, Subdiv a couple more times. More if you want to achieve a really smooth result. You should get something like the folowing graphic. Here, there are 512 polygons, but you may end up with many more. If so, be sure you have plenty of RAM and a fast processor! You can check the number of Polygons using the Stats button under the Display menu.

OK, I reckon this is good enough for an animation sequence. The next thing to do is to assign a suitable name to the flag's surface, so we'll recognise it when everything's transferred to Layout. Naming a Surface requires the area in question to be selected. However, since ALL our flag surface will have the same name, just go straight into he naming procedure. (The logic behind this is that LightWave considers ALL the Polygons to be selected if NONE are selected before the operation. Think about it!) You do the naming under the Polygon menu. On the left hand side, you'll see a button labelled Surface. Click this to pop up the Change Surface panel, shown below.

Enter an appropriate name for the surface to replace 'Default'. How about 'Flag Surface'...? You don't have to apply any particular colour settings 'cos we'll be applying an image map, which over-rides any colour values applied to the Surface. However, you should check the Smooth button to improve the render.

OK, the Flag Object is about done. All that's left is to Save it to LightWave's Objects directory under an appropriate name. I reckon 'Flag.lwo' says it all. Just click the Save button under the Objects menu and away you go. Now let's get into the interesting stuff!

OK, Let's make Waves!

Go into Layout and load in the Flag.lwo using the Load Object button on the Objects pop up panel. It should appear somewhere near the Layout origin as shown below.

Go back into the Objects panel and look for the 'T' button labelled Displacement Map. It's on the right hand side of centre. Click this to activate the Displacement Mapping functions. Here it is..

The Displacement Map panel will appear. This is where you select the procedural mapping routine you want, or nominate a Displacement Map Image. The latter will be accessible under the Planar Image Map option provided by the Texture Type scroll bar. You must have an image already loaded for LightWave to use it. You do that via the Images menu. In our case, we need Ripples. That's the procedural routine to create waves across the flag surface.

The Ripples control panel has various buttons with which you can modify the effect. Let's take a look at some of these controls.

All About Ripples

I visualise the Ripples procedure as something like tossing a pebble into a pond. The point where the pebble hits the water is the Center for the Ripple texture. Everything emanates from this point. LightWave's Ripple texture is actually three-dimensional (as all procedural textures are) so the waves are in fact spherical. When applied onto a flat surface, like the pond surface or our flag, you get a series of concentric, circular waves progressing away from the splash site. The default Center position is (0,0,0) which is the axial origin. Since this is near the centre of our flag model, we'll move it off to one side to get the waving effect. Also remember that with Ripples, the wave generation is continuous. OK, that's easy enough to understand. What's the Texture Opacity?

The Opacity of a Texture is only relevant when you apply two or more different ones to the Surface. This can be done with LightWave 4 and above. The Opacity is the perentage 'contribution' any Texture has to the final surface appearance. With a single procedural Texture, leave this setting at the default 100%. OK, what about Wavelength?

Wavelength is the distance between the waves created by the pebble. A large rock thrown into the pond will create a large Wavelength. The waves will be big and well separated. A tiny pebble on the other hand would create smaller, more tightly spaced waves. Their Wavelength is smaller. So, Wavelength is the distance between two wave crests. That's easy enough too, but what's Amplitude?

Amplitude is (more or less) the wave's height above the pond surface. In the real world, a large Amplitude ripple is usually associated with a large Wavelength and vise versa. With LightWave, you can create large Wavelengths with small Amplitudes (like oceanic swells for example) and vise versa. However, if you overdo Amplitude, the waveform will become terribly messy. Start with very small settings and work upwards. You can also vary the Amplitude over time by using the Envelope ('E' button). It all adds to the fun of Ripples! But what about Wave Speed?

Wave Speed is the rate at which the waves spread away from the Center. It's defined in distance units per anim frame. In real life, the speed is determined by the physical characteristics of the medium transmitting the Ripples. That is, the water, the air, the oil, the melted cheese, or whatever other gloop you can imagine. It's controlled by things like density and viscosity. In LightWave, you can make the Wave Speed whatever you like. To get a good looping animation, you'll need to spend some time on the Wave Speed element. The start and end of a loop sequence should be the same, so you don't see a 'join'. With Ripples, the wave crest at the end of the loop should be just about where the start position was.

The easy way to figure this out is to first decide how many frames you wish to use for the loop sequence. You should really set that initially, using the Scene menu. Here, you can fix the number of frames in the animation and other stuff (which are probably best left at default values). Once you've fixed the number of frames in the loop, it's time to estimate the Wave Speed. For the mathematicians out there, it's clear that the wavelength should be divided by the frame number. That way, the start and end frames will appear similar. The answer to this division is the Wave Speed. It inevitably requires a little tweeking in practice, but that's the gist of it. OK, let's talk about the number of Sources.

Sources is a bit more complex. Imagine two or more pebbles hitting the pond surface at the same time. They all have the same Centre, Wavelength, Velocity, etc., but they transmit their waves with differing vectors. In essence, you get a mixing effect. In some places, the waves will reinforce one another, in others they negate one another. The result is a more complex pattern of resultant waves. The larger the number of Sources, the more complex (and slower rendering) is the effect. Numbers should be kept fairly low, six or less. Large numbers add nothing to the result other than slowing down the render speed. For our waving flag scene, a single Source is best.

The only other parameters of note are the Texture Size, World Coordinates and Falloff buttons. The Size parameter is probably the most important of these. It's related to the overall size of the Surface being textured. The default values are usually about right. LightWave does a reasonably good job of matching the size of the Texture to the size of the Surface. However, if you wanted to make the Texture very small or very large in relation to the size of the Surface, this is where you'd do it.

If you check World Coordinates, the Texture mapping routine is 'locked' into the Layout grid coordinates, rather than the Surface's. This means that the Texture will not move 'with' the Surface as the Object moves. The Surface will appear to 'move through' the stationary texture. Wierd!

Falloff determines whether the Texture will 'fade away' with distance. It's expressed as a percentage reduction per unit of distance from the Center. This would be activated if you were trying to simulate real ripples on a pond. The wave gets fainter as the distance away from the Center increases. OK, let's talk about flags!

Flags of the World and Beyond

Now I've assumed we'll create a National Flag of some kind, but you may have different ideas! If you want to advertise your local club or group or the political party you favour, be my guest! Just use whatever image you'd like to have up there, waving in the breeze. All that's needed is a reasonably good image. This should be in a format recognised by LightWave, so Gifs are out I'm afraid (at least as far as the Amiga versions of LightWave are concerned).

For National Flags, a good source is the World Flag Database. From here, you can download whatever takes your fancy. They're all in .gif format, so Amigans will need to convert these into .iff or .jpeg format before use.

The database gives details on the height to width ratio of every flag. You'll be surprised to see how they vary! Anyway, if you want your waving flag animation to be a true representation, make sure you note the size ratio. This should then be applied to the flag mesh we made earlier. Just load it back into Modeler and use the Stretch tool (under the Modify menu) to make the ratio correct. If you don't do this, the flag image may appear too squashed or stretched out.

As I said at the start, I'll be using the Union Jack. This has a 2:1 size ratio (as we designed in Modeler) so the flag image will fit perfectly onto the Surface. Here's the image I downloaded from the database.

It's All Coming Together

And about time too! Let's go back to Layout and load up our .Iff or .Jpeg image by clicking the Images menu button. This provides the Images control panel. Shown below.

Click the Load Image button to get a file requester. Here, locate the desired flag image and away ya go!

The next task is to tell LightWave to use this image as a flat map on the surface of the flag object. So, click the Surfaces menu button. This pops up the Surfaces panel, with which you can apply the image as a Planar Image Map to the 'Flag Surface' we defined earlier. Here's the panel being used to project the image along the Z axis. That's the direction we'll be viewing the flag, so make sure you select the correct axis for your application. For some insight on projection axes, check out Tutorial 3.

Other parameters to note are the Height Repeat and Width Repeat buttons. Deactivate these so you won't get any wallpapering of the image. The image must fit perfectly over the flag surface in 'one go'. Ensure this by clicking the Automatic Sizing button. LightWave will then stretch any image to fit the Surface if necessary. Making the flag the same size ratio as the image will avoid this, of course.

The next thing to do (if you haven't done it already) is set up the Ripples texture for the Flag.lwo. Go back into the Objects panel and click the Displacent Map button as described earlier. The pop up panel allows you to set the various Ripple parameters we've already considered.

This grab shows the Center setting pop up panel. I've placed the ripple Center to the upper left of the Layout stage. This will cause the waves to progress across the flag from top left to bottom right. You can ring the changes on this to suit your application.

When you exit the Displacement Mapping panel, you'll see that the wireframe of the flag.lwo is already being textured by the Ripples routine. If you run a Preview animation render, you'll see how the wave action actually works. Here's what you should see if your Ripple parameters are about right.

When you run this test animation, you'll probably see a glitch as the loop recycles to the start. The easiest solution to this is to change the Wave Speed. Subtle changes to the Wave Speed setting will let you see the direction to go and you'll quickly get things looking OK. When you're happy with the Preview, it's time to sit back and let LightWave do it's stuff.

So, go to the Record menu and set up the image format/anim type and the path for storing your rendered animation or frames. Check the Camera menu to see everything there is to your liking and click the Render button, go for a cup of tea, or take the dog for a walk, depending on the power of your machine. At some stage thereafter, you should get output something like this:

For use on a webpage, you'll need to convert the animation into Gif format. Alternatively, pop over to the Downloads Page, where you'll find umpteen examples ready to use. Now what's the weather like outside? Is the wind blowing?

Go back to the top

Go to Tutorial 1
Tutorial 2
Tutorial 3
Tutorial 4
Tutorial 5
Go back to the Tutorials Page
Home Page
The Gallery
WaveGuide Manual
Other LightWave Sites
My Amiga