Previous:Omega Main Index Next:Bitmap Modifiers

#### Warps

The `warp` statement is a pattern modifier that is similar to turbulence. Turbulence works by taking the pattern evaluation point and pushing it about in a series of random steps. However warps push the point in very well-defined, non-random, geometric ways. The `warp` statement also overcomes some limitations of traditional turbulence and transformations by giving the user more control over the order in which turbulence, transformation and warp modifiers are applied to the pattern.

Currently there are three types of warps but the syntax was designed to allow future expansion. The first two, the `repeat` warp and the `black_hole` warp are new features for POV-Ray that modify the pattern in geometric ways. The other warp provides an alternative way to specify turbulence.

The syntax for using a `warp` statement is:

WARP:
`
  warp {
` WARP_ITEM `}`
WARP_ITEM:
`
  repeat
` <Directiont> [REPEAT_ITEMS...] | `
  black_hole
` <Location>`,` Radius [BLACK_HOLE_ITEMS...] | `
  turbulence
` <Amount> [TURB_ITEMS...]
REPEAT_ITEMS:
`
  offset
` <Amount> | `flip` <Axis>
BLACK_HOLE_ITEMS:
`
  strength
` Strength | `falloff` Amount | `inverse` | `type` Type | `
  repeat
` <Repeat> | `turbulence` <Amount>
TURB_ITEMS:
`
  octaves
` Count | `omega` Amount | `lambda` Amount

You may have as many separate warp statements as you like in each pattern. The placement of warp statements relative to other modifiers such as `color_map` or `turbulence` is not important. However placement of warp statements relative to each other and to transformations is significant. Multiple warps and transformations are evaluated in the order in which you specify them. For example if you translate, then warp or warp, then translate, the results can be different.

##### Black Hole Warp

A `black_hole` warp is so named because of its similarity to real black holes. Just like the real thing, you cannot actually see a black hole. The only way to detect its presence is by the effect it has on things that surround it.

Take, for example, a wood grain. Using POV-Ray's normal turbulence and other texture modifier functions, you can get a nice, random appearance to the grain. But in its randomness it is regular - it is regularly random! Adding a black hole allows you to create a localized disturbance in a wood grain in either one or multiple locations. The black hole can have the effect of either sucking the surrounding texture into itself (like the real thing) or pushing it away. In the latter case, applied to a wood grain, it would look to the viewer as if there were a knothole in the wood. In this text we use a wood grain regularly as an example, because it is ideally suitable to explaining black holes. However, black holes may in fact be used with any texture or pattern. The effect that the black hole has on the texture can be specified. By default, it sucks with the strength calculated exponentially (inverse-square). You can change this if you like.

Black holes may be used anywhere a warp is permitted. The syntax is:

BLACK_HOLE_WARP:
`
  warp {black_hole
` <Location>`,` Radius [BLACK_HOLE_ITEMS...] `}`
BLACK_HOLE_ITEMS:
`
  strength
` Strength | `falloff` Amount | `inverse` | `type` Type | `
  repeat
` <Repeat> | `turbulence` <Amount>

The minimal requirement is the `black_hole` keyword followed by a vector <Location> followed by a comma and a float Radius. Black holes effect all points within the spherical region around the location and within the radius. This is optionally followed by any number of other keywords which control how the texture is warped.

The `falloff` keyword may be used with a float value to specify the power by which the effect of the black hole falls off. The default is two. The force of the black hole at any given point, before applying the `strength` modifier, is as follows.

First, convert the distance from the point to the center to a proportion (0 to 1) that the point is from the edge of the black hole. A point on the perimeter of the black hole will be 0.0; a point at the center will be 1.0; a point exactly halfway will be 0.5, and so forth. Mentally you can consider this to be a closeness factor. A closeness of 1.0 is as close as you can get to the center (i.e. at the center), a closeness of 0.0 is as far away as you can get from the center and still be inside the black hole and a closeness of 0.5 means the point is exactly halfway between the two.

Call this value c. Raise c to the power specified in `falloff`. By default Falloff is 2, so this is c2 or c squared. The resulting value is the force of the black hole at that exact location and is used, after applying the `strength` scaling factor as described below, to determine how much the point is perturbed in space. For example, if c is 0.5 the force is 0.52 or 0.25. If c is 0.25 the force is 0.125. But if c is exactly 1.0 the force is 1.0. Recall that as c gets smaller the point is farther from the center of the black hole. Using the default power of 2, you can see that as c reduces, the force reduces exponentially in an inverse-square relationship. Put in plain English, it means that the force is much stronger (by a power of two) towards the center than it is at the outside.

By increasing `falloff`, you can increase the magnitude of the falloff. A large value will mean points towards the perimeter will hardly be affected at all and points towards the center will be affected strongly. A value of 1.0 for `falloff` will mean that the effect is linear. A point that is exactly halfway to the center of the black hole will be affected by a force of exactly 0.5. A value of `falloff` of less than one but greater than zero means that as you get closer to the outside, the force increases rather than decreases. This can have some uses but there is a side effect. Recall that the effect of a black hole ceases outside its perimeter. This means that points just within the perimeter will be affected strongly and those just outside not at all. This would lead to a visible border, shaped as a sphere. A value for `falloff` of 0 would mean that the force would be 1.0 for all points within the black hole, since any number larger 0 raised to the power of 0 is 1.0.

The `strength` keyword may be specified with a float value to give you a bit more control over how much a point is perturbed by the black hole. Basically, the force of the black hole (as determined above) is multiplied by the value of `strength`, which defaults to 1.0. If you set strength to 0.5, for example, all points within the black hole will be moved by only half as much as they would have been. If you set it to 2.0 they will be moved twice as much.

There is a rider to the latter example, though - the movement is clipped to a maximum of the original distance from the center. That is to say, a point that is 0.75 units from the center may only be moved by a maximum of 0.75 units either towards the center or away from it, regardless of the value of `strength`. The result of this clipping is that you will have an exclusion area near the center of the black hole where all points whose final force value exceeded or equaled 1.0 were moved by a fixed amount.

If the `inverted` keyword is specified then points pushed away from the center instead of being pulled in.

The `repeat` keyword followed by a vector, allows you to simulate the effect of many black holes without having to explicitly declare them. Repeat is a vector that tells POV-Ray to use this black hole at multiple locations. Using `repeat` logically divides your scene up into cubes, the first being located at <0,0,0> and going to <Repeat>. Suppose your repeat vector was <1,5,2>. The first cube would be from <0,0,0> to < 1,5,2>. This cube repeats, so there would be one at < -1,-5,-2>, <1,5,2>, <2,10,4> and so forth in all directions, ad infinitum.

When you use `repeat`, the center of the black hole does not specify an absolute location in your scene but an offset into each block. It is only possible to use positive offsets. Negative values will produce undefined results.

Suppose your center was <0.5,1,0.25> and the repeat vector is <2,2,2>. This gives us a block at < 0,0,0> and <2,2,2>, etc. The centers of the black hole's for these blocks would be <0,0,0> + < 0.5,1.0,0.25>, i. e. <0.5,1.0,0.25>, and < 2,2,2> + <0.5,1.0,0.25>, i. e. < 2,5,3.0,2.25>.

Due to the way repeats are calculated internally, there is a restriction on the values you specify for the repeat vector. Basically, each black hole must be totally enclosed within each block (or cube), with no part crossing into a neighboring one. This means that, for each of the x, y and z dimensions, the offset of the center may not be less than the radius, and the repeat value for that dimension must be >=the center plus the radius since any other values would allow the black hole to cross a boundary. Put another way, for each of x, y and z

Radius <= Offset or Center <= Repeat - Radius.

If the repeat vector in any dimension is too small to fit this criteria, it will be increased and a warning message issued. If the center is less than the radius it will also be moved but no message will be issued.

Note that none of the above should be read to mean that you can't overlap black holes. You most certainly can and in fact this can produce some most useful effects. The restriction only applies to elements of the `same` black hole which is repeating. You can declare a second black hole that also repeats and its elements can quite happily overlap the first and causing the appropriate interactions. It is legal for the repeat value for any dimension to be 0, meaning that POV-Ray will not repeat the black hole in that direction.

The `turbulence` can only be used in a black hole with `repeat`. It allows an element of randomness to be inserted into the way the black holes repeat, to cause a more natural look. A good example would be an array of knotholes in wood - it would look rather artificial if each knothole were an exact distance from the previous.

The `turbulence` vector is a measurement that is added to each individual back hole in an array, after each axis of the vector is multiplied by a different random amount ranging from 0 to 1. The resulting actual position of the black hole's center for that particular repeat element is random (but consistent, so renders will be repeatable) and somewhere within the above co-ordinates. There is a rider on the use of turbulence, which basically is the same as that of the repeat vector. You can't specify a value which would cause a black hole to potentially cross outside of its particular block.

In summary: For each of x, y and z the offset of the center must be >=radius and the value of the repeat must be >= center + radius + turbulence. The exception being that repeat may be 0 for any dimension, which means do not repeat in that direction.

Some examples are given by

      warp

      {

        black_hole <0, 0, 0>, 0.5

      }

      warp

      {

        black_hole <0.15, 0.125, 0>, 0.5

        falloff 7

        strength 1.0

        repeat <1.25, 1.25, 0>

        turbulence <0.25, 0.25, 0>

        inverse

      }

      warp

      {

        black_hole <0, 0, 0>, 1.0

        falloff 2

        strength 2

        inverse

      }

##### Repeat Warp

The `repeat` warp causes a section of the pattern to be repeated over and over. It takes a slice out of the pattern and makes multiple copies of it side-by-side. The warp has many uses but was originally designed to make it easy to model wood veneer textures. Veneer is made by taking very thin slices from a log and placing them side-by-side on some other backing material. You see side-by-side nearly identical ring patterns but each will be a slice perhaps 1/32th of an inch deeper.

The syntax for a repeat warp is

REPEAT_WARP:
`
  warp {
` `repeat` <Directiont> [REPEAT_ITEMS...] `}`
REPEAT_ITEMS:
`
  offset
` <Amount> | `flip` <Axis>

The `repeat` vector specifies the direction in which the pattern repeats and the width of the repeated area. This vector must lie entirely along an axis. In other words, two of its three components must be 0. For example

      pigment {

        wood

        warp {repeat 2*x}

      }

which means that from x=0 to x=2 you get whatever the pattern usually is. But from x=2 to x=4 you get the same thing exactly shifted two units over in the x-direction. To evaluate it you simply take the x-coordinate modulo 2. Unfortunately you get exact duplicates which isn't very realistic. The optional `offset` vector tells how much to translate the pattern each time it repeats. For example

      pigment {

        wood

        warp {repeat x*2  offset z*0.05}

      }

means that we slice the first copy from x=0 to x=2 at z=0 but at x=2 to x=4 we offset to z=0.05. In the 4 to 6 interval we slice at z=0.10. At the n-th copy we slice at 0.05 n z. Thus each copy is slightly different. There are no restrictions on the offset vector.

Finally the `flip` vector causes the pattern to be flipped or mirrored every other copy of the pattern. The first copy of the pattern in the positive direction from the axis is not flipped. The next farther is, the next is not, etc. The flip vector is a three component x, y, z vector but each component is treated as a boolean value that tells if you should or should not flip along a given axis. For example

      pigment {

        wood

        warp {repeat 2*x  flip <1,1,0>}

      }

means that every other copy of the pattern will be mirrored about the x- and y- axis but not the z-axis. A non-zero value means flip and zero means do not flip about that axis. The magnitude of the values in the flip vector doesn't matter.

##### Turbulence Warp

The POV-Ray language contains an ambiguity and limitation on the way you specify `turbulence` and transformations such as `translate`, `rotate`, `scale`, `matrix`, and `transform` transforms. Usually the turbulence is done first. Then all translate, rotate, scale, matrix, and transform operations are always done after turbulence regardless of the order in which you specify them. For example this

     pigment {

       wood

       scale .5

       turbulence .2

     }

works exactly the same as

     pigment {

       wood

       turbulence .2

       scale .5

     }

The turbulence is always first. A better example of this limitation is with uneven turbulence and rotations.

      pigment {

        wood

        turbulence 0.5*y

        rotate z*60

      }

      // as compared to

      pigment {

       wood

       rotate z*60

       turbulence 0.5*y

      }

The results will be the same either way even though you'd think it should look different.

We cannot change this basic behavior in POV-Ray now because lots of scenes would potentially render differently if suddenly the order transformation vs. turbulence suddenly mattered when in the past, it didn't.

However, by specifying our turbulence inside warp statement you tell POV-Ray that the order in which turbulence, transformations and other warps are applied is significant. Here's an example of a turbulence warp.

      warp { turbulence <0,1,1> octaves 3 lambda 1.5 omega 0.3 }

The significance is that this

     pigment {

       wood

       translate <1,2,3> rotate x*45 scale 2

       warp { turbulence <0,1,1> octaves 3 lambda 1.5 omega 0.3 }

     }

produces different results than this...

     pigment {

       wood

       warp { turbulence <0,1,1> octaves 3 lambda 1.5 omega 0.3 }

       translate <1,2,3> rotate x*45 scale 2

     }

You may specify turbulence without using a warp statement. However you cannot control the order in which they are evaluated unless you put them in a warp.

The evaluation rules are as follows:

1) First any turbulence not inside a warp statement is applied regardless of the order in which it appears relative to warps or transformations.

2) Next each warp statement, translate, rotate, scale or matrix one-by-one, is applied in the order the user specifies. If you want turbulence done in a specific order, you simply specify it inside a warp in the proper place.

Previous:Omega Main Index Next:Bitmap Modifiers