Game Development Reference
In-Depth Information
Then the function will act per component:
x y z .
The following examples show how some of these intrinsic functions
might be called:
float x = sin(1.0f);
v
cos
( ,
cos
( ,
cos
()
// sine of 1.0f radian.
float y = sqrt(4.0f);
// square root of 4.
vector u = {1.0f, 2.0f, -3.0f, 0.0f};
vector v = {3.0f, -1.0f, 0.0f, 2.0f};
float s = dot(u, v);
// compute dot product of u and v.
float3 i = {1.0f, 0.0f, 0.0f};
float3 j = {0.0f, 1.0f, 0.0f};
float3 k = cross(i, j);
// compute cross product of i and j.
matrix<float, 2, 2> M = {1.0f, 2.0f, 3.0f, 4.0f};
matrix<float, 2, 2> T = transpose(M); // compute transpose
16.8 Summary
We write HLSL programs in ASCII text files and compile them in
our applications using the D3DXCompileShaderFromFile
function.
The ID3DXConstantTable interface allows us to set variables in
the shader program from our application. This communication is
necessary because variables used by the shader can change on a
frame-to-frame basis. For example, if the view matrix changes in
the application, we need to update the shader's view matrix vari-
able with the new view matrix. We can do this update with the
ID3DXConstantTable .
For each shader, we must define an input and output structure that
describes the format of the data that the shader inputs and outputs,
respectively.
Every shader has an entry point function that takes an input struc-
ture parameter that is used to pass input data into the shader. In
addition, every shader returns an output structure instance that is
used to output data from the shader.
Search WWH ::




Custom Search