Shader Programming

Started by
1 comment, last by brekehan 14 years, 11 months ago
Hi, I've taken an interest in shader programming to make effects to use in XNA. Shader programming, or more specifically, HLSL is not something with which I'm familiar. I'm an experienced coder and I'm familiar with the maths of 3D lighting/shading etc. so I don't need help in that area. I've looked at a few .fx files and tutorials in an attempt to figure out how to create my own. However, I'm finding the tutorials a little vague and they generally seem to give how to's in specific shaders. They don't tell me how the return values of pixel shaders are used in the final rendering. For example, I'd like to create a shader that could do some glow effects. I'd like to write one of my own instead of downloading it, if only as an educational exercise. Taking this example, what should the output of a pixel shader return? Since I don't know how the return value of a pixel shader i used, it's tricky to figure out exactly what should return. I'd be grateful if somebody could point me in the direction of some docs that would help me with what i've discussed. I'm planning to use something like NVidias FX Composer to produce shaders, but I would still like to understand what I'm doing. Thank you for your time.
Advertisement
I always thought that the Cg Tutorial was a good reference. Since its available online for free now, take a minute to check it out. It actually talks about what the shaders are supposed to do from a structural standpoint which is what I think you are looking for.

To answer your question, the pixel shader outputs a color. If the pixel passes the depth/stencil tests, then its value is sent to the alpha blending stage to be added to a render target (depending on the blending state of course).

You could also check out the dxsdk for a general pipeline description too.
The whole process is spread out throughout the MSDN docs.
You are looking for the Pipeline stages, which contain a not so clear explanation.

My understanding is:
vertex shaders take in anything you give it from your vertex buffers
vertex shaders spit out anything you like, but it has to at least contain a position ( SV_POSITION )

pixel shaders take in anything you like, which is the output from your vertex shader. Those in values are automatically interpolated for a pixel somewhere in the current primitive being rendered, unless you explicitly mark them to not get interpolated.
pixel shaders must spit out, a final pixel color (SV_Target)

I have no idea about geometry shaders, because despite 6 attempts, I've never got one working.

Someone can feel free to correct me. This is just my understanding of it.

This topic is closed to new replies.

Advertisement