Game Development Reference
In-Depth Information
been drawn on that pixel so far while rendering the current frame. This is how Direc-
t3D knows whether an object is in front of or behind another object. When the pixel
shader goes to draw a pixel, it checks the depth value for that pixel in the depth sten-
cil texture. If that pixel's depth value is closer than the depth of the pixel it is trying to
draw, that pixel is discarded since it belongs to an object behind another closer one
that we already drew on this pixel.
The second variable holds our DepthStencilView object, which accesses the
depth stencil texture when Direct3D is doing depth testing on a pixel. The next two
variables have to do with sampling. The first one will hold our texture that we will put
on the cube. The second variable holds the sampler state that we will use with our
texture.
Sampling is the act of reading image data from our texture so that we can use it to
render pixels in the pixel shader. Basically, the pixel shader gets the pixel color from
the texture based on the texture coordinates of the vertices that make up the face it
is drawing.
Lastly, we have one more small set of member variables to look at:
Vector3 m_CameraPosition = new Vector3(0, 2,
-5);
float m_CubeRotation = 0.005f;
float m_MoveSpeed = 0.01f;
GraphicsMode m_GraphicsMode =
GraphicsMode.PerVertexColoring;
The first variable here keeps track of the position of our camera, of course. The
second variable tracks the current rotation amount (on the y axis) for our cube. The
m_MoveSpeed variable specifies how fast the camera moves when you press one of
the movement keys. And the last variable specifies how we want to render our cube.
I wanted to make a demo that we could really experiment with, so I added this fea-
ture. So how does it work? If you look at the code in the InitShaders() method in
the downloadable code for this demo, you can see that we have changed the code
Search WWH ::




Custom Search