Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Beginning Shader Development [closed]

Tags:

shader

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 nVidia's FX Composer is a great tool to develop shaders, but I did not find much useful and updated content on how to actually get started.

What tutorials would you recommend?

like image 419
Michael Stum Avatar asked Aug 09 '08 21:08

Michael Stum


People also ask

What are two types of shaders?

There are three types of shaders in common use (pixel, vertex, and geometry shaders), with several more recently added.

What is a GPU shader?

A shader is a piece of code that is executed on the Graphics Processing Unit (GPU), usually found on a graphics card, to manipulate an image before it is drawn to the screen. Shaders allow for various kinds of rendering effect, ranging from adding an X-Ray view to adding cartoony outlines to rendering output.

Why are shaders called shaders?

Likely because the classic lighting algorithms are named things like "Blinn shading", "Phong shading", "Gourand shading", etc. That's right. And RenderMan had a "shading language" to implement those kinds of shading (and more). And then functions written in a shading language became known as "shaders".

What is shader programming?

A shader is simply a program that runs in the graphics pipeline and tells the computer how to render each pixel. These programs are called shaders because they're often used to control lighting and shading effects, but there's no reason they can't handle other special effects.


2 Answers

Development of shaders in XNA (which obviously uses DirectX) requires knowledge of HLSL or shader assembly. I'd recommend getting familiar with the former before diving into the latter.

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.

Next make an attempt to write your own HLSL which does what the Fixed T&L 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.

As a next step you might want to simulate basic sepcular lighting 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.

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 bump or normal maps.

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 more than it was originally intended.

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 here and here.

Don't forget that there's an excellent series of books called ShaderX which covers some awesome shader stuff. There's 1, 2, 3, 4, 5 and 6 already in print, and 7 is coming soon.

Good luck. If you get some shaders going, I'd love to see them :)

like image 153
OJ. Avatar answered Oct 11 '22 00:10

OJ.


I'd just like to reiterate how great the GPU Gems books are - a truly fantastic resource for any serious graphics development.

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.

When I was beginning learning, a good exercise is to actually implement the entire T&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.

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.

like image 38
Ali Parr Avatar answered Oct 10 '22 22:10

Ali Parr