RManNotes

previous | next | regular patterns: contents | rmannotes: top

Transforming Tiles

When it is necessary to create patterns at angles, particular scales, or positions, it is usually easier to transform the texture coordinates rather than the pattern itself. Texture coordinate transformations are easy, while generating patterns is usually more difficult.

Transforming texture coordinates has an "inverse" effect on the appearance of the pattern. For example, if you scale the texture coordinates by a factor of 2, the frequency of the pattern will double and the pattern will appear twice as small. Likewise, positive translations will move the pattern up and to the left (the opposite direction) and positive clockwise rotations will rotate the pattern counter-clockwise.

Rotating Tiles

RManNotes function

rotate2d(float x, y, angle, ox, oy, rx, ry)

      Rotates a 2D point (x, y) clockwise by a specified angle (in radians) about an origin (ox, oy) and stores the resulting point in (rx, ry).

An RManNotes function called rotate2d makes it easy to rotate 2D texture coordinates. Remember that this is a clockwise rotation, therefore when applied to texture coordinates, the pattern will be rotated counter clockwise.

To rotate the cross shader, we replace the lines

  ss = repeat(s, freq);
  tt = repeat(t, freq);

with

  rotate2d(s, t, radians(45), 0.5, 0.5, ss, tt);
  ss = repeat(ss, freq);
  tt = repeat(tt, freq);

to get


rotcross.sl

Shifting Rows or Columns of Tiles

Alternating rows (or columns) of tiles can be staggered by
  1. using repeat, whichtile, and odd and/or even to determine if the current tile is in an odd or even row; and then
  2. shifting or not shifting texture or coordinates appropriately.

For example, to shift even rows of a pattern by a 1/2 tile, you would add 0.5 to ss after it has been repeated. You still need to remember to mod ss with 1 so that it stays in the range 0 to 1.

  row = whichtile(t, freq);
  if (even(row))
    ss = mod(ss + 0.5, 1);


shiftedblocks.sl

Note: shiftedblocks.sl uses a function called intersection which is described in the section on generating simple shapes.

Polar Coordinates

Polar coordinates are useful for generating radially shaped patterns (flowers, stars, etc.). The convenience function topolar2d converts a 2-D point in Cartesian coordinates to polar coordinates.

RManNotes function

topolar2d(float x, y, r, theta)

      Transforms a 2-D point (x,y) in Cartesian coordinates to polar coordinates expressed in terms of r (distance from the origin) and theta (the angle expressed in radians). theta will be in the range [-PI, PI].

previous | next | regular patterns: contents | rmannotes: top

RManNotes is Copyright © 1995, 1996 Stephen F. May

Any comments or suggestions appreciated.

Steve May (smay@pixar.com)

Last Modified: 3/29/96