Game Development Reference
In-Depth Information
Data types
Cg/HLSL has six basic data types. Some of them are the same as in C, while others are es-
pecially added for GPU programming. These types are listed in the following table:
Data type
Description
This is a 32-bit floating point number (a high-precision floating point is generally 32 bits, just like the
float
type in regular pro-
gramming languages)
float
This is a 16-bit floating point number (a medium-precision floating point is generally 16 bits, with a range of -60,000 to +60,000
and 3.3 decimal digits of precision)
half
This is a 32-bit integer
int
This is a 12-bit fixed point number (a low-precision fixed point is generally 11 bits, with a range of -2.0 to +2.0 and 1/256th preci-
sion)
fixed
bool
This is a boolean variable (
FALSE
=
0
and
TRUE
=
1
)
sampler*
This represents a texture object (
sampler1D
,
sampler2D
,
sampler3D
,
samplerCUBE
, or
samplerRECT
)
Cg/HLSL also features vector and matrix data types that are based on the basic data types,
such as
float3
and
float4x4
. Such data types are quite common when dealing with
3D graphics programming. Cg/HLSL also has the
struct
and
array
data types, which
work in a way that is similar to their C equivalents.