Friday, August 23, 2013

Shaders in OpenGL

Hello All, (this is only for techie guys)
I have started delving into So called shaders in openGL. When I learned about it for the first time, I was overwhelmed and at the same time unsure about the use of it . Shaders are small program which takes care of drawing your scene pixel by pixel. Similar to the way we did it back when we were in college. Thought that was very primitive in 16 bit graphics. THis is more advanced but any way you get the point. So shaders are program which remove Fixed pipeline used by opengl to render and Instead gives us control to determine how to shade objects.

Though this seems ardent task , its really not that hard and we can get away with some simple shading pretty easily. Even you can simple download shader programs for fixed pipeline used by opengl and make your ammendments to it.

Anyway Back to topic. Clearly its useful to make use of shaders than relying on opengl fixed pipeline to draw your objects. So what do we do ? Learn it.

There are 2 types of shaders.
1. Vertex shader
2. Fragment shader.

vertex shader is called for every glVertex3f call that we make.
and fragment shader program is called for every pixel that opengl tries to render on the screen . Before we used to set color, texture , lighting properties and let the opengl interpolate and do the calculation of determining color for the individual pixel that its wants to render. But now that control is in our hand.

With this control we can play around with normals and make use of normal map more efficiently. This lets us render more complicated shapes with less complicated geometry. Isn't it cool feature.
Indeed it is. SO have fun. Search for more on this topic. Try some simple programs and make use of best of GPU computation.

Happy coding. Bye for now :-)

No comments:

Post a Comment