28
\$\begingroup\$

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?

\$\endgroup\$

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

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

12 Answers 12

14
\$\begingroup\$

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

\$\endgroup\$
  • 1
    \$\begingroup\$ And I should specify that by "API reference" I mean more the "Programming Guide" section. \$\endgroup\$ – Sean James Jul 19 '10 at 17:16
6
\$\begingroup\$

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.

\$\endgroup\$
3
\$\begingroup\$

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.

\$\endgroup\$
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ – jacmoe Aug 4 '10 at 0:20
  • \$\begingroup\$ That is a phenomenal book. Basically anything by Kilgard was really good in terms of tutorials. \$\endgroup\$ – bobobobo Jul 20 '12 at 20:43
3
\$\begingroup\$

If you want to edit and see the results real-time you can use this simple Silverlight tool

http://shazzam-tool.com/
Shazamm 1.3 - Editor & Previwer of HSLS Shaders


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

Here's the list, you'll find them all here: http://digitalerr0r.wordpress.com/tutorials/

  • 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
\$\endgroup\$
2
\$\begingroup\$

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!
\$\endgroup\$
1
\$\begingroup\$

I found Riemers.net 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.

\$\endgroup\$
1
\$\begingroup\$

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

\$\endgroup\$
0
\$\begingroup\$

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.

\$\endgroup\$
0
\$\begingroup\$

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:

http://rbwhitaker.wikidot.com/hlsl-tutorials

\$\endgroup\$
0
\$\begingroup\$

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!

\$\endgroup\$
0
\$\begingroup\$

I do recommend this link for examples: http://www.codesampler.com/dx9src/dx9src_8.htm#dx9_hlsl_fx_simple

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.

\$\endgroup\$
-1
\$\begingroup\$

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.

\$\endgroup\$
  • 1
    \$\begingroup\$ This doesn't answer the question. \$\endgroup\$ – PhillC Jul 20 '10 at 13:13
  • \$\begingroup\$ 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). \$\endgroup\$ – Maximus Minimus Jul 24 '12 at 2:55

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