What does shaders do?

Started by
3 comments, last by Shashwat 13 years, 6 months ago
What does shaders do in XNA?
Do they directly interact with the graphics hardware?

Can't we have shader code in XNA program itself?
Advertisement
Shaders are program like source codes. Once you load one of them you send it to your hardware. Your hardware compiles it and if you set it in your XNA, you show your hardware how to render your crated primitives( like triangles).

For example you can draw your triangle's pixels with your specified way, in order to create amazing effects. You can change pixel color, with your specified way.

(I dont use) In XNA shader is created with HLSL language, generally shader code is saved in FX files. I dont know but there must be another way of loading shader code( Because DX has ). I suggest you writing your code in FX files.

Rendering pipeline has detailed explanation of shaders, see "riemers.net".
Simply said, shaders are very specialized programs executed on the graphics card.

There are different types of shaders. As you may know, all images generated with today's graphics technology are built out of polygons - triangles actually. Your graphics card is fed the corner points (vertices) of those triangles in 3D coordinates and then takes care of bringing those triangles onto the screen.

A vertex shader is a small program that is run on each of the vertices before the polygons are drawn. The vertex shader can then adjust those 3D coordinates - for example, apply the camera's orientation and position to them so the polygons are drawn in different places depending on where the camera is placed in the scene.

A pixel shader is a small program that the graphics card runs to calculate the color of each pixel it draws. This program could, for example, calculate the angle of a light source relative to the pixel and light the pixel accordingly.

That at least is the simplified version. Armed with that knowledge, it shouldn't be hard to understand the Wikipedia articles on pixel shaders and vertex shaders now :)
Professional C++ and .NET developer trying to break into indie game development.
Follow my progress: http://blog.nuclex-games.com/ or Twitter - Topics: Ogre3D, Blender, game architecture tips & code snippets.
In the case of XNA, you write shaders in HLSL (a C-like programming language). Both pixel shader and vertex shader are packaged into a single unit called an "effect".

There's no direct interaction between XNA/.NET and the effect, except that you can tell the graphics card what effect you wish to use for each batch of polygons you draw. You can set variables in the effect prior to drawing - for example to tell the vertex/pixel shader where your camera is or what textures your pixel shader should use.

So, if that's your question, you can't write shaders in .NET or XNA.
Professional C++ and .NET developer trying to break into indie game development.
Follow my progress: http://blog.nuclex-games.com/ or Twitter - Topics: Ogre3D, Blender, game architecture tips & code snippets.
Understood clearly... Thanks...

This topic is closed to new replies.

Advertisement