-turbulence

Figure 1: Now deeper in the cave, yet more evidence was found arguing for an advanced aesthetic among the Mousterian people.

-turbulence is a multi scale noise renderer akin to -plasma, in that it typically replaces the content of selected images with a turbulent effect, though it proceeds through different means and achieves distinctly different results.

Proceeding through a series of cycles or octaves, the command blurs Gaussian noise, subjects it to a mixing function, then scales and blends the results with those from previous octaves, integrating features distinct to each into a final result, one that exhibits irregular blotches and other structures, often appearing at different scales and which can vary considerably in character.

The types and sizes of features present in the results generally increase with additional octaves. That, along with the choice of a particular mixing function, the amount of damping between each octave, and the radius of the Gaussian blurring kernel which filters raw noise, gives rise to a host of effects that can emulate clouds, rock or wood.

Like plasma, turbulence may be harnessed to make height maps for lighting effects and textures. The stone wall in the opening figure was generated, in part, from a turbulence height map. The Finger painting recipe in the Cookbook describes the lighting model that draws out the features of the surface.

The format of the command is:

-turbulence: radius>0,octaves={1,2,3...,12},decay>0,difference={-10,10},mode={0,1,2,3,4,5}

  1. radius: A positive floating point value. Sets the variance, or the radius of effect, of a low pass filter. This filter integrates raw noise exhibiting a Gaussian distribution into a set of intermediary smooth functions, one at each octave, that are mixed into the final image. If results are to have relatively large features (or only large features), then radius should be on the order of 30 → 300 for a 1024 × 1024 pixel image, or one of similar area. Single digit values limit turbulence to relatively small features. This follows from the idea that a Gaussian blurring function is a low pass filter. Increasing radius progressively bars lower frequencies from the results, allowing large scale features to dominate.
  2. octaves: An integer from 1 to 12. Establishes the number of mixing steps. To a point, the number of steps sets the variance among feature sizes in the final image. With only a few octaves, features may be rather uniformly large or small depending on radius (above). With a larger number of octaves, feature sizes may range over a wider gamut. In principle any number of octaves may be employed, but the size of a pixel sets a practical limit. Beyond this limit fine details stemming from higher numbered octaves, are at scales of less than one pixel in diameter and so have no presence in the outcome.
  3. decay: A positive floating point value. Controls the amount of detail carried over from one octave to the next. When decay is small (1 → 2), perturbing noise introduced at each octave may persist through a number of subsequent octaves. High decay (> 4) erodes perturbing noise quickly, so that features established in the first few octaves tend to be the only features that persist through all octaves Setting a large octave count and a large decay tends toward pointlessness, as the fine detail which an increased number of octaves promotes is eroded into non-existence by rapid decay.
  4. difference: A floating point value ranging from -10 to 10. When zero, the resulting image is fully derived from the command's internal pipeline. Otherwise the nonzero argument scales the selected image from which the command then subtracts the internally generated turbulence. The selected image, in effect, becomes a final negative or positive bias function. It is not uncommon for the selected image to be the product of another noise generator, like -plasma, making an aggregate noise generator out of both -plasma and -turbulence.
  5. mode: Chooses both a mixing function and where mixing occurs in the pipeline. At each octave, the command smooths Gaussian noise, producing a function that varies continuously around zero and from which high frequency components have been filtered (see radius, above). The command employs one of a number of mixers that variously reshape the smoothed function. The mode flag chooses the mixer and the number times it is applied.
    1. Mode 0: The mixer entails taking the absolute value of every sample point of the smoothed noise function, after deducting any bias, so that its average value over increasingly large ranges approaches zero. This method forms distinct creases at former zero crossings which emulate cracks, creases and crevasses in the final output image. The command applies this regimen at every octave so that cracks, creases and crevasses appear at every scale.
    2. Mode 1: As in mode 0, but zero biasing and taking the absolute value of the smoothed noise function occurs only during the first octave. There are fewer creases and only at a large scale. The resulting turbulence image may have regions with negative values.
    3. Mode 2: The command uses no mixing method at all. At each octave, the command generates noise, smooths it and blends the resulting smoothed noise function with the aggregate results of the previous octaves. There are no creases and the resulting turbulence may have many regions with negative values. The output of this mode bears a passing resemblance to -plasma.
    4. Mode 3: The command squares the smoothed noise function via -pow, scaling it quadratically as well as inverting negative regions. As in Mode 1, -turbulence applies this regimen only during the first octave. While this method folds negative values to positive in the smoothed noise function, there is no creasing. Under squaring, zero crossings in the original smoothed noise function become local minima, with equal derivatives on each side.
    5. Mode 4: Turbulence folds the original function by squaring it via -pow, as in Mode 3, but applying it at every octave. As with Mode 3, this method folds negative region without creases.
    6. Mode 5: The command folds the original function by cubing it via -pow, applying it at every octave. In common with all odd power functions, this method retains the original smoothing function's sign at every point, zero crossings persist, but the command scales the resulting function in a non-linear way. There are no folding creases, but the turbulence has many small spiking peaks (or pits) of extremely high positive (or negative) value, though, on average, most points vary little from a zero mean.
image/svg+xml

Figure 2: A schmatic of turbulence operation. For each octave, the command blurs noise at a variance radius that is halved as octaves proceed, so that smoothed noise exhibits little detail at low octaves, more at higher ones. The command then applies a mixing function to the smoothed noise. This may be a power function to square or cube the noise, or it may be a conversion to absolute values, folding negative regions to the positive and creating discontinuities at zero crossings. The decay argument progressively damps the higher octaves. The command blends and rescales these octave-based slices into a final image.

Operation

Turbulence goes through a set number of cycles called octaves. The command develops features at different scales by halving, at each octave, the initial radius given as an argument for the low pass filter. As a consequence, only very low frequency features are present in the smoothed noise function produced during the initial octave. However, in the second and subsequent octaves, the radius is halved and halved again, admitting, at each octave, progressively higher frequency components and concomitantly finer detail. In effect, each octave is responsible for a particular level of detail, and with more octaves, a wider gamut of detail may be obtained, limited, as noted, by the dimensions of a single pixel, for it is pointless to generate detail smaller than that quantum unit.

Noise

Each octave begins with the introduction of a standard noise function, its point-wise values ranging from negative to positive ten and exhibiting a Gaussian distribution around a central value of zero (See -noise, in particular its Gaussian mode, mode 0). By definition, the function cannot be differentiated in any direction.

Smoothed Noise

A low-pass filter with a Gaussian kernel filters this function, producing a smoothed noise function. Unlike the source noise, one may differentiate this function, and it may have a small positive or negative bias. However, it's most salient aspect is a loss of high frequency components to a degree established by the radius argument. This establishes feature size, which becomes a characteristic of the octave, and with the first octave exhibiting the largest features, having been filtered for all but the lowest frequencies present in the noise.

To Mix or Not To Mix, and How?

Next, the smooth noise function may be mixed, an occurrence dependent the mode. As noted above, Mode 2 does not apply a mixer at any octave. Modes 1 and 3 apply mixers only at the first octave. Modes 0, 4, and 5 apply mixers at all octaves.

Mode

Mix First Octave

Mix Remaining Octaves

Mixer

0

i → |i|

1

i → |i|

2

3

 √ 

i → i2

4

i → i2

5

i → i3

There are three types of mixers. Modes 0 and 1 subtract any bias that may be in the smoothed noise function so that its average value is zero. The command then takes the point-wise absolute value of the smoothed noise function which leaves non-negative values unchanged but wraps negative values to positive; they retain their magnitudes but their signs change. This produces local discontinuities at former zero-crossings, and these appear as cracks or creases in the final output. Modes 3 and 4 point-wise squares the smoothed noise function, which flips negative values but retains first derivative continuity at former zero crossings. Creases do not appear with this mixer. Finally, Mode 5 point-wise cubes the smoothed noise function, which tend to form isolated positive and negative spikes of large value in fields that are otherwise nearly zero, on average.

Aggregation With Prior Octaves

Excepting the first, all octaves blend their (possibly mixed) smoothed noise functions with the aggregated noise functions stemming from prior octaves. This is a two-step process:

  1. The aggregate is scaled by the decay multiplier.
  2. The smoothed noise function of the current octave is added to the scaled aggregate.

The process implements the so-called decay of later smoothed noise functions through a little indirection. The erstwhile decay factor scales the aggregate as it transitions from octave to octave. When the decay factor is greater than one, the aggregate grows in magnitude from octave to octave. However, the smoothed noise function produced at each octave generally remains at the same order of magnitude as the original Gaussian noise distribution: ±10; that means the smoothed noise functions become relatively smaller than the aggregate as octaves increase, applying correspondingly smaller perturbations.

Thus, for a decay factor of three, the contribution of the first octave will be raised by 3 to the power of the number of requested octaves. For twelve octaves, the component added by the smoothed noise function of the first octave will be magnified approximately 312 or 530,000 times compared to that of the smoothed noise function produced by the twelfth octave. In a practical sense, then, the latter smoothed noise functions have been decayed with respect to the earlier ones.

One is at perfect liberty to set a decay factor less than one; the results are of limited utility. In this case, the smoothed noise functions produced by later octaves dominate, as their sizes are on the same order of magnitude as the aggregate. However, the low pass filter applied to these late-stage smoothing functions have small radii kernels, and consequently the smoothed noise functions do not differ much quantitatively from Gaussian noise; such results may be obtained much more cheaply by invoking -noise directly.

Cleanup

Following the last blending, the turbulence command scales the aggregate to the range 0,255, suitable for paint programs with unsigned eight bit character pipelines. If there is a non-zero difference argument, the turbulence command scales the selected image by the difference argument and subtracts the turbulence from it, re-normalizing the blend.

Examples

We apply a figurative (maybe even a poetic) oscilloscope to the schematic in Figure 2, illustrating some of the more salient aspects of turbulence generation. These correspond to a single row from a 1024 × 1024 turbulence image as it emerges from the primordal soup. The arguments given to the turbulence command were radius: 128, octaves: 10, decay 2.25, difference 0, and mode 0.

The chart on the left graphs two curves near the beginning of the of the flowchart in Figure 2. The blue curve ("Base") is the smoothed noise function produced from noise exhibiting a Gaussian distribution centered on zero and ranging between -10 and 10. It emerges from the box labeled "Low Pass Filter 1st Octave" and because the mode has been set to O, it passes through the decision diamond from left to right and enters the box labeled "Mix 1st Octave." The large variance (radius of 128) has removed all but the lowest frequency components.

When running in Mode 0, the mixer applies the -abs (absolute value) command to its input, after subtracting any bias. This reflects the negative-valued regions of the input curve about the zero axis, making a crease at the old zero-crossing point. This reflection is analogous to "stirring" the curve (as in stirring a cup of coffee or a bucket of paint). This particular flavor of stirring is interesting because the crease introduces new high frequency components to a curve which has been stripped of them. These kinds of repetitive give-and-take processes are hallmarks of multi-scale noise generators. 

The orange curve is the output of the mixing block; it enters the repetitive loop part of the schematic at the box labeled "Radius ÷ 2N".

 Every passage around the loop finds the generation of a new smoothed noise function filtered by a low-pass filter that employs a convolution kernel one half the size from that used in the previous passage. That means the the smoothed noise functions acquire increasingly higher frequency components, In this intial pass, we see little of that, but will see more in the following panels. Since we are in Mode 0, the new smoothed noise function also gets reflected around the zero axis, making a new crop of creases. It is now ready to "perturb" the aggregation curve.

The orange curve is very nearly the same as the "Reflected" curve from the previous panel, but it has been scaled by the decay factor, 2.25, so it is now larger and also the "aggregation curve". In this first loop, it has only aggregated one curve and is about to aggregate a second. These data are the input for the "Aggregation" box in the Figure 2 schematic.

The dark blue curve is the result of blending the orange and blue curves and becomes the new aggregate for the second octave's traversal around the loop.

For sake of brevity, we let processes percolate for octaves 2, 3, and 4 and present another  snapshot entering the "Aggregation" block. The orange curve is the aggregate, having now absorbed three curves, and the pale blue curve is the smoothed and mixed noise curve produced in the current octave. It is not particularly smaller than smoothed noise functions of previous octaves; it is that the aggregator has grown bigger, so the degree in which the present smoothed noise function will perturb the aggregate is smaller.

The other interesting aspect of the smoothed noise function is that it is the "lumpiest" one yet. The convolution kernel has been halved, halved, and halved again, and so is not nearly the low-pass filter that it once was.

The dark blue curve is the output of the Aggregator block, and is about to commence octave five. We have now seen the essence of this noise generator, the successive layering of finer (higher frequency) detail at successively smaller scales.

Having guessed the plot of this story, we fast forward to the last paragraph to see if the Good Guy gets it in the end (gets what? the treasure? the meaning of Life? the full metal jacket bullet? Ah. We're digressing...)

There's nothing new here in this third snapshot at the front door of the Aggregation box. The smoothed noise function is no longer very smooth, nor is it very big in relation to the aggregate, which has become huge. The dark blue curve is hardly perturbed at all from the ultimate minus one version; probably ten octaves is about right. Twelve would not have been meaningfully different. 

It is worth noting that the soon-to-be-output aggregate largely bears the rise and fall of the first smoothed noise function, which mainly set the shape of the curve. The products of subsequent octaves applied fiver detail at smaller scales, and we're now at the point where the detail approaches single pixel scales.

 — 

Garry Osgood