GLSL fundamentals: coordinates, vectors, and color output
Learning objectives
- learner can use swizzling, component aliases, and correct float literals to manipulate GLSL vectors
- learner can correct aspect ratio and normalize to clip space so shaders are resolution-independent
- learner can pass CPU uniforms to the GPU and manage clamped color output channels
- learner can use length() to build distance-from-origin radial gradients
Capstone — one whole task that evidences the objectives
Build a resolution-independent GLSL sketch that draws an aspect-corrected, clip-space-centered radial gradient wheel with length()-based falloff, using uniforms, swizzles, and clamped color output.
Prerequisite modules
When you project shaders behind a live set — a Hydra patch, a Shadertoy port, a custom fragment stage in your VJ rig — the venue decides your resolution. A sketch that looks right on your 16:9 laptop will smear into ellipses on a square LED wall unless coordinates are handled correctly from line one. This module builds that reflex: a small toolkit of vector, coordinate, and color moves that every later shader module assumes.
The arc starts supported. First, manipulate vectors in a working scaffold: component aliases (.xyzw / .rgba are the same storage), swizzling to reorder channels in one expression, and the strict-typing gotcha that every float literal needs a decimal point — the single most common compile error for anyone arriving from JavaScript. Next, take over the opening lines of the shader yourself: normalize pixel coordinates to [0,1], recenter to clip space [-1,1], and apply the one-line aspect-ratio correction so circles stay circular. Then wire the CPU side: declare uniforms for resolution and time, and learn why colors saturate — every output channel clamps to [0,1], so anything unnormalized flattens to white. Finally, put the corrected coordinates to work: length(uv) gives each pixel its distance from center, the seed of every radial gradient and circular shape.
The capstone removes the scaffold: from a blank file, draw a radial gradient wheel that stays centered and round at any canvas size. Every required atom gates it — the wheel’s falloff is literally length()‘s distance-from-origin value, its roundness is the aspect correction, its portability is the uniform-fed normalization, and its smooth ramp depends on respecting channel clamping. Supporting atoms enrich rather than gate: the Shadertoy-flavored take on normalized camera coordinates (the same clip-space move seen from a second angle), the vertex/fragment pipeline picture, function argument qualifiers, the pow()-of-negative trap, and mix()-based color blending all deepen the toolkit but the wheel ships without them. Drill the normalization one-liner, float literals, and swizzles until they are automatic — they open virtually every shader you will ever write live.
Runnable examples
Generated from the context/ instrument corpus by concept (redistributable idioms only). Do not edit — regenerate with gen-module-examples.mjs.
gradient-ramp
gradient(0.3).out()
hydra-0170 · MIT
[fr, fr*0.5, 1-fr] >> rgb
punctual-0033 · CC0-1.0
Atoms in this module
Required — these gate the capstone
Supporting — enrichment, not gating
Part of curricula
- Generative & AI AV Artist — real-time machine-driven performance — Orient the machine collaborator & ship a first ML AV artefact recommended
- Live Visualist — zero to performing live-coded & generative visuals — Reactive & procedural — make it listen, and go to the GPU required
- Shader Artist — real-time GPU craft to a demoscene-grade visual — The fragment shader as a per-pixel instrument required
Unlocks — modules that require this one