Over a million developers have joined DZone.

HLSL Development Cookbook–a review


While finally getting back around to my game development roots, another interesting book crossed my desk that delves into the mysterious, and sometimes scary, world of shaders.

I have an appreciation for what is going on under the covers to create the mind-blowing effects that only come from mucking around in the graphics streams on the graphics card. XNA did a lot of this for us with five built-in shaders that gave us a leg up and provided most of the basic effects used in common games.

To really make your game shine and look impressive, you need to have a good understanding of shaders.  Even if you intend to use the many resources out there to enhance your game, it helps to understand how and why these things work.

HLSL Development Cookbook

So if you want to know more about what goes on under the covers, and you want to start making / enhancing your own effects, read on.

The HLSL Development Cookbook is targeted for intermediate or experienced developers in the land of shaders, so some up-front knowledge is needed to get a real appreciation for the tips and tricks contained within.  Not to worry though, if you are a beginner when it comes to shaders, then check out Riemer's HLSL tutorial to get yourself up to speed on the basics.

This book, like many cookbooks, is a heavyset reference for shading techniques and explanations of some generic lighting and post processing effects.  What makes it good is that it leads you down a very direct path to understand exactly how these effects work and what makes them tick, leading you to try and test your own techniques and improve on them, or create new shaders.

While reading this book, I gained an understanding of how some effects are made, and what inputs are needed to simplify their application.  This puts me in a good spot when I’m reading through Nvidia and AMD’s shader libraries looking for what I want.

So what can we look for in this book?

Here’s a brief run through what all the chapters are and what to expect from them.  The book is laid out like a traditional HLSL cookbook breaking down effects and showing how each component works and its end effect on the resultant output.

Chapter 1 “Forward Lighting”

Lighting is one of the most basic and commonly used shader techniques.  After all, without light, there would only be darkness (which is only good for audio games). This chapter goes into some depth on the main basic lighting systems used in games today, such as:

  Hemispheric ambient light
  Directional light
  Point lights
  Spot lights
  Capsule lights
  Projected textures – point & spot lights
  Multiple lights in a single pass

Through this chapter, you will learn what you need to know about lighting up your scene and the models within it.

Image courtesy of Riemers HLSL tutorial

Chapter 2 “Deferred Shading”

Deferred shading is one of those advanced techniques to light a scene in a more efficient and performant way by calculating all lights at the same time, without the limitation of the geometry that it’s being applied to.  It sounds great, but it's a lot trickier to implement than standard lighting, especially since it takes multiple passes within the shader to accomplish.

In this chapter, the author does a good job of explaining all the parts needed to achieve deferred rendering and how best to implement it with a few tips and tricks to go beyond deferred rendering, covering things such as:

  GBuffer generation and unpacking
  Deferred Directional, Point, Spot and Capsule lights

Here are some really nice examples of these effects (courtesy of @NemoKrad RandomChaos blog)

Chapter 3 “Shadow Mapping”

So far, the book has covered how to add light and, as expected, we also need to be able to work by subtracting light to really show off how elements in the game are effected by the environment they are playing in (just ask Peter Pan what he thinks of his own shadow!).

Shadow mapping also gives players the feeling that they are in a real world.  Without it, games generally look flat (even 2D ones).  Through this chapter, you are shown several techniques to generate shadows.  As with everything else, there is no one silver bullet to solve a problem like shadows, so it is really good that the author offers some of the main solutions.

Techniques you will learn include:

  Spot & point light PCF (percentage-closer filtering) shadows
  Cascaded shadow maps
  PCF with varying penumbra size
  Visualizing shadow maps

Here are some really nice examples of these effects (courtesy of @NemoKrad RandomChaos blog)

Chapter 4 “Post-processing”

Now that you have a rendered scene in your game, it’s always good to add those extra special effects to make your game shine, like a blur effect to objects not in focus, motion effects when you are moving fast or really shiny glow effects (really good for explosions).  This is where post processing comes in.

Ask any photographer worth his salt about post-processing and they will likely chew your ear off for hours.  Those final touches you add to a scene are what give it life.

Post-processing can make all the difference between a game where people go "WOW" to a game where they just go “meh” and walk on by.  Some developers do post-processing work in advance by baking the textures to be used in the game, but even then, some additional effects are needed to blow them up.

The most common post-process effects are covered by this book in great detail:

  HDR rendering
  Adaptation (adjusting lighting from bright to dark spaces)
  Distance depth of field
  Bokeh (handling distant lighting)

Here are some really nice examples of these effects (courtesy of DarkOmenGames on the RandomChaos blog)

Chapter 5 “Screen Space Effects”

Screen space effects are another class of post-processing that focus on elements that effect the entire scene (usually from a single element, like the Sun).  Some see them as just another post-process.  Others see them as a particular form of advanced shading.  In either case, it is a very useful technique to have under your belt, especially if your game is set in space or the great outdoors.

Of the main types of “screen space effects” this book covers:

  Ambient occlusion
  Lens flare
  Screen space Sun rays

Here are some really nice examples of these effects (courtesy of @NemoKrad RandomChaos blog)

Chapter 6 “Environment Effects”

So we have our nicely lit and rendered scene in HD, but wouldn’t it also be nice to alter and change how things look in the scene on the fly, or have the textures on the objects in our scene be altered by other effects.  These are generally referred to as environmental effects, the most basic of which would be a rain effect, since rain distorts light when viewed through it, and it leaves a smear as it goes.

These are fairly advanced techniques for altering the environment based on another texture or set of rules.

Here, the author nicely rounds off the book with the following techniques:

  Dynamic decals
  Distance/Height-based fog

Here are some really nice examples of a fire environmental effect (courtesy of @NemoKrad RandomChaos blog)

Shaders are one of those subjects that is hard to get into and even harder to master. It’s practically a specialty in its own right, so I was pleasantly surprised at how well the author broke down what each effect was meant to achieve and how to implement it.

  • Great introductions and explanations of the effects covered
  • Complete projects available to download for each effect
  • Does not overload you with detail, keeps things simple
  • The book only covers the shaders themselves, not how to implement them (although examples do, but only in C++).
  • Not all chapters have a visual example of the effect you’re creating, so it can be hard to visualize (but you can figure it out),

Even with my rudimentary shader knowledge, I was able to understand the workings of each shader detailed in this book (even without googling).  If you are a beginner, just refer to Riemer's tutorials or the fantastic set of beginner HLSL tutorials on GameDevTuts, and you will be ready for the techniques in this book.  I feel it goes in to more detail than Riemer's tutorials, but not too much (there’s verylittle math involved, phew).  The book helps you appreciate all the things that your graphics card is doing for your game.

What are you waiting for?  Get ready to make your game shine, whether you are 2D or 3D!

HLSL Development Cookbook – packtpub


Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}