Nature, however, does not work this way.While there are variations, for example, in theelevations of a mountain or the curves in a river, there is also a great deal of structure presentas well.One of the key elements to the variations we see in natural phenomena is that the magnitudeof random variations depends on the scale (or size) at which we perceive these phenomena.Consider, for example, the textures shown in Fig. 3. By varying the frequency of the noisewe can obtain significantly different textures.Fig. 3: Perlin noise used to generate a variety of displacement textures.The tendency to see repeating patterns arising at different scales is calledself similarityandit is fundamental to many phenomena in science and nature.Such structures are studiedin mathematics under the name offractals. Perlin noise can be viewed as a type of randomnoise that is self similar at different scales, and hence it is one way of modeling random fractalobjects.Noise Functions:Let us begin by considering how to take the output of a pseudo-random numbergenerator and convert it into a smooth (but random looking) function. To start, let us considera sequence of random numbers in the interval [0,1] produced by a random number generator(see Fig. 4(a)). LetY=hy0, . . . , ynidenote the sequence of random values, and let us plotthem at the uniformly places pointsX=h0, . . . , ni.Next, let us map these points to a continuous function, we could apply linear interpolationbetween pairs of points (also calledpiecewise linear interpolation.As we have seen earlierthis semester, in order to interpolate linearly between two valuesyiandyi+1, we define aparameterαthat varies between 0 and 1, the interpolated value islerp(yi, yi+1, α) = (1-α)yi+αyi+1.To make this work in a piecewise setting we need to setαto the fractional part of thex-valuethat lies betweeniandi+1. In particular, if we definexmod 1 =x-bxcto be the fractionalLecture 122Spring 2018
CMSC 425Dave Mount & Roger Eastman10(a)10(b)10(c)Random pointsPiecewise linear interpolationCosine interpolationFig. 4:(a) Random points, (b) connected by linear interpolation, and (c) connected by cosineinterpolation.part ofx, we can define the linear interpolation function to bef‘(x) = lerp(yi, yi+1, α),wherei=bxcandα=xmod 1.The result is the function shown in Fig. 4(b).While linear interpolation is easy to define, it will not be sufficient smooth for our purposes.There are a number of ways in which to define smoother interpolating functions.(This isa topic that is usually covered in computer graphics courses.)A quick-and-dirty way todefine such an interpolation is to replace the linear blending functions (1-α) andαin linearinterpolation with smoother functions that have similar properties.In particular, observethatαvaries from 0 to 1, the function 1-αvaries from 1 down to 0 whileαgoes the otherway, and for any value ofαthese two functions sum to 1 (see Fig. 5(a)). Observe that thefunctions (cos(πα)+1)/2 and (1-cos(πα))/2 behave in exactly this same way (see Fig. 5(b)).