Game Development Reference
In-Depth Information
Note
Remember that the vertex shader is one of the stages in the Direct3D graphics
pipeline, as is the pixel shader.
The last two lines of code in this method tell the graphics processing pipeline to use
our vertex shader and pixel shader. So why do we have shaders anyway? The reas-
on is because some stages in the Direct3D graphics pipeline are programmable.
Shaders are the programs we write for these stages, so a shader is essentially a
small program that tells Direct3D what to do during that stage in the pipeline. There
are more shader types besides vertex and pixel shaders too, but they are beyond the
scope of this topic. Shaders are a powerful tool that allow us to customize the graph-
ics processing pipeline, so we can do things that otherwise we might not be able to
do. You can have more than one shader of a given type and switch between them
at will too (we will actually do this in the second demo we make in this chapter), so
you're not stuck with the first shader you set. At this point, we are ready to initialize
our scene.
Initializing the scene
In 3D graphics, the term scene is used much as it is in the movies. However, in
this case, the term scene refers to the world, or 3D scene, that we are rendering.
To initialize our scene, we will create one more initialization method named InitS-
cene() . The code for this method looks as follows:
public void InitScene()
{
// Create the vertices of our triangle.
Vector3[] vertexData =
{
new Vector3(-0.5f, 0.5f, 0.5f),
new Vector3( 0.5f, 0.5f, 0.5f),
new Vector3( 0.0f, -0.5f, 0.5f),
};
Search WWH ::




Custom Search