Prev: Operator Modules Next: Color Function Modules
5. Function Modules
The modules in the "Functions" category 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.
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.0 | Blur = 0.05 | Blur = 0.2 |
Clip
This module clips its input to a fixed range:
y(x) = | xmin | for x < xmin |
| x | for xmin < x < xmax |
| xmax | for x > xmax |
Double-click the module to set the values for xmin and xmax.
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.
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 |
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) = xlog(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)/2 | if x<0.5 |
| 1-Bias(2-2*x, 1-G)/2 | if 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.
Random
This module provides one dimensional random noise: the output varies irregularly but smoothly
as a function of the input value.
The output is created by adding together several octaves of a smooth noise function. Each octave
has twice the frequency of the previous octave. You can specify the number of octaves to use,
and the amplitude of the first octave. The amplitude of each higher octave is obtained by
multiplying the amplitude of the preceding octave by the value of the noise input port
(which is typically between 0 and 1, although this is not strictly required). Because this
is an input port rather than a parameter, it does not need to be a constant. This is very
useful for creating patterns whose character varies over the surface of an object.
The function is scaled so that output values will typically be between 0 and 1. Depending
on the values of the parameters and the noise input, however, the output value may sometimes go outside this range.
Prev: Operator Modules Next: Color Function Modules