Jump to content
  • Advertisement
Sign in to follow this  

Shaders and API

This topic is 3696 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 matrix
float4x4 matWorldViewProj : WORLDVIEWPROJECTION;

// Vertex Shader
float4 VS(float4 inPosition : POSITION) : POSITION {
return mul(inPosition, matWorldViewProj);

// Pixel Shader
float4 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.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!