Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
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?
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.
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.
\$\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\$
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.
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:
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!
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.
\$\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\$