Thursday, 31 January 2013

Shaders!!!


What are Shaders?

Small pieces of code executed by graphics hardware.




Types of Shaders
  • Vertex Shaders
  • Pixel/Fragment Shaders

Vertex Shaders

Vertex Shaders process a stream of vertices one at a time. This means that other vertices will not be affected by the shader in the graphics pipeline. There are defined by characteristics such as textures, normals, and positions. 
Vertex in and Vertex out
Here is an example of a vertex shader adding in a single vertex.

1
2
in  int   gl_VertexID;
in  int   gl_InstanceID;


Here is an example of a vertex shader outputting the vertex.

1
2
3
4
5
out gl_PerVertex {
    vec4  gl_Position;
    float gl_PointSize;
    float gl_ClipDistance[];
};

This code was taken from the website http://www.lighthouse3d.com/tutorials/glsl-core-tutorial/vertex-shader/



Examples of Vertex Shaders:

  • Model Skinning
  • Morphing
  • Particle Systems
  • Displacement Mapping


Pixel/Fragment Shaders

Pixel or sometimes referred to as Fragment shaders process a parallel stream of pixels. This means one pixel is processed at a time and their is no accessibility between pixels.

Data In Colour Out






Examples of Fragment Shaders:

  • Bump Mapping
  • Per-pixel lighting


No comments:

Post a Comment