GLSL essentials for the course
JSON describes resources and execution; GLSL computes vertices and pixels. Read a vertex main first, then its matching fragment main. This course uses GLSL ES 3.20 with #version 320 es.
Values and stages
float is scalar, vec2/3/4 are vectors, mat4 transforms a position, and uint preserves integer identifiers. Uniforms are supplied by bindings; in/out connects stages. flat keeps an identifier from being interpolated. A fullscreen vertex shader generates a quad from gl_VertexID; Terrain instead consumes the host’s public vertex attributes.
Read a pixel
sampler2D names a bound texture, texture samples normalized UV coordinates, and texelFetch reads an integer pixel without interpolation. mix(a,b,s) blends endpoints; clamp limits values. Start with the complete chapter 01 fragment shader:
#version 320 es
precision highp float;
uniform sampler2D u_sceneColor;
in vec2 v_uv;
layout(location = 0) out vec4 o_color;
void main() {
vec3 source = texture(u_sceneColor, v_uv).rgb;
const vec3 tint = vec3(1.04, 1.0, 0.92);
const float strength = 0.65;
vec3 contrast = (source - 0.5) * 1.08 + 0.5;
o_color = vec4(clamp(mix(source, contrast * tint, strength), 0.0, 1.0), 1.0);
}Compile and reason
Keep precision declarations in fragment shaders. Sampler names must match manifest symbols exactly. A Program combines vertex and fragment files; successful source analysis does not prove driver link success. Read errors from the first diagnostic, with filename and line, then force-reload the saved file. No online shader editor can reproduce the host’s bindings by itself.
For each line ask: which stage runs it, where does its input come from, what output location receives it, and is the value normalized color, encoded data or an integer? Chapter 04 relies on these distinctions.