🎚️ Interpolation: Lerp, Smoothstep and Easing
Blending smoothly from one value to another is everywhere in graphics: colours, positions, textures, animation. Meet lerp, its reverse, remapping, smoothstep and easing curves.
Blending smoothly from one value to another is everywhere in graphics: colours, positions, textures, animation. Meet lerp, its reverse, remapping, smoothstep and easing curves.
The rules for using ddx and ddy safely, and helper pixels: the extra, invisible fragment shader runs that 2×2 groups need. See them on your own GPU.
Build each triangle’s normal in the fragment shader from ddx and ddy of its position: a faceted, low-poly look with no extra mesh data. Plus more uses for derivatives.
The two uses of ddx and ddy you’ll meet most: choosing a texture’s mipmap level, and smooth edges at any zoom with fwidth. With live WebGL demos.
What ddx and ddy (dFdx and dFdy in GLSL) tell a shader, and how the graphics card works them out by comparing neighbouring pixels in 2×2 groups, with interactive WebGL demos.
A graphics card runs shaders in groups of 32 or 64 that all execute the same instruction at once. See what that means for if statements, and how GPUs hide slow memory by juggling groups.
With a 3D distance function, a fragment shader can draw a whole scene without a single triangle: march a ray from each pixel, jumping as far as the distance allows. Watch the jumps, then explore a live scene. Part 4 of the signed distance fields series.
Two lines of maths join, cut and melt shapes together, and a few more repeat, mirror and twist them, endlessly, for free. Part 2 of the signed distance fields series.
Describe a shape by how far every point is from its edge, and you get crisp edges at any size, easy outlines and much more. See how circles, boxes, lines and polygons are written as distance functions.
A flat square can look like a bumpy brick wall if each pixel lies about which way it faces. See how normal maps store those directions, and why they’re always blue.
How a shader fakes light with three simple terms: ambient, diffuse and specular. Learn Lambert’s cosine law, the Blinn-Phong highlight, and why lighting per pixel beats lighting per vertex.
How values are blended smoothly across a triangle, how a fragment shader turns them into a colour, and why perspective needs special care. Includes a live fragment shader editor.