Loopable Chaos - Volumes!

In my previous tutorial, I discussed a method of using combinations of 3D textures to create a sequence of 2D images which could be looped, yet still appear to be ongoing chaotic change. However, that technique won't work if what you want to create is a 3D volume, resulting in a 3D movie you want to be able to loop. For example, a fire in a fireplace, with logs and all. If you try to employ my previous technique, you end up with a dancing volume that appears to have at least 2 distinct portions to it: some sliding up and some sliding down.

In order to emulate a fire in a fireplace, the texture needs to move up and only up. Any downward motion just wouldn't look right. However this leads to a serious problem - you can move a 3D fractal texture up all you like and you're not likely going to hit a space where the pattern starts over. You'll never make a loop.

Let's start with some basics: create a new scene, place the default distant light at 0,0,0 and point it straight up. Then, open the property panel for it, select "Volumetric Lighting" (remember, you need to also enable volumetric lights in the global Render options panel), and then click "Volumetric Light Options." To save a little time, load this preset. I then changed things a bit: set the Radius and Height to 1m, and Attenutation to 40%. There, that clears out some of the grunt work. On to the real meat.

Move your camera in reasonably close and render frame 0. Looks reasonably like a flame in a fireplace. Once again, if you should render out several frames, the texture won't move at all because we haven't animated it yet. Open the Volumetric Options panel for the light again and click "Edit Texture". You'll see three layers to this texture. The Gradient layer controls color output so we're not going to play with it at all. For the two Turbulence layers, apply an envelope to the Z channel and have frame 0 at 0m, and frame 120 at 10m. For me, this results in the right speed for flickering flames in a confined fireplace. If you render out frames 1 to 120 (don't start at frame 0), you'll get yourself a nice fire movie. Only, it won't loop nicely. Once again, there's no relationship in the texture between the first and last frames.

Here's where we'll get tricky: what we need to accomplish is a method of getting the texture to repeat itself. Since only the Ripples texture intrinsically loops, and we're not using that texture, we need to fake it out. Add a null object to the scene, name it Fader, and place it at 0,0,0. Then at frame 120, place it at x=1km. Now go back to the volumetric texture panel and add a new gradient texture to the top of the list. Give it an Alpha mapping mode, an Input Parameter of "Distance to Object", the ref object of "Fader" and give it two keys: 0m all white, 100% alpha, and at 1km, all black, 100% alpha. If you render out the sequence again, you'll see the flame slowly fading away.

Now, clone the light once. On the clone, edit the volumetric texture and invert the keys on the alpha gradient. If you render out the sequence again, you'll notice it looks exactly like the first render you did. In this case, the first light is slowly fading out, while the second light is slowly fading in. The two combined result in the original 100%. But it still doesn't loop.

What we need to do is make it so the end of the animation of the second light matches the beginning of the animation of the first light. Once again, open the volumetric texture panel for the second light, and change the Z location keys of the two Turbulence layers such that they move from -10m at frame zero up to 0m at frame 120. If you render frame 0 and frame 120, you'll see they're identical. Now render out the sequence (remember, frames 1 to 120 - don't include frame 0). If you loop it, you'll get something like this.

Note that this technique is also useful for creating loopable 2D image sequences: Since we're making a volumetric texture that repeats in a series of frames, you can take any 2D slice of that texture and get a repeating sequence of images.

(I've discovered a Lightwave bug: it won't save the scene properly, and reloading it won't render stuff out correctly. It loses the reference object for the two Distance to Object gradients. Load the saved scene file in a text editor and search for "Distance to Object". The following line will be 'ItemName ""'. Insert the word Fader in the pair of double quotes - do it for both instances! The scene will now load correctly, and oddly, save correctly too.)

Loopable Chaos

I've been working on a Stargate (see a few pictures) and one of the primary problems is the open wormhole. It's supposed to look like a water surface. The problem is it takes too long to render all that detail. I wanted to make an image sequence and then use that as a simple texture on a single polygon. The sequence had to be long enough that viewers can't notice the loop yet short enough that it doesn't take up too much disk space or too much time to render out.

This tutorial will cover how to make an image sequence that can be looped, yet still present the illusion of ongoing chaotic change. It will be a tutorial, not a recipe. Some amount of your own creativity is required.

Lightwave comes with many different flavors of fractal noise, and animating that noise in some way is pretty easy. Let's start with an example. Start Modeller and create a rectangle that's perpendicular to the Z axis:

OK, save it. Load that into Layout. Open the surface editor and set Double Sided (not strictly necessary, but it saves us the effort of properly aligning the polygon to the camera). Change the surface color to black. Assign a procedural color texure, and pick one of the myriad fractal noise functions. Set the scale to something appropriate so you can see some level of detail. Set the procedural texture color to white and do a test render. You should see something like this:

If you were to render several frames, they'd all come out the same since we haven't animated it yet. Since the rectangle was built perpendicular to the Z axis, changes in the texture's Z position will provide the best illusion of random variation. Moving the texture's position along the X or Y axes will only give the illusion that the texture is sliding around and not really changing.

Go back to the texture editor and click the Position tab. Then click on the E button to the right of Z. The graph editor will open with the Z axis selected.

Decide how many frames the animation will last. Note that if you plan on using the Ripples texture in your mix of procedurals, it will dictate how many frames you should use. The wavelength divided by the wave speed gives you the number of frames before the texture repeats itself. Be sure to choose useful values here so that the division results in an integer! Or, if you're going to use multiple Ripples textures, use the least common integral multiple for all instances to determine the frame count.

I'm not going to use Ripples in my mix so I'm going to arbitrarily use 60 frames. At frame 60, create another key and assign it a value:

Render out frames 1 through 60 (not 0 to 60) and you'll get something like this (you will need Windows Media Player v9 to view). However, there's a problem. The last frame rendered isn't the same as frame 0 would have been (had we rendered it) and so it won't "lead in" very well to frame 1. In fact, the whole tail end of the sequence has no relationship with the front end of the sequence. Consequently, the loop has abrupt jumps in it.

The solution is to use the Oscillator motion modifier. Delete the key at frame 60 and then click on the modifiers tab. Add Oscillator and open its property page. Set it up like so:

Note that the cycle time is 2 seconds (I'm using 30 fps), so the whole cycle will last the 60 frames. Also note that the start of the cycle is frame 0, but we'll be rendering starting with frame 1. This way, mathematically, frame 60 is the same as frame 0, and it'll loop nicely. Here is the result, and here is the loop.

It's better, in as much as the sequence loops nicely. However, this isn't good enough. It looks like it's see-sawing. The sinusoid is ridiculously obvious. We need to add to this to get rid of those pauses where the texture turns around. Go back to the texture editor and clone this layer twice. Set the two top layers' blending mode to additive and set all three layers' opacity to something between 30 and 50 percent (otherwise it'll get all washed out). To maximize the effect, we need to move all three textures to different base x,y positions (exact location is pretty much irrelevant - just as long as they're not overlapping):

Now change the oscillator settings so that the first one has a phase of zero (it should have that already), the 2nd has a phase of 120 degrees, and the third has a phase of 240 degrees. Looking at just the Z axes will show this:

The important thing to note here is that while any one of the textures is at a crest or a trough, the other two are changing rapidly. You can use any number of texture layers, as long as it's an odd number. I'll leave it as an exercise to determine why using an even number isn't helpful. The phase values for each layer should be L*360/C, where C is the count of layers and L is the layer number. When we render this out, the noise should be devoid of any noticable pattern. Here is the result, and here is the loop.

So there you have it. Now you know how to make a small sequence of apparent randomness that will actually loop for you. Watch for movies of my stargate that exploit this technique. You can apply it to clipmaps, bump maps, deformation maps - anywhere you can use a procedural texture.

UPDATE - It occurred to me that this can be done with just two layers where one has a phase of zero, and the other has a phase of 90. Any other even number of layers doesn't buy you anything (again, think this through for yourself).

ANOTHER UPDATE - There's an even easier way to do this. See my new tutorial for accomplishing this with whole volumes here.