Milestone 1: colour
This time every pixel is in the right place, but its colour has been scrambled. Your shader unscrambles it.
The recipe
Encoding: colour. Each pixel stays in place. Its red, green and blue are moved round one place and inverted, which means each value v becomes 1 − v:
encoded.rgb = (1 − g, 1 − b, 1 − r)
Here r, g and b are the picture's red, green and blue, from 0 to 1. So the encoded red is one minus the picture's green, and so on.
Decoding: each pixel reads its encoded colour, then works out the picture's colour from it:
r = 1 − encoded.b, g = 1 − encoded.r, b = 1 − encoded.g
- The picture is W × H = 512 × 168 pixels, with rows counted from the bottom.
The Puzzle uses this exact colour step, so you'll need this shader again.
Your shader
Your input is u_encodedAsset: the Encoded Asset, the picture your shader reads and decodes.
The starter shader below is the Milestone 0 solution: it draws the Encoded Asset pixel for pixel, scrambled colours and all. Change the last line so it draws the picture's colours instead.
A colour in GLSL is a vector, a small list of numbers: here red, green and blue. A swizzle such as encodedColour.gbr picks a vector's numbers in any order, and 1.0 - encodedColour works on all of them at once. Working with colour shows both, live.
The recipe says how the colours were scrambled, and the decoding line says how to get them back: each pixel reads its scrambled colour and undoes the change. Working backwards explains why a shader works this way round.
You'll know when you've solved it: the colours will look right.