DirectX10 Tutorial 9: The Geometry Shader

This tutorial is going to cover the basics of using the geometry shader stage present in DX10+. The geometry stage is extremely useful for rendering sprites, billboards and particles systems. This is the first part of a three part series which will cover geometry shaders, billboards and particles systems.

The Geometry Shader

The geometry shader stage was introduced in DX10 and people initially assumed that it would be useful for tessellation purpose (which is true) but it’s more useful for use with particles systems and sprite rendering. The geometry stage sits between the vertex and pixel shader stages and its primary use is creating new primitives from existing ones.

Just to recap, vertices are sent to the vertex shader within a vertex buffer that is stored on the GPU.  A draw call issued to the API, sends a vertex buffer down the pipeline.  Each vertex first enters the vertex shader where it is transformed as necessary, and its vertex data is modified (if necessary). Once vertices have been processed and outputted by the vertex shader, they get combined into primitives during the primitive setup stage of the API. The type of primitive created from the vertices sent through the vertex buffer depends on the primitive topology set (points, lines and triangles).  Normally, once a primitive is constructed, it moves on to the screen mapping and fragment generation (convert triangle to pixels) stages before reaching the pixel shader stage and finally being drawn to the screen. Continue reading “DirectX10 Tutorial 9: The Geometry Shader”

Weapon Modification in Games

I recently played through Fallout: New Vegas and couldn’t help but feel that while the whole weapon modification system was a nice addition, it was a pointless one. I, as much as anyone, love some good gun porn and being able to modify my weapon is a welcome addition to any game but in fallout:new vegas there really wasnt any reason to bother with it.

So what did I find so wrong with the weapon modification system in new vegas? Well two things, the first being that unique weapons exist in the game world. These unique weapons are far superior to their fully upgraded standard counterparts which makes you wonder why should I bother with the upgrades? You’ll spent a ton of cash buying the upgrades just to end up with an inferior weapon. Honestly, if designers want unique weapons, I think they need to either remove the entire modification system (and offer more unique weapons) or make the unique weapons upgradeable as well. Hell, make unique weapons unique by adding smaller perks like offering increased criticals or accuracy due to improved internals or improved reliability or something along those lines. That way the the player still has the option of modifying the unique weapons as well and not lose any of the unique features. Basically what you’d be doing is offering the player an improved base platform for the weapon modifications.

Hunting Rifle Upgrade Options from Fallout:New Vegas

Continue reading “Weapon Modification in Games”

Introduction to Game Development (Second Edition) Review

Introduction to Game Development 2ND Edition - Steve Rabin

Introduction to Game Development 2nd Edition - Steve Rabin

Introduction to Game Development is a book in the vein of the Game Programming Gems series, it consists of a collection of articles written by game industry veterans (Steve Rabin, Noel Llopis, Eric Lengyel, etc.) with the  aim of providing a solid overall introduction to the game development industry from all its various aspects, be they engineering, art or business based. Calling this a book is a bit misleading, it is more of a tome, this  hardcover 1000 page monster is extremely detailed and comprehensive for what you would expect just looking at the cover.

Continue reading “Introduction to Game Development (Second Edition) Review”

DirectX10 Tutorial 8: Lighting Theory and HLSL

This tutorial will deal with the basic scene lighting. It will cover the basic Phong and Blinn-Phong reflection models and the per-vertex (Gouraud) and per-pixel shading models (Phong). The Blinn-Phong reflection model is used in the openGL fixed-function pipeline (and as far as I know also used in DX9 but I’m not 100% sure).  Modern games don’t really used these shading models any more as they are very expensive especially when there are numerous objects and light sources in a scene and much more efficient techniques such as deferred shading are pretty much the industry standard at the moment in regards to scene lighting and shadowing. Even though the shading models may have changed and aren’t really all that relevant, the reflection models explained here are still in use. Continue reading “DirectX10 Tutorial 8: Lighting Theory and HLSL”

Video Game Optimization Review

Video game optimization by Eric Preisz and Ben Garney is a book that is focused on highlighting and addressing performance concerns found in modern video games. This is probably the best code optimization book that I have ever read. It is also the only book on the market that covers the entire game development programming pipeline from start to finish and is the only book I know of with a heavy focus on GPU and Shader optimization. In brief this this book fills an important gap in any game dev’s library and is an absolute gem. Continue reading “Video Game Optimization Review”

DirectX10 Tutorial 7: Viewports

This is going to be a very brief tutorial; the idea for it came about from a comment on my very first tutorial about using multiple viewports. I assumed that using multiple viewports would be a simple matter of just calling a SetViewport method just like in DX9, but it isn’t. I tried finding some info online but there is absolutely nothing available so I had to figure it out on my own. There are two methods to get multiple viewports working. The first requires a state change when selecting the viewports but I don’t think that the cost of that is too prohibitive since you would probably only swap viewports once per viewport during the scene rendering. The second method involves using a geometry shader to specify which viewport to use during the clipping/screen mapping stage in the pipeline.

What is a viewport

Well lets first discuss what a viewport actually is, if you Google a bit you’ll find almost no information regarding viewports or what they actually are (and there is absolutely no info in the DX documentation). A viewport is a rectangle that defines the area of the frame buffer that you are rendering to. Viewports do have depth values which affect the projected z range of any primitives in the viewport but this is only used in very advanced cases so you should always set the near depth to 0 and the far depth to 1. If we imagine a car game in which we have a rear view mirror, a simple method to draw the rear view mirror contents is to set the viewport to the mirror area, rotate the camera to face backwards and render the scene. Another common use in games is when you see another player’s viewpoint within your HUD (Ghost recon does this quite often), once again to render this all that is require is to set the viewport to the area of your final image you want to render to, then you render the scene from the other players viewpoint. Continue reading “DirectX10 Tutorial 7: Viewports”

Game Coding Complete (Third Edition) Review

Game Coding Complete 3rd Edition - Mike McShaffry

Game Coding Complete 3rd Edition - Mike McShaffry

I first heard of this book when it won the Game Developer Magazine book of the year award, I kinda made a note to get hold of it and then kinda forgot about it. I only remembered about it when it popped up in my amazon recommended books newsletter and I pulled the trigger on it.

This book is written primarily by Mike McShaffry (who spent years working for origin on the Ultima games) with a few chapters by guest authors. It aims to cover the A to Z of game programming in one book and in that regard it both succeeds and fails. The book is targeted at beginners and I guess for me that was my the biggest issue.

Continue reading “Game Coding Complete (Third Edition) Review”

Setting up the DirectX SDK with Visual Studio 2010

So I had a bit of time this morning and finally upgraded to visual studio 2010. There are a lot of changes but I am really enjoying it. It is a definite improvement over VS2008, some features that I have been begging for for years are finally in and the interface has been cleaned up significantly.

The new help system takes a bit of getting used to but it is only the first version and they promised that some massive improvements are coming.

Now Getting DX integrated with VS2010 was a bit tricky as the installer doesn’t automatically as the SDK include and lib folders to the default include/lib folders as it did in VS 2008, and it requires a bit of fiddling.

Setting up the Include and Library Paths

They removed the global VC path system accessible through the options dialog and have opted for a per-project path system with several global user files. This mean that for every single project that you make that uses the DX API you will need to add in the DX SDK directories manually via the project properties -> VC++ Directories (I’d personally recommend this technique since it allows projects to be more portable) but if you are lazy, you can add the SDK paths to the default c++ project settings template stored in the glocal cpp user file. This is done as follows:

Step 1: Open up the “Property Manager” under the “View” menu.

Continue reading “Setting up the DirectX SDK with Visual Studio 2010”

Game Engine Architecture Review

Game Engine Architecture - Jason Gregory

Game Engine Architecture - Jason Gregory

I’ve toyed around with building a very simple game engine over the last few months and made some progress in regards to the renderer of the engine but unfortunately during development, for every question I answered another 10 sprung up, with every new question and my frustration grew, and after the third re-planning of the engine core and the 4th rewrite, I gave into my frustration and just threw the engine on the back burner. Now why didnt I just get a book on game engines and move on from there, well I’ve read a few books on the topic of designing and creating game engines in the past, and they left me severely unimpressed and jaded, possibly some of the biggest wastes of paper out there  and I guess that’s one of the reasons I avoided looking for a new book on the topic and just gave up. Continue reading “Game Engine Architecture Review”

DirectX10 Tutorial 6: Blending and Alpha Blending

It’s been ages since my last DirectX 10 tutorial and I apologize, I’ve been buried under a ton of work and haven’t had much free time lately. This is going to be a very short tutorial on pretty much the final stage in the rendering pipeline: color blending. If you recall, each frame displayed on the screen is simply a bitmap that gets displayed and updated multiple times a second. This bitmap is called the frame buffer, now the frame buffer is technically the image we see at any given point and the back buffer (assuming you are double buffering) is what you actually draw to (referred to as your render target) and only once you finish drawing do you display the back buffer to the screen by swapping the frame buffer and the back buffer by using the Present member of the DX10 swapchain class.

Now think back to the depth testing tutorial where we displayed that cube and had to enable depth testing for it to render properly. Now a  cube is made up of 6 sides with 2 faces per side, so that is 12 triangles we have to draw for each cube. The graphical API draws one triangle at a time to the back buffer, and used the depth buffer to check whether it can overwrite a pixel in the back buffer if the new pixel to be drawn is in front of it. If this test passes then the API is given permission to overwrite that pixel’s value but its not as simple as that! Continue reading “DirectX10 Tutorial 6: Blending and Alpha Blending”