CodeBlanks Logo Icon CodeBlanks

What is a Shader?

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

Player.cs
using UnityEngine;

public class ShaderInfo : MonoBehaviour
{
    // Start metodunu tanimla ve log yazdir
}

Sample solution

Player.cs
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

Question
Shader shader = Shader.____("Standard");
Answer
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

All lessons in Advanced