Post-processing
glint · Examples · Tutorials · Gallery
Effects on the finished picture: vignette, chromatic aberration, grain, lens distortion, an old TV, pixel art, dithering, halftone, ASCII art, edges, cartoon, a painterly filter, lift/gamma/gain, teal and orange, sharpening, glitch, VHS, night vision and a kaleidoscope.
A free interactive course of 20 steps in glint, a live shader editor in the browser: each step changes a running shader, and ticks itself when you've done its task.
1. A vignette
Post-processing works on the finished picture: a pass that reads the scene's picture and changes it. Every step of this course has the same two passes: Scene (a street at dusk, with a light moving about) and Post (open), which reads it as prevPass. Everything happens in Post.
First, the oldest one: real lenses let less light reach the corners than the middle, so photos darken towards the edges. It pulls the eye inwards, and almost every film does it on purpose.
d is how far this pixel is from the middle, in screen heights (so it's round, not stretched). vig is how much light gets here: 1 now, everywhere.
Your turn: Darken the corners: float vig = 1.0 - dot(d, d) * 1.2;
2. Chromatic aberration
Glass bends each colour by a slightly different amount, so a cheap lens puts the red, green and blue images in slightly different places: colour fringes, worst at the edges. Phone cameras correct it; films and games add it back for character.
Read each channel from a different place: red from a little further out from the middle, blue from a little further in, green where it is. Nothing happens in the middle, and fringes grow outwards.
Your turn: Split the colours: const float AMOUNT = 0.012;
3. Film grain
Film is made of grains of silver, and video sensors have noise: a fine, moving speckle over everything. Clean digital pictures look sterile without it; a little grain makes them feel photographed (and hides banding in smooth gradients).
hash gives a random number for each pixel and frame (frame changes every frame, so the grain moves; frozen grain looks like dirt on the lens). Subtracting 0.5 makes it lighten and darken equally.
Your turn: Add grain: col += (hash(uvec3(gl_FragCoord.xy, uint(frame))) - 0.5) * 0.12;
4. Lens distortion
Wide lenses bow straight lines outwards (barrel distortion): GoPros, fisheye shots, security cameras. Long lenses pinch them in a little (pincushion).
Move each pixel's reading point out from the middle by an amount that grows with the square of its distance: d *= 1.0 + K * dot(d, d). In the middle nothing changes; at the edges the picture is read from further out, so it seems squeezed into a bulge. Negative K pinches.
Your turn: Make it bulge: const float K = 0.4;
5. An old TV
A CRT television: the curved glass bulges the picture (the last step's trick), each column of pixels is a red, green or blue phosphor stripe (the shadow mask), and the picture is drawn in lines with gaps between them.
The lines are what's missing: brighten and darken by a wave that repeats every two pixels down the screen. sin(gl_FragCoord.y * 3.14159) goes up and down once every 2 pixels.
Your turn: Add scanlines: col *= 0.6 + 0.4 * abs(sin(gl_FragCoord.y * 3.14159 * 0.5));
6. Pixel art
Big pixels: every screen pixel in a SIZE × SIZE block reads the same spot (the block's middle), so the block is one colour. Rounding the colour to a few levels (floor(col * 5.0 + 0.5) / 5.0) gives the small palette of old consoles.
With SIZE 1 the blocks are single pixels and only the palette shows.
Your turn: Make the pixels big: const float SIZE = 6.0;
7. Two colours: ordered dithering
With only two colours, cutting at one brightness (0.5) turns the picture into blotches: everything darker is solid ink. Dithering fakes the grey in between with patterns of dots: a darker grey has more ink dots.
Ordered dithering uses a different threshold for each pixel from a small repeating grid, the Bayer matrix (the stock bayer texture, 8 × 8). In a mid grey, half the pixels pass their threshold, in a pattern spread as evenly as possible. It's the look of the original Macintosh and the Game Boy.
Your turn: Threshold by the matrix: float threshold = texelFetch(bayer, ivec2(gl_FragCoord.xy) % 8, 0).r;
8. Halftone
Newspapers print grey with dots of black ink: big dots where it's dark, small where it's light, on a grid turned 30° so it doesn't line up with the picture. Each grid cell reads the picture once, at its middle, and draws one dot.
All the dots are the same size now. A dot's area is what makes the grey, so its radius should go with the square root of the darkness: sqrt(1.0 - l) * 0.6.
Your turn: Size the dots by darkness: float r = sqrt(1.0 - l) * 0.6;
9. ASCII art
Draw the picture in letters: cut the screen into character-sized cells, read each cell's colour, and pick a character whose ink covers about as much as the cell's brightness, from a space for black to @ for white.
The characters come from the stock font texture (the Vertex shaders 2 course used it too). RAMP lists ten characters from empty to full. Right now every cell is k = 9, the @.
Your turn: Pick by brightness: int k = int(l * 9.99);
10. Finding edges
Edges are where brightness changes fast. The Sobel filter measures how fast, across (gx) and up (gy), from the eight neighbouring pixels, weighting the nearest ones double. length(vec2(gx, gy)) is the steepness, whatever the direction.
It's the starting point of countless effects: outlines, sketches, neon edges, motion detection, sharpening. Here it's worked out but the picture is shown as it was.
Your turn: Show the edges: col = vec3(length(vec2(gx, gy)));
11. Cartoon
Two of the last effects together make a cartoon: flat bands of colour (posterising, like the pixel art's palette) and dark ink lines where the picture has edges.
edge is the brightness change across and up (a cheaper edge than Sobel, from four neighbours). Where it's big, darken towards black.
Your turn: Ink the edges: col *= 1.0 - smoothstep(0.1, 0.25, edge);
12. A painting: the Kuwahara filter
A blur smears edges along with everything else. The Kuwahara filter blurs inside areas but keeps edges sharp: for each pixel, it looks at the four boxes that touch it (up-left, up-right, down-left, down-right) and takes the average of whichever box varies least.
On an edge, at least one box lies wholly on one side and is calm, so it wins and the edge stays crisp. Inside an area, all four are similar and it averages. The result looks painted, in flat brush strokes.
This step's Scene has a fine grain over it, like a real photo's detail: on a smooth picture the filter has nothing to paint over.
R is each box's size, in steps of px (about a 500th of the screen's height, so it looks the same on any screen): 0 is one pixel, no change. It costs 4 × (R+1)² reads per pixel, so it grows fast.
Your turn: Paint it: const int R = 4;
13. Lift, gamma, gain
The three wheels of every colour-grading desk. Lift moves the shadows (here a little blue-purple, so blacks aren't dead black), gain scales the highlights, gamma bends the tones in between. Each is a colour, so each part of the picture can be tinted separately.
Warm highlights against cool shadows is the classic: the eye reads it as sunlight and sky.
Your turn: Warm the highlights: vec3 gain = vec3(1.12, 1.0, 0.85);
14. Teal and orange
The blockbuster look: shadows pushed towards teal, highlights towards orange. Skin is orange-ish and skies blue, so the two families of colour separate and the picture looks rich even when it isn't.
tone goes from teal to orange with the brightness, and the picture is multiplied by it. STRENGTH mixes between the original and the toned one.
Your turn: Tone it: const float STRENGTH = 0.6;
15. Sharpening
Sharpening is blurring backwards. blur is the average of the four neighbours; col - blur is what's different about this pixel (its detail), and adding more of it exaggerates the detail: edges get a bright side and a dark side, textures crisper. It's called an unsharp mask, after the darkroom trick it copies.
Too much makes halos round everything and boosts noise.
Your turn: Sharpen: const float AMOUNT = 1.5;
16. Glitch
Digital video breaks in blocks and bands. Cut the picture into 24 horizontal bands; ten times a second, each band rolls two random numbers (r, r2). Most bands stay put; a few jump sideways, with the colours slightly apart, as if the signal tore.
step(0.85, r2) is 1 for about one band in seven. The glitch passes (glint › New › Add glitch pass) do much more, but this is the core.
Your turn: Tear some bands: float shift = (r - 0.5) * 0.15 * step(0.85, r2);
17. VHS
A videotape: the picture wobbles sideways a little, colour is smeared (tape kept sharp brightness but very blurry colour, so here the colour comes from a wide horizontal average while the brightness stays sharp), and there's noise.
The giveaway is the tracking: a band of torn picture rolling slowly up the screen. fract(time * 0.15) moves from 0 to 1 and round again; rows near it get pushed sideways.
Your turn: Add the rolling tear: uv.x += 0.03 * smoothstep(0.03, 0.0, abs(uv.y - fract(time * 0.15)));
18. Night vision
False colour: replace the picture's colours with ones that mean something else. Night-vision goggles amplify faint light (and their noise) and show it on a green phosphor screen, because the eye tells more shades of green apart than any other colour.
l is already amplified and noisy, and the round eyepiece is there. Right now it's shown as plain grey.
Your turn: Make it green: col = vec3(0.15, 1.0, 0.3) * l;
19. A kaleidoscope
Post-processing can rearrange the picture as well as recolour it. A kaleidoscope folds the angle round the middle into one slice and mirrors it, so every slice shows the same piece of the picture.
k is half a slice. abs(mod(a, 2k) - k) folds every angle into 0..k, mirrored back and forth. With N = 1 the fold is a single mirror; more slices, more symmetry.
Your turn: Six slices: const float N = 6.0;
20. Pull it apart: the washed-out grade
A chain of effects, as you'd finish a real piece: barrel distortion with colour fringes, a teal and warm grade, grain and a vignette. But the result is washed out and milky, the blacks grey and the colours weak.
The scene's picture is already ready for the screen (a photo is stored with its gamma). Something at the end does that again.
Your turn: Fix the washed-out look.
Other courses: Basics · Medium · Advanced · Maths for shaders · Raymarching, step by step · Matrices, from scratch · Sound you can see · Noise from scratch · Colour and light · Passes and feedback · Skies and reflections · Vertex shaders, step by step · Raymarching 2: glow, fog and light · Raymarching 3: worlds · Raymarching 4: modelling, materials and motion · Fractals, step by step · Vertex shaders 2: lines, particles and moving meshes · Fractals 2: further in · Vertex shaders 3: living geometry · Surfaces: from vertex to fragment · Blur and glow