Art of Illusion



To Documentation Index
Prev: Value Modules Next: Color Function Modules

4. Function Modules

The modules in the "Functions" submenu have one or more numeric input ports, and a single numeric output port. The output value is calculated by applying a function to the input values.

Expression

This module allows you to enter an arbitrary mathematical expression. It calculates its output as a function of its three inputs. It also may depend directly on the current position or time for which the procedure is being evaluated. Double-click the module to bring up a window in which you can edit the expression.

Your expression may include any of the following elements:

  • Numbers
  • ( ) for grouping
  • Variables
    • x, y, and z: the coordinates of the point for which the procedure is being evaluated
    • t: the time for which the procedure is being evaluated.
    • input1, input2, and input3: the values of the three inputs to the module
    • pi: 3.141592...
    • e: 2.718281...
  • Operators
    • +: addition
    • -: subtraction
    • *: multiplication
    • /: division
    • ^: exponentiation
    • %: modulus
  • Functions
    • sin(a): sine of a
    • cos(a): cosine of a
    • sqrt(a): square root of a
    • abs(a): absolute value of a
    • log(a): natural logarithm of a
    • exp(a): e to the a power (same as e^a)
    • min(a, b): minimum of a and b
    • max(a, b): maximum of a and b
    • pow(a, b): a to the b power (same as a^b)
    • angle(a, b): the angle formed by a right triangle with sides a and b
    • bias(a, b): the Bias function with a bias of b
    • gain(a, b): the Gain function with a gain of b
See below for details of the Bias and Gain functions. Also, some functions have slightly non-standard behavior as described below. For example, if x is negative, then sqrt(x) is evaluated as -sqrt(-x) (rather than attempting to return an imaginary value).

Custom

This module represents a user defined function y(x) which maps input values to output values. Double-click the module to bring up a window in which you can edit the function. You define it by specifying the output values y(x) for a set of input values of x, where x is between 0 and 1. The behavior outside the range [0, 1] is determined by the "Function is Periodic" checkbox. If you select this option, the function will repeat so that it has the same value at 0.2, 1.2, 1000.2, -0.8, etc. If you do not choose this option, the function will be constant outside this range so that f(x) = f(0) for any x<0, and f(x) = f(1) for any x>1.

If you select the "Smooth Curve" option, a smoothly varying function will be used which interpolates the values you specify. If you do not select this option, a piecewise linear function will be used.

Scale/Shift

This module represents a linear mapping of input to output values:

y(x) = A*x + B

where you can set the values of the two constants A and B.

Add

This module outputs the sum of its two inputs.

Subtract

This module outputs its first input minus its second input.

Multiply

This module outputs the product of its two inputs.

Divide

This module outputs its first input divided by its second input.

Abs

This module outputs the absolute value of its input.

Blur

This module outputs a "smoothed" or "blurred" version of its input. That is, it averages the input value over a region of a particular width, and outputs that average. This module has two input ports: the first is the signal to blur, and the second gives the size of the region over which to average it. Because this is an input port rather than a fixed parameter, the amount of blurring can be different in different parts of the texture or material.

Blur = 0.0Blur = 0.05Blur = 0.2

Clip

This module clips its input to a fixed range:

y(x) = Xminfor x<Xmin
xfor Xmin<x<Xmax
Xmaxfor x>Xmax

Double-click the module to set the values for Xmin and Xmax.

Greater Than

This module has two input ports. Its output is equal to 1 if the first input value is greater than the second one, and zero otherwise.

You might wonder why there is a "greater than" module, but not a "less than" module. Hint: Try reversing the inputs.

Min

This module outputs the minimum of its two inputs.

Max

This module outputs the maximum of its two inputs.

Interpolate

This module has three input ports. It uses the fraction input to interpolate between the value 1 and value 2 inputs. If fraction<0, the output equals value 1. If fraction>1, the output equals value 2. If fraction is between 0 and 1, the output is a weighted average of value 1 and value 2.

Mod

This module calculates its output value according to:

y(x) = x Mod M

where the input value x and modulus M correspond to the two input ports.

Sine

This module outputs the sine of its input.

Cosine

This module outputs the cosine of its input.

Square Root

This module outputs the square root of its input. More accurately, its output is given by:

y(x) = sqrt(x)if x>0
-sqrt(-x)if x<0

Exponential

This module outputs the exponential of its input.

Log

This module outputs the natural logarithm of its input. More accurately, its output is given by:

y(x) = log(x)if x>0
-log(-x)if x<0

Power

This module outputs its first input raised to the power of its second input. More accurately, its output is given by:

y(x) = x^pif x>0
-(x^(-p))if x<0

where x and p are the two inputs.

Bias

This module calculates Ken Perlin's Bias function. Given an input value between 0 and 1, it calculates an output value which is also between 0 and 1 according to:

y(x) = x^(log(B)/log(0.5))

where the input value x and bias B correspond to the two input ports. If B=0.5, then y(x)=x. Values of B less than 0.5 push the output toward smaller values, while values of B greater than 0.5 push the output toward larger values.

Gain

This module calculates Ken Perlin's Gain function. Given an input value between 0 and 1, it calculates an output value which is also between 0 and 1 according to:

y(x) = Bias(2*x, 1-G)/2if x<0.5
1-Bias(2-2*x, 1-G)/2if x>0.5

where the input value x and gain G correspond to the two input ports, and Bias(x, B) is the Bias function described above. If G=0.5, then y(x)=x. Values of G less than 0.5 smooth the input by pushing the output toward 0.5, while values of G greater than 0.5 sharpen the input by pushing the output toward 0 or 1.

Prev: Value Modules Next: Color Function Modules