HLSL Development Cookbook – Review

September 7th, 2013

I just picked up a copy of the new HLSL Development Cookbook. The book is a great continuation of the very basic shader set up I have implemented in the XNA tutorial engine, but goes into much more complex and deeper shaders taking full advantage of the new possibilities provided by DirectX 11.

The book tends to be pretty source heavy (HLSL source that is) with very little C++ or DirectX code being shown, so it is definitely recommended to at least have a basic grasp of setting up a simple DirectX 11 application works before tackling the content. On the bright side though, all of the HLSL source is explained in great detail including many diagrams to help get across more of the complicated concepts that aren’t necessarily obvious just from reading the code itself. One thing I really got from these descriptions and diagrams was a good explanation of how the half angle optimization for Blinn Specular works. I always knew how to write the code for this technique but never really understood the real reasoning behind why it works until now.

If you found the samples in my lighting tutorials helpful at all, then you will love the first chapter of this book. The same basic layout is used in all of the shaders that I introduced, but right away a more advanced look at using different light types and effects are included. Each “recipe” builds on top of the last one, so going through the whole chapter one sample at a time is a great way to build your knowledge of all the standard lighting types and shaders normally used.

Once you have a firm grasp of the different shading models and techniques for each light type, Chapter 2 will take you into the much more complicated but also more high performance world of Deferred Shading. Using the new Hull and Domain shader functionality provided by DirectX 11, much of the hard work of optimizing the steps of Deferred Shading are easily handled. All of the complexities of basic Hull and Domain shaders are explained while developing the model, and each light type from the first chapter is then implemented in a single flexible shader that can eventually handle multiple lights (up to 4) in a single rendering pass.

After Deferred Shading, the much more advanced and complex techniques of shadow maps, post processing, screen space effects like ambient occlusion and “god rays”, and environmental effects like fog and decals are discussed in depth. There is too much content to go in to in a simple review, so why don’t you go pick up a copy and see for yourself how great the recipes in this title are and how much you can learn from it! I know I’ll be using the techniques in future development.

Book Link:

Sample Chapter:

Windows 8, Visual Studio 2012, DirectX 11

September 27th, 2012

For a short while now I have been working on porting over most (if not all quite yet) of the functionality of the tutorial HMEngine to a DirectX 11 and C++ version of things that I have been calling “Haze”. Recently, quite a few changes have been occurring that greatly affected how I have been going about this and I have once again wiped the project slate clean and started it up again using the new functionality available in Windows 8 and Visual Studio 2012.

One of the major changes I have made to things now that the base engine is in place and working is changing the static ComponentManager class that used to handle all of the Initialization, Loading, Updating, and Rendering of objects. It has now been transformed into a Scene class and a Scene Manager. Using the new setup, I can put together completely independent groups of items, effects, and cameras (one per scene for now) and load and unload any scene at will.

Using the new XAML UI integration in the Windows 8 version of a Direct3D application, I have hooked up the Scene Mananager to a set of buttons and can swap between them with a simple click. Here is a quick screen shot of what I am talking about (albeit with a VERY simple scene):


Technical Review: XNA 4.0 Game Development by Example – Visual Basic Edition.

January 1st, 2012

Just finished up a detailed technical edit of the new Visual Basic version of a book I reviewed previously. The new Visual Basic version with my edits included is now available from Packt Publishing. Check it out!

XNA 4.0 Game Development by Example: Beginner’s Guide – Visual Basic Edition

Also available from Amazon

Git, push all local branches to origin

October 26th, 2011

At work when we do bug fixes we always create a numbered branch matching our ticket number off of our current production code:

git checkout -b [ticket number here] production

This makes for incredibly simple merging and passing bug fixes around. I come across the issue a lot where I will have about 5 bug fix branches created locally and cannot remember which ones I have pushed to my origin (github) and which I haven’t. There is a command to view unpushed commited branches:

git log --branches --not --remotes --simplify-by-decoration --decorate --oneline

This ugly thing pretty much just parses the log for commits not in your remotes and dumps the result with one branch per line. What it doesn’t do is push these branches for me. Instead of trying to remember that all the time I decided today to just chain a few linux commands I do remember to make it a bit easier for myself:

git branch | grep [0-9] | xargs git push origin

This much shorter command just takes all of my number named branches and tries to push them. If they are already up to date, no biggie, git just returns a nice message telling me so. Branches that need updating on my origin get updated.

This little command only works when my HEAD is not currently on one of my numbered branches, otherwise the little “*” causes way more things than I want to push to my origin. There are, I’m sure, many ways to make this command better, but this simple form with its few prerequisites (not being on one of the branches being pushed) works out great for me.

Anyone else have some tricks for keeping your origin up to date?

Ireland Trip 2011

September 26th, 2011

2011 October 7 – 2011 October 17

I will try to get photos on the map as well as we are travelling. If I’m having too much fun to add photos you’ll just have to wait until we get back to see them!

View Ireland 2011 in a larger map


Bozeman to SLC


Dublin to Kinsale

Kinsale and Cork

Ring of Kerry


Dingle to Ennis

Ennis (Cliffs of Moher)

More Tessellated Terrain

August 25th, 2011

Just a quick note about some small changes I made to the terrain object in Haze. Originally its initialization code just created a single quad made of two triangles with an index buffer in the form {0, 1, 2, 2, 3, 0}. Since then I have updated the constructor to take in an initial size value (int) that sets the number of quads (width and height) in the x and z direction to create. The initialize method now just generates the starting geometry in a loop and sends quad indexes in instead of triangles {0, 1, 2, 3}

The major effect this has on things is that now there can be a single vertex for every single texel passed in as a height map. Since the max tessellation level is 64, we only have to make an 8×8 initial grid to get a full 512×512 tessellated terrain. This opens up other doors as well for things like levels of detail using different tessellation in different quads based on camera distance or view angle. Next up is to get some texture mapping going and see how much I can make things look like real terrain.

I might start with standard splatting techniques, but I’d really like to have the video card generate some of the splat “stencils” based on heights on the whole map (snowy parts at the highest points, less snow on steep slopes, etc.) We’ll see what happens.

Tessellated Terrain

August 18th, 2011

As an exercise in learning Hull and Domain shaders with DirectX 11, I decided to whip up a quick (or what I thought would be quick) height mapped terrain demo that only sent a single quad to the video card and handled everything else in the shader. Aside from some minor problems remembering to use SampleLevel instead of Sample in the Domain Shader everything came together fairly well.

At the moment I have a 512 x 512 height map texture (a simple black and white Filter > Render > Clouds in Photoshop) and a single quad that gets tessellated up to level 64 with the heights added in the Domain Shader. I am currently tessellating at the triangle level and would like to switch to quad as well just to see how it looks both ways. I’ll stick a video of the whole on here once I get the quad tessellation going and throw in a FillMode = Wireframe option to make it easier to see what is going on.

edit: Here’s the video

DirectX 11 and C++

July 17th, 2011

To try and expand my programming horizons a bit, I am working on a version of the HMEngine (codenamed Haze for the moment) using C++ and the latest DirectX version. It has been a while since I have coded anything large in C++ so I’m sure there will be a bit of a curve getting back into it. I am considering posting this version of the engine as a tutorial series alongside the XNA ones depending on how things go and if I feel the concepts are simple enough for beginning game developers. I may also just put it together as a small demo engine for more of a portfolio use. If anyone has thoughts or opinions about this please let me know in the comments.

Tabs vs Spaces

June 16th, 2011

Tabs. Period.

If you think spaces are better, you are stupid. I can’t set a space width on my editor to deal with your stupid 2 space indents. You can use tabs and set your editor to show tabs as 2 spaces though. So why don’t you stop being stupid and just use tabs so we can both read your code. Although if you are writing code that uses spaces for indentation it probably isn’t worth reading anyway.

3D Graphics with XNA Game Studio 4.0 – Review

February 14th, 2011

I recently got a copy of the  new 3D Graphics with XNA Game Studio 4.0, which (complexity wise at least) is a good follow up book for the previous XNA GDBE I just finished going through. This new book skips entirely over the 2D aspects of XNA game development and dives straight in to getting some pretty 3D graphics on the screen. My personal preference (as I noted in my review of XNA GDBE) is towards the 3D side of graphics and game development, so I felt a lot more at home in the code and content of this book.

Sean James doesn’t fool around with a lot of fluff and fillers in the book, which I see as both an asset and a liability. It is an asset for anyone who is highly familiar with the topics in the book but hasn’t personally implemented many of them. In this case the book can be used as a great reference for code (which is most of the content of the book after all) and not have to worry about the explanations of the code blocks. This specific use is actually mentioned in the book itself as one of the uses. There are a few comments sprinkled around the C# and the HLSL code to help you along if you need it, but not so much to get in the way of quickly skimming and finding what you are looking for.

I consider this same aspect a liability depending on the person who is actually reading the book. For someone who has not done a lot of HLSL or other shader development, the amount of HLSL code with very little explanation can seem daunting, but could of course also be a great challenge for anyone who really likes to learn and grow in their abilities and is perfectly fine with having to work for their knowledge (which is much more the kind of learner that I am.) I don’t say this as a criticism of the book or its writing style, as many of the code blocks in my own tutorials are put together in the same way (although I do try to make things as easy to understand as I can). I mostly am mentioning this to let people know that if they aren’t comfortable having to think a little bit about the code they are looking at, they might want to look for their code samples elsewhere.

One of the best things about this book that I have personally had a hard time finding anywhere else is actually the great amount of HLSL code for the various different types of effects presented in the book. Deferred lighting (called prelighting in the book), skinned animations, diffuse and specular lighting, materials and shadowing are all very advanced and difficult to learn effects in shaders and all of them are presented in this book in one easy to use format. Many of these topics are ones that I have been considering implementing in my own engine for a long time, but haven’t really found any concise examples of how others have implemented similar features in their own games, and haven’t found the time to just dive in and figure the whole thing out from scratch myself.

The one problem I had with the book is the lack of color visuals that I feel the topics in this book really require to get across the level of understanding of what visually is really happening in the code. One place where this becomes incredibly obvious is in one of the images that is explained as having been generated by adding eight colored point lights to a scene with a teapot, where the image itself simply looks like a single spot light shining down from above. Using a colored image to show the color blending of the lights and the point light effect instead of the plain gray spot type output that the image looks like it is showing would greatly enhance the effect that having images at all adds to the content of the chapters. Many of the Game Development Gems books get around this issue by just including large number of high resolution glossy color print pages in the middle of the book that can be turned to whenever any other chapter needs to reference a graphic or visual help to really get their concepts across. I really feel like this is probably the only thing missing from this book.

In the end, 3D Graphics with XNA Game Studio 4.0 is a great intermediate to advanced XNA book and an especially good reference for anyone looking to start learning or to learn more HLSL shading and advanced rendering techniques. As I mentioned before, finding this much good shader code across so many varied topics in one place has been almost impossible for me in the past, and I am incredibly happy that someone has finally put something out there to help other like me be able to find and learn these topics better without scouring the internet for days at a time.

Overall I am incredibly impressed with the content and the code in this book and can’t wait to find a good way to implement similar effects into the HMEngine in hopefully a way that is easy enough for everyone to understand. Hopefully I can just find the time to get some of it done!

Book Link: http://link.packtpub.com/dRrfxI

Sample Chapter: http://www.packtpub.com/sites/default/files/0041-chapter-7-environmental-effects.pdf

Do NOT follow this link or you will be banned from the site!