Appendices
Cheat sheet, keywords, built-in function quick reference, math reference for graphics, learning resources and suggested study plan (12 weeks).
Appendices
41.1 Cheat sheet attribute const uniform varying buffer shared coherent volatile restrict readonly writeonly atomic_uint layout centroid flat smooth noperspective patch sample break continue do for while switch case default if else subroutine in out inout float double int void bool true false invariant precise discard return mat2 mat3 mat4 dmat2..4 matCxR vec2 vec3 vec4 ivec2..4 bvec2..4 dvec2..4 uint uvec2..4 lowp mediump highp precision sampler* isampler* usampler* image* iimage* uimage* struct
Reserved for future use (don't use as names): common partition active asm class union enum typedef template this resource goto inline noinline public static extern external interface long short half fixed unsigned superp input output hvec2..4 fvec2..4 sampler3DRect filter sizeof cast namespace using.
41.3 Built-in function quick reference radians degrees sin cos tan asin acos atan sinh cosh tanh asinh acosh atanh
pow exp log exp2 log2 sqrt inversesqrt abs sign floor ceil trunc round roundEven fract mod modf min max clamp mix step smoothstep isnan isinf fma
length distance dot cross normalize faceforward reflect refract
matrixCompMult outerProduct transpose determinant inverse lessThan lessThanEqual greaterThan greaterThanEqual equal notEqual any all not
bitfieldExtract bitfieldInsert bitfieldReverse bitCount findLSB findMSB uaddCarry usubBorrow umulExtended imulExtended
packUnorm2x16 packSnorm2x16 packUnorm4x8 packSnorm4x8 packHalf2x16 unpack*
texture textureLod textureOffset texelFetch texelFetchOffset textureGrad textureProj textureGather textureSize textureQueryLod textureQueryLevels textureSamples
dFdx dFdy fwidth dFdxFine dFdyFine dFdxCoarse dFdyCoarse interpolateAtCentroid interpolateAtSample interpolateAtOffset Images & atomics
imageLoad imageStore imageSize imageAtomicAdd ... atomicAdd atomicMin atomicMax atomicAnd atomicOr atomicXor atomicExchange atomicCompSwap atomicCounterIncrement
barrier memoryBarrier memoryBarrierShared memoryBarrierBuffer memoryBarrierImage groupMemoryBarrier
EmitVertex EndPrimitive EmitStreamVertex EndStreamPrimitive 41.4 Math reference for graphics Formula / GLSL max(dot(N, L), 0.0) Blinn–Phong specular
pow(max(dot(N, normalize(L + V)), 0.0), shininess) I - 2.0 * dot(N, I) * N = reflect(I, N)
F0 + (1.0 - F0) * pow(1.0 - cosθ, 5.0) a² / (π ((N·H)² (a² − 1) + 1)²)
1 / (c + l·d + q·d²) or physically 1 / d² mix(a, b, t)
(x - inMin) / (inMax - inMin) * (outMax - outMin) + outMin
mat2(cos a, sin a, -sin a, cos a) (column-major) w0 * A + w1 * B + w2 * C Luminance (Rec. 709) dot(c, vec3(0.2126, 0.7152, 0.0722))
mix(b, a, h) - k*h*(1-h) with h = clamp(0.5 + 0.5*(b-a)/k, 0, 1) 41.5 Learning resources Online (free):
*The Book of Shaders* — Patricio Gonzalez Vivo & Jen Lowe (thebookofshaders.com)
*LearnOpenGL* — Joey de Vries (learnopengl.com) — the best OpenGL/GLSL tutorial series
Inigo Quilez's articles (iquilezles.org) — SDFs, noise, ray marching, procedural techniques
Shadertoy (shadertoy.com) — study and fork thousands of shaders
*WebGL2 Fundamentals* (webgl2fundamentals.org) *Vulkan Tutorial* (vulkan-tutorial.com), *Vulkan Guide* (vkguide.dev)
*GPU Gems* series (free on NVIDIA's site), Khronos GLSL specifications and reference pages
*The Art of Code* & *Freya Holmér* YouTube channels; Sebastian Lague's coding adventures
*OpenGL 4 Shading Language Cookbook* (3rd ed.) — David Wolff
*OpenGL Programming Guide* ("Red Book", 9th ed.) — Kessenich, Sellers, Shreiner
*OpenGL SuperBible* (7th ed.) — Sellers, Wright, Haemel *Real-Time Rendering* (4th ed.) — Akenine-Möller, Haines, Hoffman et al.
*Physically Based Rendering* (4th ed., free online) — Pharr, Jakob, Humphreys
*Practical Shader Development* — Kyle Halladay *Graphics Shaders: Theory and Practice* — Bailey & Cunningham *GPU Pro / GPU Zen* series
Community: Shadertoy comments, r/GraphicsProgramming, r/opengl, r/vulkan, Graphics Programming Discord, Khronos forums, SIGGRAPH courses (e.g., "Physically Based Shading in Theory and Practice") 41.6 Suggested study plan (12 weeks)
Pipeline concepts, tools, first triangle, first Shadertoy shaders
Versions, types, vectors/matrices, qualifiers, operators Control flow, built-in variables & functions — Part I exercises
Transformations, fragment output, uniforms/UBOs, textures Lighting, normal/parallax/environment mapping — Project 2
Procedural graphics, noise, color science — Project 1 Post-processing, shadows, instancing & skinning — Part II exercises, Project 3
Geometry, tessellation, compute shaders, SSBOs & images PBR, IBL, deferred shading, SSAO — Project 4
Ray marching, GPU effects (particles, water, terrain, volumetrics) — Project 6
Vulkan GLSL/SPIR-V, modern extensions, GLSL ES/WebGL Performance, debugging, shader architecture, best practices — Project 5, 7, or 8 🎓 Final Words
You've journeyed from a single colored triangle to physically based rendering, compute-driven particle systems, ray-marched worlds, and hardware ray tracing. Shader programming rewards curiosity and experimentation — visualize everything, keep your coordinate spaces and color spaces straight, and study the masters on Shadertoy and in Inigo Quilez's articles. Build the capstone projects, share your shaders, and make beautiful pixels. Happy shading! 🎨
#version 330 core // or 300 es / 450 (Vulkan) / 460
// Vertex shader
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec3 aNormal;
layout (location = 2) in vec2 aUV;
uniform mat4 uModel, uView, uProj;
out vec3 vNormal; out vec2 vUV; out vec3 vWorldPos;
void main() {
vec4 w = uModel * vec4(aPos, 1.0);
vWorldPos = w.xyz; vNormal = mat3(uModel) * aNormal; vUV = aUV;
gl_Position = uProj * uView * w;
}
// Fragment shader
in vec3 vNormal; in vec2 vUV; in vec3 vWorldPos;
uniform sampler2D uTex; uniform vec3 uLightDir; uniform vec3 uCamPos;
out vec4 fragColor;
void main() {
vec3 N = normalize(vNormal), L = normalize(-uLightDir), V = normalize(uCamPos - vWorldPos);
vec3 H = normalize(L + V);
vec3 albedo = texture(uTex, vUV).rgb;
vec3 col = albedo * (0.1 + max(dot(N, L), 0.0)) + pow(max(dot(N, H), 0.0), 64.0);
fragColor = vec4(pow(col, vec3(1.0 / 2.2)), 1.0);
}
// Compute shader
layout (local_size_x = 256) in;
layout (std430, binding = 0) buffer Data { float v[]; };
void main() { uint i = gl_GlobalInvocationID.x; if (i < uint(v.length())) v[i] *= 2.0; }
// Handy functions
mix(a, b, t) step(e, x) smoothstep(e0, e1, x) cl
…