Wednesday, July 31, 2013

Textured Hills Demo

This time around, we are going to revisit our old friend, the Waves Demo, and add textures to the land and water meshes.  We will also be taking advantage of the gTexTransform matrix of our Basic.fx shader to tile our land texture multiple times across our mesh, to achieve more detail, and use tiling and translations on on our water mesh texture to create a simple but very visually appealing animation for our waves.  This demo corresponds to the TexturedHillsAndWaves demo from Chapter 8 of Frank Luna’s Introduction to 3D Game Programming with Direct3D 11.0.  You can download the full source for this example from my GitHub repository at https://github.com/ericrrichards/dx11.git.

Here is a still of our finished project this time:


texHills

I’m also going to try to upload a video of this demo in action, as the static screenshot doesn’t quite do justice:

Monday, July 29, 2013

Texturing 101–Crate Demo


This time around, we are going to begin with a simple texturing example.  We’ll draw a simple cube, and apply a crate-style texture to it.  We’ll need to make some changes to our Basic.fx shader code, as well as the C# wrapper class, BasicEffect.  Lastly, we’ll need to create a new vertex structure, which will contain, in addition to the position and normal information we have been using, a uv texture coordinate.  If you are following along in Mr. Luna’s book, this would be Chapter 8, the Crate Demo.  You can see my full code for the demo at https://github.com/ericrrichards/dx11.git, under DX11/CrateDemo.

crate

Thursday, July 25, 2013

Three-point Lighting – LitSkull Demo

This time, we are going to take the scene that we used for the Shapes Demo, and apply a three-point lighting shader.  We’ll replace the central sphere from the scene with the skull model that we loaded from a file in the Skull Demo, to make the scene a little more interesting.  We will also do some work encapsulating our shader in a C# class, as we will be using this shader effect as a basis that we will extend when we look at texturing, blending and other effects.  As always, the full code for this example can be found at my Github repository https://github.com/ericrrichards/dx11.git; the project for this example can be found in the DX11 solution under Examples/LitSkull.



litskull1



litskull2



litskull3

Rendering the LitSkull scene with 1 light (key lit) Rendering the LitSkull scene with 2 lights (key and fill lit) Rendering the LitSkull scene with 3 lights (key, fill and back lit)

Wednesday, July 24, 2013

Lit Terrain Demo

Last time, we ran through a whirlwind tour of lighting and material theory, and built up our data structures and shader functions for our lighting operations.  This time around, we’ll get to actually implementing our first lighting demo.  We’re going to take the Waves Demo that we covered previously and light it with a directional light, a point light that will orbit the scene, and a spot light that will focus on our camera’s view point.  On to the code!


lighting

Tuesday, July 23, 2013

Lighting, Take 1

Last time, we finished up our exploration of the examples from Chapter 6 of Frank Luna’s Introduction to 3D Game Programming with Direct3D 11.0.  This time, and for the next week or so, we’re going to be adding lighting to our repertoire.  There are only two demo applications on tap in this chapter, but they are comparatively meatier, so I may take a couple posts to describe each one.

First off, we are going to modify our previous Waves Demo to render using per-pixel lighting, as opposed to the flat color we used previously.  Even without any more advanced techniques, this gives us a much prettier visual.

lighting
waves


To get there, we are going to have to do a lot of legwork to implement this more realistic lighting model.  We will need to implement three different varieties of lights, a material class, and a much more advanced shader effect.  Along the way, we will run into a couple interesting and slightly aggravating differences between the way one would do things in C++ and native DirectX and how we need to implement the same ideas in C# with SlimDX.  I would suggest that you follow along with my code from https://github.com/ericrrichards/dx11.git.  You will want to examine the Examples/LightingDemo and Core projects from the solution.

Monday, July 22, 2013

Dynamic Vertex Buffers: Waves Demo

We’ll wrap up the slate of examples from Chapter 6 of Frank Luna’s Introduction to 3D Game Programming with Direct3D 11.0 by taking a look at updating a vertex buffer each frame, as opposed to the immutable vertex buffers we have been working with previously.  We will be using the Hills Demo that we created previously as a starting point, and add a second grid mesh that will represent water.  We will update this mesh each frame, to get the ripple effect shown below.
waves

Saturday, July 20, 2013

Loading a Mesh From a File: Skull Demo

This time around, we are going to be loading a pre-defined mesh from a simple text-file format.  This will be a rather quick post, as the only thing different that we will be doing here is altering our CreateGeometryBuffer function to load the vertex and index data from a file, rather than creating it on-the-fly.  If you are following along with me in Frank Luna’s Introduction to 3D Game Programming with Direct3D 11.0, this example corresponds to section 6.12, and is a port of the Skull Demo from the example code.
skull

Friday, July 19, 2013

Cylinders, Spheres, and Boxes with Direct3D11 and SlimDX

This time up, we are going to add some additional shape types to our GeometryGenerator class, and look at how to redraw the same geometry at different locations and scales in our scene.  This example corresponds to the ShapesDemo from Frank Luna’s Introduction to 3D Game Programming with Direct3D 11.0.
shapes

Wednesday, July 10, 2013

A Colored Cube in DirectX 11 and SlimDX

Now that we have the demo framework constructed, we can move on to a more interesting example.  This time, we are going to use the demo framework that we just developed to render a colored cube in DirectX 11, using a simple vertex and pixel shader.  This example corresponds with the BoxDemo from Chapter 6 of Frank Luna’s Introduction to Game Programming with Direc3D 11.0
image

Monday, July 8, 2013

DirectX 11 Initialization with SlimDX and C#

I’m going to skip over the first few chapters of Introduction to 3D Game Programming with Direct3D 11.0.  I’ve got a basic understanding of basic linear algebra for 3D graphics, and I’m not eager to get into the weeds there, instead opting to go straight into the meat of DirectX coding.  Besides the math pre-requisites, these chapters also give an overview of the XNA Math C++ library, which I am going to forgo for the SlimDX types instead. 

With that out of the way, we will begin with Chapter 4, Direct3D Initialization.  This chapter covers basic initialization of the Direct3D device, and lays out the application framework used for the rest of the book.  If you’ve read any of Mr. Luna’s other DirectX books, this framework will look very familiar, and even if you have not, it is basically a canonical example of a Windows game loop implementation.  The framework provides a base class that handles creating a window, initializing DirectX, and provides some virtual methods that can be overridden in derived classes for application-specific logic.  Additionally, this chapter introduces a timer class, which allows for updating the game world based on the elapsed time per frame, and for determining the frame rate, using the high-performance system timer.
Capture

Thursday, July 4, 2013

Learning DirectX 11 via SlimDX

Personal things... 
A while back I picked up Frank Luna's Introduction to 3D Game Programming with DirectX 11. I've been meaning to start going through it for some time, but some personal things have cut into my programming time significantly.  I recently acquired a two year old Australian Cattle dog, and Dixie has kept me on the dead run for the weeks...  It's very difficult to muster up the courage to dive into a programming project when you feel half zombified from getting up at 4:30 to let the dog out so she will stop her adorable yet frenzied licking attacks on your fiance.

But today, I'm going to start.  I have not dealt with DirectX 11, nor 10 before; it's only in the last year or so that I built myself a modern desktop to replace my badly aging laptop from 2006.  I do have some experience playing around with DirectX 9, so it will be interesting to see what has changed.

As I mentioned, I'll be going through Introduction to 3D Game Programming with DirectX 11 by Frank D. Luna.  At first glance, it seems very similar to his previous book, Introduction to 3D Game Programming with Direct X 9.0c: A Shader Approach, which I found to be very well-written, with easy to follow code examples.  One wrinkle is that I'm going to be doing this in C#, with SlimDX, rather than in C++ and straight DirectX 11.  At my job, I mostly write C#, and have developed a serious fondness for it.  Additionally, I've found that attempting to port C++ code over to C# is a somewhat interesting exercise, and not a bad way to learn some of the darker and less-common corners of the C# standard libraries.

I plan on doing a post on each major example.  So there may be a couple per chapter, and I don't know what kind of pace my schedule will allow me.  If you're interested at looking at my code as I'm going along, you can clone my Git repository at https://github.com/ericrrichards/dx11.git.  I'm not going to include the original book code (I couldn't find a license specifically for the code, and I'm struggling to parse the legalese on the inside cover of the book), but you can download it from the book's website at http://www.d3dcoder.net/d3d11.htm.