Game Development Reference
In-Depth Information
Common methods to create shaders
Method
Description
dot(a, b)
This gives the dot product of two vectors.
cross(A, B)
This gives the cross product of vectors
A
and
B
.
A
and
B
must be three-component vectors.
This gives the maximum of
a
and
b
.
max(a, b)
This gives the minimum of
a
and
b
.
min(a, b)
This gets the largest integer not greater than
x
.
floor(x)
This gets the closest integer to
x
.
round(x)
This gets the smallest integer not less than
x
.
ceil(x)
This computes x raised to the power
y
.
pow(x, y)
This returns a vector of length
1
that points in the same direction as vector
v
.
normalize(v)
This clamps
x
to the
[0, 1]
range.
saturate(x)
tex2D(sampler,
x)
This is a 2D texture lookup (the sampled data at the location indicated by the texture coordinate set in the sampler ob-
ject).
The methods mentioned in the preceding table are the common methods that you can use to
create your shader with Cg/HLSL. There are a lot of methods that you can also use in Cg/
HLSL.
For more details, you can visit the following site: