GLSL Fundamentals

Understanding UV Coordinates in GLSL

Learn how shaders understand screen space, positioning, distortion, procedural animation, and coordinate-driven visual effects.

Beginner GLSL Core Concept 12 min read

Introduction

UV coordinates are one of the most important concepts in shader programming.

Almost every GLSL shader relies on UV coordinates for positioning, animation, textures, distortion, procedural patterns, and screen-space effects.

The Big Idea

If you understand UV coordinates well, shader programming becomes dramatically easier.

Once the concept clicks, you begin to see how shaders build entire visual worlds mathematically.

What Are UV Coordinates?

UV coordinates are normalized coordinate values used to describe positions across a surface or screen.

Instead of using pixel positions like 1920 × 1080, UV coordinates typically range from 0.0 → 1.0.

Why This Matters

UV coordinates create a resolution-independent coordinate system, allowing shaders to behave consistently across different screen sizes.

UV Gradient Demo

Shader Preview Unavailable

This realtime shader may be too intensive for your current device or browser.

Why Are They Called “UV”?

In graphics programming, X and Y are often used for geometry positions, so texture and surface coordinates traditionally use U and V.

U Axis

The horizontal direction across the screen or surface.

V Axis

The vertical direction across the screen or surface.

Basic UV Setup

One of the most common lines in GLSL converts pixel coordinates into normalized UV space.

vec2 uv = fragCoord.xy / iResolution.xy;
Breaking It Down

fragCoord represents the current pixel position, while iResolution represents the screen size. Dividing the two converts pixel coordinates into values ranging from 0.0 to 1.0.

After normalization:

  • left edge = 0.0
  • right edge = 1.0
  • bottom = 0.0
  • top = 1.0

Visualizing UV Space

Imagine the screen as a coordinate grid.

Bottom Left

(0.0, 0.0)

Center

(0.5, 0.5)

Top Right

(1.0, 1.0)

UV Coordinate Space

Shader Preview Unavailable

This realtime shader may be too intensive for your current device or browser.

UV space allows shaders to work consistently regardless of screen resolution.

Simple UV Gradient Example

Here is one of the most common beginner shaders.

void mainImage(out vec4 fragColor, in vec2 fragCoord)
{
    vec2 uv = fragCoord.xy / iResolution.xy;

    fragColor = vec4(uv.x, uv.y, 0.5, 1.0);
}

This creates:

  • red increasing horizontally
  • green increasing vertically
  • blue remaining constant

The result is a smooth screen-space gradient.

Gradient Shader

Shader Preview Unavailable

This realtime shader may be too intensive for your current device or browser.

Centering UV Coordinates

Many shaders work better when UV space is centered around zero.

vec2 uv = fragCoord.xy / iResolution.xy;
uv = uv * 2.0 - 1.0;

Now:

  • center = (0,0)
  • left = -1
  • right = +1
  • bottom = -1
  • top = +1
Why Center UVs?

Centered UV coordinates make symmetry, rotation, distance calculations, radial effects, and procedural animation much easier.

Aspect Ratio Correction

Without correction, circles and radial effects may appear stretched on widescreen displays.

uv.x *= iResolution.x / iResolution.y;

This compensates for non-square screen dimensions.

Aspect Ratio Comparison

Shader Preview Unavailable

This realtime shader may be too intensive for your current device or browser.

UV Coordinates and Textures

UV coordinates are heavily used for texture sampling.

vec3 col = texture(iChannel0, uv).rgb;

The texture is sampled using UV coordinates, allowing images, video, feedback buffers, noise textures, and procedural textures to map across the screen.

UV Distortion

One of the most powerful shader techniques is UV distortion.

Instead of sampling textures normally, you modify the UV coordinates first.

uv.y += sin(uv.x * 10.0 + iTime) * 0.05;

This creates waves, ripples, liquid motion, and psychedelic distortion.

UV Distortion Demo

Shader Preview Unavailable

This realtime shader may be too intensive for your current device or browser.

Repeating Patterns With UVs

Using functions like fract(), mod(), and floor(), you can tile patterns infinitely.

vec2 gv = fract(uv * 10.0);

This divides UV space into repeating cells.

Common Uses

Repeating UV patterns are commonly used in grids, procedural textures, sci-fi interfaces, and generative art systems.

Polar Coordinates

UV coordinates can also be converted into angle and distance.

float angle = atan(uv.y, uv.x);
float dist = length(uv);

This enables spirals, tunnels, radial patterns, kaleidoscopes, vortex effects, and many procedural visual systems.

Polar Coordinate Demo

Shader Preview Unavailable

This realtime shader may be too intensive for your current device or browser.

Animation Using UVs

UV coordinates become especially powerful when combined with time.

uv.x += iTime * 0.2;

This scrolls the UVs horizontally.

Techniques like this are used for flowing textures, moving backgrounds, tunnels, starfields, and procedural motion.

Scrolling UV Animation

Shader Preview Unavailable

This realtime shader may be too intensive for your current device or browser.

UV Coordinates in Audio Reactive Shaders

Audio reactive shaders often distort UV coordinates using music data.

float bass = texture(syn_Spectrum, 0.05).g;

uv += sin(uv.yx * 8.0 + iTime) * bass * 0.05;

This causes the screen to pulse and distort with bass frequencies.

Audio Reactive UV Distortion

Shader Preview Unavailable

This realtime shader may be too intensive for your current device or browser.

Why UV Coordinates Matter So Much

UV coordinates are the foundation of screen-space rendering, procedural graphics, texture mapping, distortion, raymarching, post-processing, and generative animation.

The Foundation of GLSL

UV coordinates are essentially the canvas coordinates of shader programming. Understanding them deeply unlocks a huge portion of GLSL.

Common Beginner Mistakes

No Aspect Ratio Correction

Without correction, circles and radial effects may appear stretched.

Confusing Coordinate Spaces

Pixel coordinates are resolution-dependent, while UV coordinates are normalized.

Overdistorting UVs

Large UV distortion can tear textures, create artifacts, or destabilize visuals.

Final Thoughts

Nearly every shader begins with UV coordinates.

They define where things appear, how textures map, how effects distort, and how visuals animate across the screen.

  • UVs create resolution-independent coordinate space.
  • Centered UVs simplify many procedural effects.
  • UV distortion powers many advanced shader techniques.
  • UVs are fundamental to textures, motion, and procedural animation.
  • Shader programming often becomes coordinate-space manipulation.

Over time, you begin to think of shaders less as drawing pixels and more as manipulating coordinate space itself.

And that’s where shader programming becomes truly powerful.

Continue Learning

Fragment Shaders

Learn how shaders calculate the color of every pixel on the screen.

Read Tutorial

Noise Functions

Create procedural motion, flowing textures, clouds, terrain, and organic distortion.

Explore

Audio Reactive GLSL

Connect music, motion, FFT analysis, and realtime visual systems.

Continue
Scroll to top