Shaders and API

Started by
1 comment, last by Googol PL3X 15 years, 5 months ago
What are shaders and whats the diff between shader and API programming??? Any help will be appreciated.
Advertisement
Here is 2 places you can look:
wikipedia - shaders
wikipedia - API
Those links basically describe everything you are asking in technical terms, but basically a shader alows you to manipulate verticies in the vertex shader, geometry in the geometry shader and pixels in the pixel shader. The name shader is more of an abstraction as it doesn't nesiccarily shade anything, it is all programmer defined.

What's the difference between shader and API programming? HLSL (and is't OpenGL equivelent, GLSL) are languages of their own, Higher Level Shading language, here's why it's called that. Firstly, shaders prior to DirectX8 (in the direct3d chain at least) were written in assembly, not something that was fun or easy to do. So the term Higher level refers to the fact it is a higher level language and no loner assembly. Shader Lanauge, it is just that, it's a language all on it's own with additional and differnet syntax to other languages, it's most similar to C syntax although has C++ features and a few things like semantics added to the list.

What does a piece of HLSL code look like? Here's a basic Vertex shader:

// Global world-view-projection matrixfloat4x4 matWorldViewProj : WORLDVIEWPROJECTION; // Vertex Shaderfloat4 VS(float4 inPosition : POSITION) : POSITION {    return mul(inPosition, matWorldViewProj);} // Pixel Shaderfloat4 PS() : COLOR {    return float4(1, 1, 1, 1);} technique TSM1 {    pass P0 {        VertexShader = compile vs_1_1 VS();        PixelShader  = compile ps_1_1 PS();    }}


What does it do? outputs white verticies, I won't explain syntax etc, but as you can see, it's definately a language on it's own. As I have mentioned, there are three shaders, in DirectX, the geometry shader is only available in Direct3D10 and 10.1. The vertex and pixel shaders are avaliable to Direct3D8 up till 10.1 (current version). One thing to remeber about shaders is that the vertex shader's output provides the input for the pixel shader (similarly to the Geometry shader). hope that clarified something for you, so in basic, shaders allow you to manipulate single verticies (in the vertex shader), large piceies of geometry (geometry shader) and individual pixels (in the pixel shader) to add cool, interesting and often very realistic effects from HDR and procedural light shafts to motion blur and local deformation.

This topic is closed to new replies.

Advertisement