home/ modules/ orient-shaders-as-pixel-functions

Orientation: the fragment shader as a per-pixel color function

  • learner can explain that a fragment shader runs in parallel and maps each pixel coordinate to an RGB color
  • learner can normalize gl_FragCoord to UV space and visualize the coordinate field as a gradient
  • learner can locate the Book of Shaders standard-uniform conventions (u_resolution/u_mouse/u_time) as a reference anchor

Write your first Book-of-Shaders GLSL fragment shader that fills the canvas with a UV-as-RGB gradient driven by u_resolution, and annotate it explaining the per-pixel parallel model.

In a live-visuals rig — Hydra, a Shadertoy tab, or a GLSL layer behind your TidalCycles set — everything you will ever project starts from one idea: the fragment shader is a tiny pure function that the GPU calls once per pixel, millions of times per frame, in parallel. This module builds toward writing that first shader yourself: a canvas-filling gradient where the coordinate field itself becomes the image, annotated in your own words so the mental model sticks before any club-ready patching begins.

The arc is deliberately gentle. Start in the Book of Shaders live editor with its default template already running, and lean on two just-in-time how-tos: “Dividing gl_FragCoord by u_resolution maps pixel coordinates to the [0,1] UV range” gives you the one line that opens nearly every shader you will ever write, and “Mapping UV coordinates directly to RGB channels visualizes the coordinate space as a gradient” turns that abstract space into something you can see and debug. From there, strip the template and rebuild it blank-page for the capstone, pulling the standard-uniform conventions (u_resolution, u_mouse, u_time) from the fact atom rather than from memory.

The required atoms gate the capstone directly: you cannot write the gradient without normalization and the UV-to-RGB mapping, cannot wire it without the standard uniforms, and cannot honestly annotate the parallel model without the pixel-color-function and massively-parallel concepts. The supporting atoms enrich the picture without gating the work: the free PBR textbook is worth bookmarking as a long-term theory anchor, and triangles-as-the-only-GPU-primitive foreshadows what the GPU is actually rasterizing in the vertex-buffer world ahead — but nothing in the capstone depends on either yet.

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

A GLSL fragment shader is a function that maps each pixel's (x,y) coordinate to an output RGB color, run in parallel for every pixel
Concept L1 Foundations G
Dividing gl_FragCoord by u_resolution maps pixel coordinates to the [0,1] UV range
Procedure L1 Foundations G
Mapping UV coordinates directly to RGB channels visualizes the coordinate space as a gradient
Concept L1 Foundations G
GPU shaders run massively in parallel — individual invocations cannot communicate with or observe each other within a pass
Concept L1 Foundations G
The Book of Shaders defines three standard uniforms: u_resolution, u_mouse, and u_time
Fact L1 Foundations G

Supporting — enrichment, not gating

Physically Based Rendering is a free CC-licensed textbook coupling rendering theory with a full implementation
Fact L0 Orientation G
GPUs work exclusively with triangles, lines, and points — all geometry must be decomposed into triangles before drawing
Concept L1 Foundations G