Game Development Reference
In-Depth Information
“
bool
” vector contains the results of each compared component. For
example:
vectoru={1.0f, 0.0f, -3.0f, 1.0f};
vector v = {-4.0f, 0.0f, 1.0f, 1.0f};
vectorb=(u==v);//b=(false, true, false, true)
Finally, we conclude by discussing variable promotions with binary
operations:
For binary operations, if the left side and right side differ in dimen-
sion, the side with the smaller dimension is promoted (cast) to
have the same dimension as the side with the larger dimension. For
example, if
x
is of type
float
and
y
is of type
float3
,inthe
expression
(x+y)
the variable
x
is promoted to
float3
and the
expression evaluates to a value of type
float3
. The promotion is
done using the defined cast. In this case we are casting scalar-to-
vector; therefore, after
x
is promoted to
float3
,
x = (x, x,
x)
, as the scalar-to-vector cast defines. Note that the promotion is
not defined if the cast is not defined. For example, we can't pro-
mote
float2
to
float3
because there exists no such defined
cast.
For binary operations, if the left side and right side differ in type,
then the side with the lower type resolution is promoted (cast) to
have the same type as the side with the higher type resolution. For
example, if
x
is of type
int
and
y
is of type
half
, in the expres-
sion
(x+y)
the variable
x
is promoted to a
half
and the expres-
sion evaluates to a value of type
half
.
16.6
User-Defined Functions
Functions in HLSL have the following properties:
Functions use a familiar C++ syntax.
Parameters are always passed by value.
Recursion is not supported.
Functions are always inlined.
Furthermore, HLSL adds some extra keywords that can be used with
functions. For example, consider the following function written in
HLSL:
bool foo(in const bool b, // input bool
out int r1,
// output int
inout float r2)
// input/output float
{
Search WWH ::
Custom Search