Saturday 8 December 2012

Shaders in C++

So after a while of not doing much I decided to tackle some shaders in C++, this is to say in GLSL (OpenGL's native Shading Language). The idea was to get some knowledge before going into my third year at university as I will have a module called Advanced Games Programming and in it we would be creating programs with the use of GLSL. So why not get a head start now?

I started off following Swiftless's Tutorials "http://www.swiftless.com/glsltuts.html" , Doing the standard Gouraud shading, then went on to change it into per pixel lighting also known as Phong. Demonstrated in the image below




You can see that Gouraud gives you a bit more of a blocky lighting compared to Phong, this is because Gouraud is done within the vertex shader which deals with the vertices, as the name suggest, and Phong is done within the fragment shader, fragments are possible pixels, so you can see why Phong is sometimes refered to "Per-Pixel lighting".


Adding materials was quite simple aswell, I had to declare a struct for it in the main of my program that took the ambient diffuse specular and shininess values. this allowed me to change the look of the model to a rough material to a very smooth shiny material





I later went on to explore adding textures to the model using shaders, this proved quite easy as all I had to do was declare a Uniform texture2D variable and call in the texture coordinates from the model through the vertex and fragment shaders and setting the texture to equal the incoming texture coordinates. Jobs an easy one.


I also attempted Bump mapping but that Didn't turn out so well.


I am writting this months on and I actually have done the Advanced Games Programming module and I will go on in later blogs to talk about that.