646 Game Development and Simulation with Unreal Technology
COSINE
This expression calculates and returns the cosine of its input value. Note that the input
value is always in radians (and not in d egrees). By connecting the output channel of
a Time expression to this expression, you will be able to create a waveform that
oscillates between -1.0 a nd +1 .0 over time .
Properties
Period: Specifies the period of the resulting waveform. Larger values result in
slower oscillations while smaller values resu lt in faster oscillations.
Example Usage: To create a pulsating material, connect the Time expression to
the input of a Cosine expression and plug the output channel of the cosine to the
Emissive Color cha nnel of the material node.
CROSS-PRODUCT
This expression takes two vectors as input and returns a vector that is equal to the
cross-product o f the two input vectors. Mathematically speaking, the cross-product
will create a vector that is perpendicular to the two input vectors and whose le ngth is
proportional to the Sine of the angle between the two input vecto rs.
Let X and Y be two vectors. Th e cross-product of these two vectors is calculated
according to the following equation:
X Y = |X| ·|Y| ·sin(
θ
) · n (A.5)
where
θ
is the angle between vectors X and Y, and n be the normal to the plane
composed of the two vectors.
Inputs
A: Ta kes in a 3-chan nel vector value as the first vector.
B: Takes in a 3-channel vector value as the second vector.
Example Usage: Use the cross-product of two vectors to find the n ormal to th eir
plane. In other words, to find a vector that is perpendicular to both.
DIVIDE
This exp ression takes its two input valu es (A and B) and returns the division o f
the first value by the second value. The division operation is performed on a per-
channel basis. In other words, if you add to Constant3Ve ctors, the result will be a
Constant3Ve ctor in which the R, G, a nd B components are the division of the two
input R, G, and B channels, respectively.
Mathematically speaking, Let X and Y be two N-channel vectors. Then the Add
expression of these two values will be:
DIVIDE(X,Y) =
X
Y
=
x
1
y
1
,
x
2
y
2
,··· ,
x
N
y
N
(A.6)
Material Expressions in Unreal Engine 4 647
Properties
Const A: Takes the value to be divided. It is only used if the A input channel is
not connected.
Const B: Takes the value to divide by. It is only used if the B input channel is not
connected.
Inputs
A: Ta kes the valu e to be divided, the dividend.
B: Takes the value to divide by, the divisor.
Example Usa ge: You can connect the output channels of one Texture Sample
expressions to the A and a Constant value to the B input of a Divide expression
to make the textur e look dimmer. Note: The con sta nt valu e must be greater than
1.0 to make the texture dimmer. If the constant value is less than 1.0, the texture
will look brighter.
DOT PRODUCT
This expression takes two vecto rs as input and returns a scalar value that is equal to
the dot product of the two input vectors. Mathematically speaking, the dot product
will create a scalar that is propo rtional Cosine of the angle between the two input
vectors.
Let X and Y be two vectors. The dot product of these two vectors is calc ulated
according to the following equation:
X Y = |X| · |Y| · cos(
θ
) (A.7)
where
θ
is the angle between vecto rs X and Y.
Inputs
A: Ta kes in a value or vector any length as the first vector.
B: Takes in a value or vector any length as the second vecto r.
Example Usa ge: Use the cross-product of two vectors to find the angle between
them. If the vector s are parallel, the value will be close to +1 or -1. If the vectors
are perpendicular, the value will be 0. Other w ise the value will range between -1
and +1.
FLOOR
This operation, as the name suggests, takes in one input and returns its floor value -
i.e., rounds the input down to the previous integer number. If the input to this expres-
sion is a vector, then the expression outputs the floor value on a per-channel basis.
Example: The floor of 3.4 is 3, and the floor of 3.9 is also 3.
Example Usa ge: You can mu ltiply a vector or constant by some co nstant K, then
take the ce iling of the result and divide it by the same c onstant K to create
bands with varying colors. Similar to what we did for the Ceiling expression on
page 186.
648 Game Development and Simulation with Unreal Technology
FMOD
This ope ration takes in two inputs an d returns the floating point reminder of their
division. If th e inpu t to this expression is a vector, then the expression outputs the
floor value on a per-channel basis.
Example: The FMod of 3.4 by 2.3 is 1.1.
FRAC
This operation, as the name sugge sts, takes in one input and retu rns its decimal part
- i.e., removes the integer par t of the input value. If the input to this expression is a
vector, then the expression outputs the floor value on a per-channel basis.
Example: The ceiling of 3.4 is .4, and the ceiling of (3.9, 1.27) is (0.9, 0.27).
IF
This expression compares two scalar floating point input values, and three condition
values. Then it passes through one o f the three values from its input condition chan-
nels based on which con dition is true on the two input scalar values.
Inputs
A: Ta kes in a scalar floating p oint value as the first input.
B: Takes in a scalar floating point value a s the second input.
A<B: Takes in a value to output if the A is less than B.
A=B: Takes in a value to output if the A is equal to B.
A>B: Takes in a value to output if the A is greater than B.
Example Usage: You can connect a Texture Samp le to th e A input and a scalar
value T h (as the threshold) to the B chann el, then connect three different Con-
stant3Vecto rs to the A<B, A=B, an d A>B to c reate a tri-color m ap based on the
input texture and the threshold value (see Figure 4.51).
LINEAR INTERPOLATE (LERP)
This expression blends between two input value(s) based on a third input value used
as a mask. This can be thoug ht of as a mask to define transitions between two textures,
like a layer mask in Photo shop.
The intensity of the mask Alpha channel determ ines the ratio of color to take from the
two input values. If Alpha is 0 .0/white, the first input is used. If Alpha is 1.0/black,
the secon d input is used. If Alpha is grey (som ewhere between 0.0 a nd 1.0), the
output is a blend be tween the two inputs.
Mathematically speaking, let A be the first input, B be the second input, and 0
α
1 be th e mask input. The output O will be calculated according to the following
equation :
O = (1
α
) × A +
α
× B (A.8)
Material Expressions in Unreal Engine 4 649
Keep in mind that the blend happens per channel. So, if Alpha is an RGB color,
Alpha’s red channe l value d efines the blend between A a nd B’s re d channels inde-
pendently of Alpha’s green channel, which defines the blend between A and B’s
green channels.
Properties
Const A: The value mapped to black (0.0). It is only used if the A input is u ncon-
nected.
Const B: The value mapped to white (1.0). I t is o nly used if the A input is uncon-
nected.
Const Alpha : Takes in the value to use as the mask alpha. It is only used if the
Alpha input is unconnected.
Inputs
A: Ta kes in the value(s) mapped to b la ck (0. 0).
B: Takes in the value(s) mapped to white (1.0).
Alpha: Takes in the value to use as the mask alpha .
Example Usa ge: You can connect two Constant3Vector RGB colors to the inputs A
and B and the alpha channel of a Texture Sample to the Alpha input channel o f
the Lerp expression to Interpolate the values between two colors. Connecting the
output channel of the Lerp to the Base color channel of a material node will have
the result shown in color (see Figure 4.52).
MAX
This expression takes in two inpu ts and returns the maximum of the two as output.
Properties
Const A: The first value taken as input. It is only u sed if the A in put is uncon-
nected.
Const B: The second value taken as input. It is only used if the A input is uncon-
nected.
Inputs
A: The first value taken as input.
B: The second value taken as input.
MIN
This expression takes in two inpu ts and returns the minimum of the two as output.
Properties
Const A: The first value taken as input. It is only u sed if the A in put is uncon-
nected.
Const B: The second value taken as input. It is only used if the A input is uncon-
nected.
Inputs
A: The first value taken as input.
B: The second value taken as input.
650 Game Development and Simulation with Unreal Technology
MULTIPLY
This expression takes its two input value s (A and B) and retur ns the multiplication
of the first value by the second value. The multiply operation is performed on a per-
channel basis. In other words, if you add to Constant3Ve ctors, the result will be a
Constant3Ve ctor in wh ic h the R, G, and B components are the multiplication of the
two input R, G, and B channels, respectively.
Mathematically speaking, let X and Y be two N-channel vectors. Then the Multiply
expression of these two values will be:
MULTIPLY(X,Y) = [x
1
× y
1
,x
2
× y
2
,··· ,x
N
× y
N
] (A.9)
Properties
Const A: Takes the value to be multiplied. It is only used if the A input channel
is not connected .
Const B: Takes th e value to multiply to. It is only used if the B input channel is
not connected.
Inputs
A: Ta kes the first value to multiply, the multiplicand.
B: Takes the second value to multiply, the multiplier.
Example Usage: You can connect the output channels of two Texture S ample
expressions to the A and B inputs of a Multiply expression to make the texture
affect eac h other. Note: If the input texture RGB values are less than one, the
resulting texture will look much dimm er. You may need to multiply the result by a
constant value greater than 1 to compensate.
NORMALIZE
This expression performs a very important operation on vectors called Normalization.
The Normalize expression takes in a vector as input and normalize s it and returns the
normalized vector. Mathematically speaking, the normalization operation will make
the length of the vector to be equal to unit length (i.e., 1).
Unreal Engine uses L-2 lengths– the square root of the sum of squares of each ele-
ment in the vecto r.
Let X = [x
1
,x
2
,··· ,x
N
] be an N-dimensional vector, the L-2 norm (o r length) of X is
calculated accord ing to the following equations:
|X| =
s
N
i=1
x
2
i
(A.10)
Then the normalized vector
ˆ
X is calculated by dividing X by its L -2 norm:
ˆ
X =
X
|X|
(A.11)
Notice that after normalization the length (L-2 norm) of the normalized vector will
be equal to 1.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.241.250