Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The last time I tried learning HLSL, I made a few shaders and mostly understood what I was doing, but I still felt like I was stumbling in the dark. Most of what I learned I got from various blog posts that didn't explain things very well.

Also, the documentation on MSDN seems to be more of a function reference.

Where can I learn to not only write HLSL, but learn techniques for writing shaders?

share|improve this question

closed as too broad by Josh Petrie Oct 23 '15 at 15:35

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs.If this question can be reworded to fit the rules in the help center, please edit the question.

12 Answers 12

Those two noted, I consistently come back to the following article almost every time I write a generic shader:

share|improve this answer
And I should specify that by "API reference" I mean more the "Programming Guide" section. – Sean James Jul 19 '10 at 17:16

If what you are after is "shader technique", rather than mere language reference (read the question, people), I recommend (from easy to advanced):

And basically either: Try things out and practice, all while absorbing how the "pros" do things. Or pick and choose things that are similar to what you're trying to achieve and work from there.

share|improve this answer

Cg is not technically HLSL, but syntactically they are virtually identical.

Having said that, it's an older book, but NVIDIA has made "The Cg Tutorial" free to read online. It covers the basics of the programmable pipeline in a very comprehensive fashion, and it should all translate to HLSL with minimal effort.

share|improve this answer
nVidia and Microsoft co-authored Cg/HLSL back in the day. They gave it different names due to branding, but the language is the same. Now, there's probably a slight difference, but it's truly minimal. – jacmoe Aug 4 '10 at 0:20
That is a phenomenal book. Basically anything by Kilgard was really good in terms of tutorials. – bobobobo Jul 20 '12 at 20:43

If you want to edit and see the results real-time you can use this simple Silverlight tool
Shazamm 1.3 - Editor & Previwer of HSLS Shaders

As for tutorials +1 for but I also found this series of XNA/HLSL tutorials even better.

Here's the list, you'll find them all here:

  • 1 – Intro to HSLS, ambient light
  • 2 – Diffuse light
  • 3 – Specular light
  • 4 – Normal mapping
  • 5 – Deform vertex shader
  • 6 – Shader demo: Simple ocean/island scenery
  • 7 – Toon shading
  • 8 – Gloss map
  • 9 – Wiggle post process
  • 10 – Invert post process
  • 11 – Grayscale shader
  • 12 – Pixel distortion shader
  • 13 – Alpha mapping
  • 14 – Transmittance/depth buffers
  • 15 – Dynamic Environment mapping
  • 16 – Refraction
  • 17 – Point light + Self-Shadowing
  • 18 – Multiple Point Lights
  • 19 – Hemispheric ambient light
  • 20 – Depth of Field
  • 21 – Transition: Fade
  • 22 – Transition: Cross
  • 23 – Blur
  • 24 – Bloom
  • 25 – Perlin Noise on the GPU
  • 26 – Bump Mapping Perlin Noise
share|improve this answer

A few things come to mind

  1. Introduction to 3D Game Programming With DirectX 9.0 (awesome)
  2. NVIDIA FX Composer (good for examples)
  3. There was a Shader X2 intro paper on ATI's website, but it's been removed... Ah! Found it here!
share|improve this answer

I found has a very good introductory tutorial on HLSL as part of its XNA tutorials. The author, Riemer Grootjans, also wrote the recommendable book XNA 3.0 Game Programming Recipes - if You like the recipe approach.

share|improve this answer

I would suggest you check the HLSL Development Cookbook , I found it to be really helpful. Especially chapter 3.

share|improve this answer

When I was reading about HLSL I found this tutorial back in the day. I liked it since it tried to explain every part of what it was doing.

share|improve this answer

I found a series of tutorials that goes from a basic ambient light shader all the way to reflections and toon shaders. Each goes through and explains every line and even explains some of the math a bit:

share|improve this answer

Not sure what shader model and DirectX version you are targeting but I highly recommend Practical Rendering and Computation with Direct3D11. The book walks you through all the nitty gritty details of DirectX11, it's resources, all the different pipeline shaders, HLSL (an entire chapter dedicated to this), and how to start implementing things like particle system simulations, tessellation, image processing, deferred rendering, and DirectCompute!

share|improve this answer

I do recommend this link for examples:

For those wondering why their code won't work, or if you're confused on how to incorporate the shader into your pipeline, this is a good place to go.

share|improve this answer

for me its easier to learn GLSL first, and since HLSL and GLSL is similar. once you understand the whole concept, the pipeline, the hardware and how the inner shader language work it's easy for you to use another language such as HLSL or even Cg.

I propose GLSL because it has a very good book such as the orange and red book of openGL and its easy to learn for beginner.

share|improve this answer
This doesn't answer the question. – PhillC Jul 20 '10 at 13:13
It's not a bad response though - much of what underlies GLSL is very similar to HLSL and if the OP can find resources for GLSL then it's valid to make use of them. Many of the major differences between the shader code itself are just a matter of mental conversion once you know what you're looking at. The idea of learning GLSL first fails because one would also have to learn OpenGL (not bad in itself; useful to know both) and rewrite one's program (bad), but there's absolutely nothing wrong with using GLSL material to supplement one's HLSL learning (and vice-versa, where relevant). – Le Comte du Merde-fou Jul 24 '12 at 2:55

Not the answer you're looking for? Browse other questions tagged or ask your own question.