Okay, let’s get started. This series of blog articles will be following a simple format: I list what I’m going to be talking about today, then I explain it, lastly I give you an example in the format of a video game to further iron my idea in.
Since we started with shaders…
From this point on, we are talking about shaders.
The concept of “Shader” is sometimes blurry since it can do anything. However ultimately, it’s a computer program that’s doing any sort of post processing. We generally use shaders to apply Special Effects such like Lighting and Shadowing, change the hue and/or color of the rendering result, or change the position of a texture and many more.
As Shaders work with GPU, it’s not as simple as programming some few line of codes into C++ and tell it to run. Yes you can draw some cubes or even load a OBJ model in this way, but we’re still talking through CPU. Actually, OpenGL provided a way to program the GPU by using GLSL which features C-like code, enabling the programming of shaders in OpenGL.
There are three kinds of shaders that we may be encountering in this time period:
- Vertex Shaders – This shader transforms each vertex’s 3D Position to the 2D Viewport as seen on the screen. This shader can manipulate the position, color and the texture coordinates. But cannot create something new. The result of the processed data from this shader goes to a Fragment Shader or a Geometry Shader for future access.
- Fragment Shader – This Shader calculates and manipulate color and other attributes for each pixel. This is the shader that will mainly used to change the color of the fragment, giving the finished render all kinds of effects such like lighting. It’s the same as applying a filter with a photo (or in Photoshop, for that matter.)
- Geometry Shader – A Geometry Shader would be used to generate new vertices (which Vertex shader cannot do), It can generate points, lines and triangles, allowing more things to be added on the rendering process.
According to Wikipedia (as I’m doing my research), there is actually a 4th kind of shader called Tessellation Shader, but I don’t know if we’ll get to that in this time period.
Recently, a game called “Dream” has been Greenlit on Steam and is an Early-Access Title. I got my copy from a friend and after playing a while, I think this single pic can sum up the importance of the shaders.
Fun Fact: The word “Shader” is written in Chinese as “着色器” which literally means “Coloring Machine”.
Now, until next week…