<p>I want to get started doing some game development using Microsoft's XNA. Part of that is Shader development, but I have no idea how to get started. I know that <a href="http://developer.nvidia.com/object/fx_composer_home.html" rel="noreferrer">nVidia's FX Composer</a> is a great tool to develop shaders, but I did not find much useful and updated content on how to actually get started.</p>

<p>What tutorials would you recommend?</p>

[{'answer_id': 6971, 'author': 'Nidonocu', 'author_id': 483, 'author_profile': 'https://Stackoverflow.com/users/483', 'pm_score': 1, 'selected': False, 'text': '<p>SAMS\'s <a href="https://rads.stackoverflow.com/amzn/click/com/0672329646" rel="nofollow noreferrer" rel="nofollow noreferrer">XNA Unleashed</a> by Chad Carter is a great starting point for XNA and assumes little knowledge of game development practices or hard maths before you start. It has two chapters on basic and advanced shaders.</p>\n\n<p>As a sidenote, keep an eye out on Google for WPF Shader tutorials, it now uses the same technology to allow customer shaders in WPF applications and tutorials for that I believe are largely compatible with XNA.</p>\n'}, {'answer_id': 7039, 'author': 'OJ.', 'author_id': 611, 'author_profile': 'https://Stackoverflow.com/users/611', 'pm_score': 6, 'selected': True, 'text': '<p>Development of shaders in XNA (which obviously uses DirectX) requires knowledge of <a href="http://msdn.microsoft.com/en-us/library/bb509561(VS.85).aspx" rel="noreferrer">HLSL</a> or shader assembly. I\'d recommend getting familiar with the former before diving into the latter.</p>\n\n<p>Before writing any shaders, it\'s a good idea to get solid understanding of the shader pipeline, and attempt to get your mind around what is possible when using programmable shaders. When you\'re familiar with the life of a pixel (from source data all the way through to the screen) then understanding examples of shaders becomes a lot easier.</p>\n\n<p>Next make an attempt to write your own HLSL which does what the <a href="http://www.computerhope.com/jargon/t/tandl.htm" rel="noreferrer">Fixed T&amp;L</a> pipeline used to do, just to get you hands dirty. This is the equivalent of a "hello world" program in vertex/pixel shader world. When you\'re able to do that and you understand what you\'ve written you\'re ready to go onto the more fun stuff.</p>\n\n<p>As a next step you might want to simulate basic <a href="http://www.gamasutra.com/features/20030418/engel_pfv.htm" rel="noreferrer">sepcular lighting</a> in one of your shaders from a single light source. You can then adapt this down the track to use multiple lights. Play with colours, and movement of lights. This will help get familiar with the use of shader constants as well.</p>\n\n<p>When you have a couple of basic shaders together, you should attempt to make it so that your game/engine uses multiple/different shaders on different objects. Start adding some other bits like basic <a href="http://www.paulsprojects.net/tutorials/simplebump/simplebump.html" rel="noreferrer">bump</a> or <a href="http://www.bencloward.com/tutorials_normal_maps1.shtml" rel="noreferrer">normal maps</a>.</p>\n\n<p>When you get to this stage, the world is your oyster. You can start diving into some funky effectcs, and even consider using the GPU for <a href="http://www.gpgpu.org/" rel="noreferrer">more</a> than it was originally intended.</p>\n\n<p>For those who are a little more advanced, there are a couple of good books that are available for free online which have some great information from Nvidia <a href="http://developer.nvidia.com/object/gpu_gems_home.html" rel="noreferrer">here</a> and <a href="http://developer.nvidia.com/object/gpu_gems_2_home.html" rel="noreferrer">here</a>.</p>\n\n<p>Don\'t forget that there\'s an excellent series of books called ShaderX which covers some awesome shader stuff. There\'s <a href="https://rads.stackoverflow.com/amzn/click/com/1556220413" rel="noreferrer" rel="nofollow noreferrer">1</a>, <a href="https://rads.stackoverflow.com/amzn/click/com/1556229887" rel="noreferrer" rel="nofollow noreferrer">2</a>, <a href="https://rads.stackoverflow.com/amzn/click/com/1584503572" rel="noreferrer" rel="nofollow noreferrer">3</a>, <a href="https://rads.stackoverflow.com/amzn/click/com/1584504250" rel="noreferrer" rel="nofollow noreferrer">4</a>, <a href="https://rads.stackoverflow.com/amzn/click/com/1584504994" rel="noreferrer" rel="nofollow noreferrer">5</a> and <a href="https://rads.stackoverflow.com/amzn/click/com/1584505443" rel="noreferrer" rel="nofollow noreferrer">6</a> already in print, and <a href="http://www.shaderx7.com/" rel="noreferrer">7</a> is coming soon.</p>\n\n<p>Good luck. If you get some shaders going, I\'d love to see them :)</p>\n'}, {'answer_id': 11247, 'author': 'Ali Parr', 'author_id': 1169, 'author_profile': 'https://Stackoverflow.com/users/1169', 'pm_score': 3, 'selected': False, 'text': "<p>I'd just like to reiterate how great the GPU Gems books are - a truly fantastic resource for any serious graphics development.</p>\n\n<p>OJ has basically summed up a really good process of learning, I'd just add that having a good foundation in geometric math (vectors/matrices as a minimum) cannot be underestimated - but it's not as hard as people sometimes make out. Learning what a dot product, cross product, normal vector and matrix multiply are and do is a good first step :). Try to understand exactly what is happening between World/View/Projection-Clip/Screen space, what the perspective divide is, etc.</p>\n\n<p>When I was beginning learning, a good exercise is to actually implement the entire T&amp;L pipeline in software, complete with clipping/culling etc. This is a long process and may not seem worthwhile as I'm sure you want to just dive into the fun stuff, but having a proper understanding of what's going on is really useful and will prove worthwhile when you invariably run into more insidious and difficult to diagnose bugs.</p>\n\n<p>Try not to be sidelined with tools like the FX Composer initially, they're useful for prototyping, but having a solid foundation in the basics is much more worthwhile in the long run.</p>\n"}, {'answer_id': 14430, 'author': 'Ashwin Nanjappa', 'author_id': 1630, 'author_profile': 'https://Stackoverflow.com/users/1630', 'pm_score': 1, 'selected': False, 'text': '<p>I haven\'t used XNA or DirectX. But, for getting to know the basics of shader programming with Cg, the <a href="http://developer.nvidia.com/object/cg_tutorial_home.html" rel="nofollow noreferrer">Cg Tutorial</a> is the best book I\'ve found.</p>\n'}, {'answer_id': 32518, 'author': 'Joel Martinez', 'author_id': 3433, 'author_profile': 'https://Stackoverflow.com/users/3433', 'pm_score': 1, 'selected': False, 'text': "<p>You should also look at RenderMonkey.  It's a good tool.  As far as books go, check out XNA 2.0 Game Programming Recipes from Riemer Grootjans ... great book.</p>\n"}, {'answer_id': 86460, 'author': 'Adi', 'author_id': 9090, 'author_profile': 'https://Stackoverflow.com/users/9090', 'pm_score': 2, 'selected': False, 'text': '<p>I\'d join the praises given to OJ - truely a good answer.\nStill, once you do have the basic understanding you can learn a lot and fast by downloading one of the following two great tools:</p>\n\n<ul>\n<li>Render monkey <a href="http://ati.amd.com/developer/rendermonkey/downloads.html" rel="nofollow noreferrer">http://ati.amd.com/developer/rendermonkey/downloads.html</a> or the </li>\n<li>Fx Composer <a href="http://developer.nvidia.com/object/fx_composer_home.html" rel="nofollow noreferrer">http://developer.nvidia.com/object/fx_composer_home.html</a></li>\n</ul>\n\n<p>Once you do that, go to their project libraries and start browsing through examples, starting with the basic shading and moving to shadows, normal mapping, materials, effects and everything you find of interest.\ntake a project, start altering the algorithms according to some goals you set and see how to get it.\nYou\'ll find that many of the examples are really advanced and they will open up your horizons.</p>\n\n<p>Have fun</p>\n'}, {'answer_id': 240632, 'author': 'Ray Hayes', 'author_id': 7093, 'author_profile': 'https://Stackoverflow.com/users/7093', 'pm_score': 2, 'selected': False, 'text': '<p>Whilst a lot of good advice has already been given, if you\'re having a hard job getting your mind around the steps involved, <a href="http://www.mentalimages.com/products/mental-mill.html" rel="nofollow noreferrer">Mental Mill</a> provides a visual way of constructing Shaders (the Artist Edition is bundled free with Fx Composer -- itself also free!).</p>\n\n<p>Whilst you\'d be better off long term learning the HLSL code directly, Mental Mill can generate these Fx files for you (so you can peek at the changes).  Note, like all code-generators, it\'s a little more verbose than you\'re likely to do once you understand HLSL!</p>\n\n<p>The visual progression of the effects, from one method to another, is very impressive!</p>\n'}, {'answer_id': 291975, 'author': 'Rodrigo Lopez', 'author_id': 36295, 'author_profile': 'https://Stackoverflow.com/users/36295', 'pm_score': 1, 'selected': False, 'text': "<p>One quick thought on visual shader editors.\nThose sort of editors are a very fun thing to play with, but I would really, really recommend to stick with working with text-based HLSL (there both RM and FXC do the job). I work as a game dev and have built a few shader systems (the one in Battlefield 2 and Farcry 2, for instance) and, to be honest, have found that HLSL is more valuable than any graphic shader network to date. </p>\n\n<p>There are things like following the flow of execution, debugging the shader or being able to quickly iterate test cases that give you an insight that is pretty much impossible to get through a visual tool.</p>\n\n<p>I have used visual shader builders myself, and I like them, and one day, when shading is not as performance-critical as it is today, they might be the right tool for the job.</p>\n\n<p>..though my guess is that we'll see deferred lighting and probably full software rendering before that day comes ;)</p>\n"}, {'answer_id': 324733, 'author': 'Milan Nankov', 'author_id': 41482, 'author_profile': 'https://Stackoverflow.com/users/41482', 'pm_score': 2, 'selected': False, 'text': '<p>One of the best ways to get started with shaders is to read Introduction to 3D Game Programming with DirectX 9.0c a Shader Approach by Frank Luna. The author first introduces the DirectX and the HLSL and then gradualy reveals the power of shader. He starts with very simple shaders but by the end of the book you know how to create lighting, shadows, particle systems, etc. Great Book.</p>\n\n<p>OJ suggested that you read the ShaderX series, but the stuff there is not for beginners so it will not help you a lot when you are making your first steps.</p>\n\n<p>I\'ve also posted an article <a href="http://blog.nankov.com/2008/10/30/best-books-about-game-development/" rel="nofollow noreferrer">here</a> about the best books that will get you started with game development.</p>\n'}]
['https://Stackoverflow.com/questions/6926', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/91/']