PixelShift Studios Logo PixelShift Studios Contact Us
Contact Us

Understanding Vertex and Fragment Shaders

The two most fundamental shader types in graphics programming. We’ll cover how they work together to create visual effects.

12 min read Beginner May 2026
Marcus Thorne, GPU Programming Instructor

By Marcus Thorne

Senior GPU Programming Instructor & Technical Director

Close-up of shader code displayed on dark monitor with syntax highlighting and blue lighting

What Are Shaders?

If you’re starting out in graphics programming, you’ve probably heard the term “shader” thrown around. It’s one of those words that sounds more intimidating than it actually is. At its core, a shader is just a specialized program that runs on your GPU to calculate rendering effects. Think of it like a recipe — you give it some ingredients (like vertex positions or texture data) and it produces a result (a pixel’s color on screen).

Two shaders form the backbone of nearly every graphics pipeline you’ll encounter: the vertex shader and the fragment shader. They work together like a team — one handles positioning and transformations, the other handles colors and final appearance. Understanding how they collaborate is absolutely essential if you want to create anything beyond basic 3D graphics.

The GPU Pipeline Basics

Your GPU processes geometry in stages. Vertex shaders run first, transforming individual vertices. Fragment shaders run second, determining the color of each pixel. This two-stage approach has been the standard for over 20 years.

The Vertex Shader Explained

The vertex shader is where transformation happens. Every single vertex in your 3D model gets processed by this shader. A typical 3D model might have thousands or even millions of vertices, and each one runs through your vertex shader independently.

Here’s what’s really important: the vertex shader doesn’t know anything about what your final image will look like. It’s not calculating colors yet. Instead, it’s doing mathematical transformations — moving vertices around, scaling them, rotating them. It takes world coordinates and transforms them into screen space. It can also calculate lighting per vertex, which is called Gouraud shading. You’ll often see vertex shaders handling normal transformations, bone animations for characters, and wind effects for vegetation.

Key Responsibility

Transform vertices from model space world space camera space screen space. That’s 4 coordinate system conversions happening in sequence.

The Fragment Shader in Action

After your vertex shader finishes, the rasterizer takes over. It’s a fixed-function part of the GPU that converts your transformed vertices into fragments — potential pixels on screen. Then your fragment shader runs once for every single fragment that needs to be drawn. On a 19201080 screen, that’s over 2 million fragment shader invocations per frame. You can see why optimization matters.

The fragment shader’s job is simple but critical: determine the final color of each pixel. It receives data from the vertex shader (interpolated across the triangle), and it has access to textures, lighting calculations, and more. This is where you implement all your fancy effects — normal mapping for surface detail, parallax mapping for depth, ambient occlusion for realism. Want dynamic shadows? Fragment shader. Want a heat haze effect? Fragment shader. The fragment shader is where your creativity really shines.

Vertex vs Fragment

Vertex shaders run once per vertex. Fragment shaders run once per pixel. For a mesh with 50,000 vertices on a 1080p screen, you’re looking at 50K vertex shader calls versus 2+ million fragment shader calls. This is why optimization techniques differ between the two.

How They Work Together

The real magic happens when you understand the relationship between these two shaders. The vertex shader outputs data — position, color, texture coordinates, normal vectors. The rasterizer then interpolates all this data across the triangle. When your fragment shader runs, it receives those interpolated values as inputs.

Let’s say you want to create a glowing effect. Your vertex shader could pass the object’s emission color to the fragment shader. The fragment shader then uses that color, combines it with texture lookups, applies some brightness calculations, and outputs the final glowing result. Neither shader could do this alone — they’re genuinely a team.

One common pattern is calculating lighting in different places. You might do simple ambient lighting in the vertex shader (fast, but less accurate) and reserve complex effects like parallax mapping for the fragment shader (slower, but beautiful). This balance between performance and visual quality is what game developers spend hours perfecting.

Practical Example: A Simple Textured Mesh

Here’s how these shaders typically work in a real scenario:

1

Vertex Shader Processes Input

Receives the vertex position and UV coordinates. Multiplies position by model-view-projection matrix. Outputs the transformed screen position and passes UV coordinates to the fragment shader.

2

Rasterizer Interpolates

Takes the triangle’s three transformed vertices. Creates fragments for every pixel the triangle covers. Smoothly interpolates UV coordinates across the triangle surface.

3

Fragment Shader Colors Pixels

Receives interpolated UV coordinates. Samples the texture at those coordinates. Applies any color adjustments or effects. Outputs the final pixel color to the framebuffer.

This article provides educational information about shader programming concepts. The examples and explanations are simplified for learning purposes. Actual shader performance and capabilities depend on your target GPU, graphics API (DirectX, OpenGL, Vulkan), and hardware specifications. Always refer to official documentation for your chosen graphics framework and test thoroughly on your target platforms.

Ready to Start Writing Shaders?

You’ve now got the foundational understanding of how vertex and fragment shaders work. The vertex shader transforms geometry, the fragment shader colors pixels, and the rasterizer brings them together. This partnership has been at the heart of real-time graphics for decades, and it’s not going anywhere.

The best way to truly understand shaders? Write them. Experiment with simple transformations in your vertex shader. Try different texture sampling techniques in your fragment shader. Break things intentionally — you’ll learn more from debugging a glitchy effect than reading theory alone. Start simple, build complexity gradually, and don’t be intimidated by the math. It’s just coordinates and colors.

Ready to explore more shader techniques?

Explore Dynamic Lighting Effects