Click here to Skip to main content
15,884,388 members
Articles / Nvidia

HLSL Development Cookbook–A Review

Rate me:
Please Sign up or sign in to vote.
5.00/5 (4 votes)
19 Sep 2013CPOL7 min read 16.6K   4   1
HLSL Development Cookbook Review

This article is in the Book Review chapter. Reviews are intended to provide you with information on books - both paid and free - that others consider useful and of value to developers. Read a good programming book? Write a review!

Introduction

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

Even I only have an appreciation for what's going on under the covers to create the mind blowing effects that only comes from mucking around in the graphics streams on the graphics card. XNA did a lot of this for us with 5 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 only intend on using 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 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 of the tips and tricks contained within, not to worry though if you are a noob or beginner then check out Riemers HLSL tutorial to get yourself up to speed on the basics – http://bit.ly/13stnxW.

This book, like many cookbooks is a heavy set 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.

An appreciation I got from reading this book is an understanding of how some effects are made and what inputs are needed to simplify their application. This puts me in good stead when I’m reading through Nvidia and AMD’s shader libraries looking for what I want or to keep things simple for just the effect I’m looking for.

I digress, 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 Open-mouthed smile), 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 to light 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, sounds great but 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 also a few tips and tricks to go beyond, covering things such as:

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

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, 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 lets you to give the effect that the player is in an actual 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 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

Some really nice examples of these effects (courtesy of @NemoKrad RandomChaos blog) can be found here.

Chapter 4 “Postprocessing”

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 adding a blur effect to objects not in focus, motion effects when you are moving fast or really shiny glow effects (really good for explosions Open-mouthed smile), 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 that make it live.

Postprocessing can make all the difference from a game people go WOW about to one they just go “meh” and walk on by and this applies to all games. Some devs do some of this 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 in this book in great detail:

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

Some really nice examples of these effects (courtesy of DarkOmenGames on the  RandomChaos blog) can be seen here.

Chapter 5 “Screen Space Effects”

Screen space effects are another class of post processing which 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 featured 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
    Reflections

Some really nice examples of these effects (courtesy of @NemoKrad RandomChaos blog) can be found here.

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 on our scene altered by other effects. This is 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 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
    Rain

Some really nice examples of a fire environmental effect (courtesy of @NemoKrad RandomChaos blog) can be seen here.


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 nicely surprised at how well the author broke down what each effect was meant to achieve and how it implement it.

Pros
  • 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
Cons
  • The book only covers the shaders themselves, not how to implement them (although the examples do but they are in C++ only)
  • Not all chapters have a visual example of the effect you’re creating so hard to visualise (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 Riemers 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 into more detail but not too much (there’s little math involved, phew) to help you appreciate just what your graphics card is doing to the output from your game.

What are you waiting for, get ready to make your game shine, whether you are 2D or 3D. Open-mouthed smile

HLSL Development Cookbook – packtpub

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect ZenithMoon Studios
United Kingdom United Kingdom
Long-time game developer / IT maniac.
By day I architect, design, build and deliver enriching Mixed Reality solutions to clients, bringing the work of AR/VR to light in new and interesting ways, by night I Masquerade as the Master Chief of ZenithMoon Studios, my own game development studio.

At heart, I am a community developer breaking down lots of fun and curious technologies and bringing them to the masses.

I'm also a contributor to several open-source projects, most notably, the Reality Toolkit and all the services provided by the Reality Collective, The Unity-UI-Extensions project, as well as in the past the AdRotator advertising rotator project for Windows and Windows Phone.

Currently, I spend my time fulfilling contracts in the Mixed Reality space (primarily for an XR experience firm called Ethar), writing books, technically reviewing tons of material and continuing my long tradition of contributing to open-source development, as well as delivering talks, but that goes without saying Big Grin | :-D

Mixed Reality MVP, Xbox Ambassador, MS GameDevelopment Ambassador & Best selling author:

[Accelerating Unity Through Automation](https://www.amazon.co.uk/Accelerating-Unity-Through-Automation-Offloading/dp/1484295072/ref=rvi_sccl_3/262-0817396-1418043)
[Mastering Unity 2D Game Development] (https://www.packtpub.com/game-development/mastering-unity-2d-game-development)
[Unity 3D UI Essentials] (https://www.packtpub.com/game-development/unity-3d-gui-essentials)

Comments and Discussions

 
NewsReview Copies Available HLSL development Cookbook by Packt !!! Pin
Sandy Joseph6-Aug-13 2:14
Sandy Joseph6-Aug-13 2:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.