Thursday, 17 January 2013

Introduction to Intermediate Computer Graphics and OpenGL

Hello, my name is Wesley Chartrand and I am a second year Game Development and Entrepreneurship student at UOIT. Here in Game Dev. we study a variety of different fields in computer graphics and the business world. In this blog, I will be focusing primary on my intermediate computer graphics class that focuses primarily on utilizing the power of OpenGL and shaders. I will also be demonstrating different programs I created throughout the program, as well as some videos from professionally made video games for your enjoyment and education. Let's get started.

Before I dive straight into talking about video games, fancy graphics, awesome particles, and more, I will first be talking about the foundation of in which many video games are programmed: OpenGL and shaders. Once we have a basic understanding of exactly what both accomplish we can understand how it is used to make video games look and feel awesome!

What is OpenGL?

OpenGL (Open Graphics Library) is a cross-language, multi-platform API used to render 2D and 3D graphics. What makes OpenGL so great is that it taps into the GPU to achieve high render speeds. With OpenGL we can create a 3D environment in which programmers can display whatever they wish to the viewer. In order to use OpenGL though, we use API like GLUT, GLEW, and SFML in order to effectively utilize the libraries in OpenGL
An example scene I programmed. Note: there is no lighting yet
As seen above, OpenGL can be used to create a scene, draw objects at specified x,y,z coordinates, add color, and more. All of these are rendered quickly and efficiently through the GPU. Below is an example of a particle system I developed.



These are just simple examples of some really easy programs that can be created with OpenGL. Many popular games have been created using this tool such as Half-Life, Minecraft, the Quake Series, Doom 3, and more. These are just a few examples of the power of the OpenGL tool. Utilizing shaders helps brings games to life.

What are Shaders?

Shaders, in computer graphics, are programs that run off of the GPU in order to do specialty tasks such as lighting, special affects, or post-processing. While most shaders calculate different levels of light or dark, there are numerous algorithms available or waiting to be discovered that allow for programmers to do all sorts of neat tricks. Some examples of where shading algorithms are useful: hue, saturation, brightness, contrast, blur, bloom, bump mapping, displacement mapping, and many more.

Overview of Shaders

Shaders are simple programs that describe the components of either a pixel or vertex. By describing their components, we can achieve many different goals. Two major different shaders we use are pixel shaders, also known as fragment shaders, and vertex shaders.

Pixel shaders compute things like color, z-depth, and alpha values of a pixel. Fragment shaders can do many things like bump mapping, applying light values, shadows, specular highlights, and other things. However, Fragment shaders have their limitations. They are restricted in how many effects they can do because it operates on a single fragment, and not necessarily the scenes entire geometry. Although, fragment shaders do know the screen coordinates that are being drawn, and can sample the screen and nearby pixels if the contents of the entire screen are passed as a texture to the shader. This technique allows for many two-dimensional post-processing effects, such as blur and cel-shading for cartoonists.

Phong Shading is often implemented using pixel or fragment shaders
Vertex shaders commonly describe position, color, texture co-ordinates, etc., of a vertex. Vertex shaders are called for each vertex in a primitive. Every vertex is then rendered out as a series of pixels that is transferred to the screen. It is important to note that vertex shaders influence currently drawn vertex's, they do not create new ones. Vertex shaders are a powerful tool for controlling position, lighting, color, and more.

The below images were provided by our Interactive Computer Graphics tutorial


Using a shader to create lighting
No lighting.









As of yet, we have learned about pixel shaders, also known as fragment shaders, and vertex shaders.

Alright so we know that shaders exist and they can do fancy things. Why is this so important?

The more games evolve, the better looking they get, the better they run, the more realistic effects we produce, and most importantly, the games simply get better. By utilizing these tools, we can achieve great levels of quality, detail, and speed.

Later in the year, I will be explaining more in depth of how these shaders work, and some sample programs of how they work. I hope you enjoyed this introduction, leave any comments you wish below! Thanks!




No comments:

Post a Comment