Home Technical Talk

HLSL magic

polycounter lvl 18
Offline / Send Message
Slum polycounter lvl 18
In an attempt to take some load off other people at work (and beef up my skillset) I've committed to learning HLSL shaders. I've done a fair bit of scripting/coding over the years but I wouldn't call myself a programmer. Does anyone have any recommendations on books/sites to check out to get started?

Replies

  • Rob Galanakis
    Yes sir!

    First of all, read Ben Cloward's site, www.bencloward.com .
    Then, get a copy of ShaderFX for 3dsmax to fool around in, or alternatively you could probably mess around in the UE3 shader node tool. But I would recommend ShaderFX. This will allow you to get the hang of building shaders without actually coding and you will really understand the concepts behind them if you don't know already.

    There are also Ben Cloward's HLSL DVD's from CG Academy. These are very useful as an introduction to shaders and will take loads of the really hard work getting started with shaders (like any sort of scripting, the hardest part is just the basics, after that you can just look at sample code and references for ideas and techniques). Though if you have coding experience you may choose to pass over this, some guys at work just went through them and really enjoyed them though.

    As far as books, you can find some around. Just keep in mind, most Shader books come from the perspective of a Programmer, one who knows DirectX. Thus things are approached differently and with different assumptions. Which is why I suggest learning from other artists. Then once you are writing shaders, maybe approach them from a programmer's point of view. There are some very good chapters in Frank Luna's Game Programming with DirectX 9, specifically Part I (mathematical pre-requisites) and Part IV (Chapters 16, 17, 18, and 19 all concern shaders and effects framework). There are other books around too but I'd not prefer to read 500 pages instead of 'doing.'

    Otherwise, just look at shaders. Start with Ben's, they are pretty simple and well-written (though some of his earlier ones are not well written). I have some at http://robg3d.com/shaders.html which are a bit more advanced but I made sure to comment them well, so that may help... and I stay away from functions in those shaders to make them more easily readable to the uninitiated to the programming world (though code with functions is infinitely easier to read once you are comfortable with them). Another thing that helps (and still helps if I'm writing shaders for Max which has lots of peculiarities) is to take ShaderFX shader exports and edit them by hand to 'make sense.' This will give you a clearer idea of what goes on behind the scenes- so you can see cause and effect and then see the code that makes it happen.

    HLSL will be well worth the investment, especially as an Effects artist. IMO, HLSL is quite simple as far as programming goes. Spend a good weekend or two learning it and you're set. Once you can write your own very simple vertex and pixel shaders, that is 90% of the job. After that it is just reading other people's code for ideas and techniques for implementation; you've essentially learned all the basics of it and can do much of what you need.

    And sooner or later maybe there will be more artists represented in contests like this (yeah that's me on the bottom right, you haters)
  • CrazyButcher
    Offline / Send Message
    CrazyButcher polycounter lvl 20
    there is also "Mental mill - artist edition" which is node-based just like ShaderFX, and comes free with Nvidia's FX Composer 2.0.

    the app is standalone and can dump shader code, as well. (fx composer itself feels a bit bloated imo)

    the Cg Tutorial book, eventhough old, has some nice basic stuff. The Cg Manual (in here http://developer.download.nvidia.com/cg/Cg_1.5/1.5.0023/Cg-1.5_Sep2007_Setup.exe
    also comes with various tutorials and basic setup stuff (from the book).
    Cg code will work almost the same as HLSL. However I agree that books arent really needed, tons of material on the web. Check the Dx,ATI,Nvidia SDKs... or nvidias shader library and so on. There is also many "primer" tutorials on .fx/hlsl on the web.

    Other than that, it really comes down to playing around, once you got the basic setup done.

    the biggest problem is probably finding a IDE/Framework you enjoy working with wink.gif. Personally I just use crimsoneditor and for error checking send the .fx files to the dx/cg compiler myself. Viewing is done either in luxinia or 3dsmax... though there are some more lightweight simple shader editors out there (sadly many just for linux&glsl)
Sign In or Register to comment.