What is a Shader?

Game Design

What is a Shader?

 In game design, day by day I am making the topics a bit more advanced and trying to share with you what I know or learn about game design, and for the past month or two, or rather since I started the final for the game project course in the first semester of my sophomore year at university, I started dealing with these "shaders", that is "gölgelendiriciler", and today I will try to answer questions like what is a shader (gölgelendirici). It might be a bit of a long article, so I'll warn you in advance.

What is a Pixel? Vertex?

Now, below when I explain what a shader is, there are 2 units I will use: pixel and vertex. First, I want to explain what these are, because later when reading you might otherwise say "what is he talking about?" Though if you are at the level to search for this article on the internet, you probably know or at least have an idea of what a pixel and vertex are—at least what a pixel is.

What is a Pixel?

A pixel is the smallest unit that allows and can be controlled to obtain a digital image.

What is a pixel?

I can say that every color in the visual above represents a pixel.

What is a Vertex?

A vertex is a data structure that represents a point in a 2D or 3D space.

Blender Vertex

The corner points of the square you see in the visual above each represent a vertex.


What is a Shader?

A shader is a program that entered our lives with the arrival of programmable graphics cards (GPUs) and that we write to control vertices and pixels on the graphics card as we wish.

Now, defining a shader this way is quite confusing, but let me try to explain it in a little more open manner.

What we call a shader are programs/applications we write for graphics cards. These applications help us create various beautiful effects and textures in games, and also help us create fluid materials such as sea and lava in games. In addition, they are used in many areas such as how light falling on an object will create shading on the object and color adjustments.

I'm leaving a simple shader tutorial from Unity here; seeing how water is made with shader in Unity will help you better understand what a shader is.




Render Pipeline / Graphics Pipeline

One subject leads to another, but to grasp shaders in fact, you need to know a little about all of these.

The so-called Render Pipeline or Graphics Pipeline in English, which is translated as Output Pipeline or Graphics Pipeline in Turkish, is a model that defines the steps performed to convert a 3D image/screen to a 2D screen/plane.

Frankly, I can't say I know much about the functioning of the Render Pipeline, but I do know that when I use the Standard Render Pipeline in Unity, a shader I wrote for URP (Universal Render Pipeline) does not work.

Let me immediately post an example Pipeline here.


Vulkan RP

Shader Types

Pixel (Fragment) Shader (2D)

This type of shader is used to hold and process properties of incoming pixels such as color, transparency (alpha), depth (z-depth).
Since it holds and controls the data of a single pixel, it doesn't really allow you to create very large visual effects.
In the visual below, the second image from the top in the center can be given as an example of areas affected by the pixel shader.


Vertex Shader (3D)

Vertex Shader, unlike pixel shader, is used to hold and arrange the vertices used by the Render Pipeline. Vertex position, color...
Many things in games, such as seas and the movement of grass, are done with Vertex Shader.
In the image above, the top 3 points in the center section can be shown as examples of areas affected by the vertex shader.

How to Write a Shader?

If you remember, what we call shaders are programs written for programmable graphic cards. Of course, to write these programs, you need a few main things. Actually, let’s not say we need them, but our writing style changes according to where you use them.
To write shaders, we use Graphics APIs, i.e. ready-made graphics libraries.
With the standard code scripts in the graphics library, just like writing normal code (of course, you must stick to the graphics library's syntax here!), you can write shaders.

To write shaders 
  • GLSL : Based on C, supports OpenGL and has cross-platform support.
  • HLSL : Based on Directx and works only in Windows environments.
  • CG : Developed by Nvidia, it is considered the same as HLSL but has cross-platform support.

You need to know such languages. In addition to these, you can also write shader programs on Unity without writing any code by using Shader Graph with URP.

Graphics Libraries (Graphics APIs)
  • Direct3D (DirectX)
  • Glide
  • Mantle (AMD)
  • Metal (Apple)
  • OpenGL
  • OpenGL ES
  • Vulkan
There are also many other graphics libraries..


Shader Examples


Dissolve Shader

Grass Shader