Game Development Reference
In-Depth Information
if( b )
// test input value
{
r1 = 5;
// output a value through r1
}
else
{
r1 = 1;
// output a value through r1
}
// since r2 is inout we can use it as an input
// value and also output a value through it
r2=r2*r2*r2;
return true;
}
The function is almost identical to a C++ function except for the
in
,
out
, and
inout
keywords.
in
—Specifies that the
argument
(particular variable that we pass
into a parameter) should be copied to the parameter before the
function begins. It is not necessary to explicitly specify a parameter
as
in
because a parameter is
in
by default. For example, the fol-
lowing are equivalent:
float square(in float x)
{
returnx*x;
}
Without explicitly specifying
in
:
float square(float x)
{
returnx*x;
}
out
—Specifies that the parameter should be copied to the argu-
ment when the function returns. This is useful for returning values
through parameters. The
out
keyword is necessary because HLSL
doesn't allow us to pass by reference or pass a pointer. We note
that if a parameter is marked as
out
, the argument is not copied to
the parameter before the function begins. In other words, an
out
parameter can only be used to output data—it can't be used for
input.
void square(in float x, out float y)
{
y=x*x;
}
Here we input the number to be squared through
x
and return the
square of
x
through the parameter
y
.
Search WWH ::
Custom Search