Game Development Reference
In-Depth Information
Pixel shaders really become powerful when they are used to add lighting and shad-
ing to objects. These effects can range from simple calculations (N dot L lighting cal-
culation), to advanced global illumination (light bounces around the scene to realist-
ically provide ambient lighting).
Compiling and loading
We now need to load these shaders into our program, compile them, and load them
onto the GPU. One important thing to note here is that you cannot compile shaders
once they have been submitted to the Windows Store, so you need to make sure
you precompile the shaders and load them in (from the file or from within the code)
as byte-code shaders when you want to submit to the store. During development you
are allowed to use the compiler within your application if you want; however, once
you are ready to submit you need to precompile the shaders.
There are a few ways to load in your code, and the Direct3D sample provides a help-
er method that reads all the data from a file. Once you have the data, though, you
need to use the Direct3D device to create the shader.
Note
If you give your shader the .hlsl file extension and add it to your project, Visual
Studio 2012 will compile it for you and output an object file that you can load dir-
ectly without worrying about a custom compile step.
To load in the shader you need to call the appropriate CreateXXShader method,
where XX is the type of shader. To create the vertex shader, you can use the follow-
ing method:
ID3D11VertexShader *shader;
m_d3dDevice->CreateVertexShader(
file->Data,
file->Length,
nullptr,
&shader
);
Search WWH ::




Custom Search