The Puzzle
The Puzzle's Encoded Asset is a scrambled picture, 512 × 168 pixels: 512 dots of colour across and 168 up. Your task is to write a shader that decodes it, which means turning it back into the original picture. A shader is a small program that runs on the graphics card and draws a picture.
The encoding is the list of steps that scrambled the picture. Its keys are the numbers that say how far those steps moved the pixels. Each Milestone is a smaller practice puzzle, in the tabs before this one, and Milestone 4 is the last of them.
This uses the same encoding as Milestone 4, on a 512×168 image, but the keys are hidden. Milestone 4 told you its keys. Here you find them by trying.
Both keys are prime numbers between 10 and 100. A prime number is a whole number that divides exactly only by 1 and by itself, such as 11 or 13.
The method
The encoding had two steps. Your shader undoes them in reverse order: the last step that was done is the first one you undo. Working backwards shows how.
The picture is W × H pixels, where W = 512 is the width and H = 168 is the height. Rows are counted from the bottom and columns from the left, both starting at 0. mod means "the remainder after dividing by": 530 mod 512 is 18. The dot, ·, means multiply.
- Shear. A shear slides each row of the picture by a different amount, then each column by a different amount. Whatever slides off one edge comes back in at the opposite edge, which is called wrapping. Wrapping shows how to do it in a shader, and Shifting rows and columns shows a slide that's different for every row or column.
- First, each row
yslides right by(KROW · y) mod Wpixels. - Then each column
x′of the result slides up by(KCOL · x′) mod Hpixels.x′, said "x prime", is a column after the rows have slid.
- First, each row
- Colour. A colour is three numbers, red (
r), green (g) and blue (b), each from 0 to 1. Each pixel's three numbers move round one place, and each is taken away from 1:encoded.rgb = (1 − g, 1 − b, 1 − r). Working with colour shows how to move them round.
KROW is the row key: it sets how far each row slides. KCOL is the column key: it sets how far each column slides.
You'll know when you've solved it, because you'll see a clear picture appear.
Your shader
Your input is u_encodedAsset: the Encoded Asset, the picture your shader reads and decodes.
The canvas below shows what your shader draws. The editor under it is where you write your shader. It runs your shader again each time you type, and shows any error next to the line it's on. The shader it starts with just draws the Encoded Asset as it is. A good place to start is your Milestone 4 shader: copy it in, then change the keys.