User profile picture

What are shaders?

Shaders are programs that run on your GPU instead of your CPU. While your CPU handles logic and game state one instruction at a time, your GPU runs thousands of shader programs in parallel—one for every pixel, vertex, or compute thread.

There are three main types:

Vertex shaders transform 3D coordinates. They take your mesh data (vertices, normals, UVs) and project them onto the 2D screen. This is where models get positioned, animated, and perspective-corrected before rasterization.

Fragment shaders (or pixel shaders) decide the final color of each pixel. They run after the geometry is rasterized into fragments, calculating lighting, textures, shadows, and effects. This is where the visual magic happens—glossy reflections, cel shading, glow effects, all live here.

Compute shaders (newer) run arbitrary computations on GPU data without rendering anything. They’re used for particle physics, image processing, or machine learning—anything that needs massive parallel number crunching.

Shaders are written in specialized languages: GLSL for OpenGL/WebGL, HLSL for DirectX, WGSL for WebGPU. They look like C but with restrictions—no recursion, limited memory access patterns, designed for parallel execution.

The power of shaders is their parallelism. A fragment shader doesn’t know about neighboring pixels; each one runs independently. This lets GPUs execute millions of them simultaneously, turning simple math into stunning visuals at 60+ frames per second.

Tags:

# graphics

# game development

# fundamentals