What is a Shader?
- Game Development course
- Advanced
- Lesson 1/71
- 4 min
Learn that a Shader tells the GPU how to draw a surface.
What is a Shader?
A Shader is a program that dictates how the surface of a 3D model is rendered on screen and what colors its pixels will have. It executes tasks in parallel on the graphics processing unit (GPU) with thousands of cores instead of the central processing unit (CPU).
Shader "Custom/MyFirstShader"
{
// Code structure to run on the GPU
}Light reflections, shadows, water ripples, and visual effects are all governed by shader code.
The Graphics Pipeline and Materials
The process of converting 3D model geometry into screen pixels is called the Render Pipeline. In Unity, shaders are not attached directly to objects; they are assigned to a Material, which holds parameter values.
// Shader is assigned to material, material to object
Shader shader = Shader.Find("Standard");Thanks to this separation, the same shader code can be shared by hundreds of materials with different colors and textures.
Practice Shader execution environment
Define a Start method. Inside, make a Debug.Log call printing "Shader GPU uzerinde calisir" to the console.
Starter code
using UnityEngine;
public class ShaderInfo : MonoBehaviour
{
// Start metodunu tanimla ve log yazdir
}Sample solution
using UnityEngine;
public class ShaderInfo : MonoBehaviour
{
void Start()
{
Debug.Log("Shader GPU uzerinde calisir");
}
}Expected output
Shader GPU uzerinde calisir
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 On which hardware component of the computer do shader programs run in parallel?
- CPU (Central Processing Unit)
- GPU (Graphics Processing Unit) Correct answer
- Hard Disk (Storage)
- RAM (Memory)
Explanation: Shaders execute in parallel on the GPU (Graphics Processing Unit) to handle massive vertex and pixel data simultaneously.
2 Shader lookup method
Shader shader = Shader.____("Standard");
Shader shader = Shader.Find("Standard");
Explanation: The Shader.Find method is used in Unity to obtain a shader reference by name.
3 Fundamental shader concepts
| Term | Meaning |
|---|---|
Shader |
Render program running on the GPU |
GPU |
Parallel graphics computing hardware |
Render Pipeline |
Pipeline from geometry to pixels |
Material |
Asset storing shader parameters |