Monday, May 9, 2011

Environmental Reflections

Shiny objects in your game should be able to reflect the environment around them. Don't think that you can use a mirror technique everywhere, the reflections on a car will require a high number of directions to reflect so it will become almost impossible to compute them. We can use a cube map to simulate the reflections of the environment around the object. Cube mapping helps us because we don't need to actually reflect the items, we just have to do a texture look-up and that's it.

Wednesday, May 4, 2011

Loading a model with a custom effect

XNA allows us to use complex 3D models very easily, we just use the content pipeline and load a model into the game just like a texture. It will have everything it needs, vertex buffers, index buffers, bones, effects, textures. All we will have to do is set our effect parameters (for each effect in the mesh) and draw it. But by default the Model class uses one of the 5 build-in effects and as  I love shaders, I want to make it run with one of my own.

Tuesday, May 3, 2011

Creating a Sky Box

If your game is going to have a part that you play outside you will also need a sky. One of the most simple ways to get this is by simply using a cube map to create a sky box. What you will do is create a cube map that has all 6 faces mapped to a cube surrounding the player. Simple huh? Well it is and you should get results like this one:

Screenshot from the finished tutorial

Monday, May 2, 2011

Cube Mapping

Environmental reflections can be very expensive to compute, luckily we can use a cube map accomplish this.  Cube maps are textures that help us map the environment on a 3D object like so:

Environmental reflections on a skull

Sunday, May 1, 2011

Using the stencil buffer, rendering a stencil mirror

As we've seen the stencil buffer helps us to stop some pixels from ever being drawn to the screen, also the rasterizer is configurable in such a way that we can tell it how to draw geometry. In this short tutorial you will see how to combine these 2 to get a mirror effect.

How the rasterization process works, the RasterizerState object

You probably noticed that when we draw something we use polygons (triangles) but on screen we have pixels. The process of converting from triangles to pixels on the screen. We can play with this process by using a few settings exposed to us by the RasterizerObject.

How depth and stencil testing work, the DepthStencilState object

You probably have noticed that when more than one object is drawn in the same place on the GPU the closer object is the one we will see on screen. That makes sense right? You can't see objects that are behind other objects (I'm talking about opaque objects).  This is the result of the depth test. The GPU looks at the different pixels and compares their respective depth values, the smaller (closer) ones get drawn while the others are discarded. We can change this behavior and set up another one, the stencil test, which is completely configurable.