Sign in to follow this  
Shashwat

What does shaders do?

Recommended Posts

onozkan    100
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".

Share this post


Link to post
Share on other sites
Cygon    1219
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 :)

Share this post


Link to post
Share on other sites
Cygon    1219
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this