Milestone 3: shear
The Encoded Asset for this Milestone is a scrambled picture. Its colours are right, but its pixels have moved, and this time each row and each column moved by a different amount. Your shader moves them back: a small program, written in a language called GLSL, that runs on the graphics card and draws a picture.
The recipe
This recipe has two keys: the numbers that say how far it moves the pixels. They are KROW = 317 and KCOL = 233.
Encoding: a shear, which 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. mod means "the remainder after dividing by", which is how that wrap is written: 530 mod 512 is 18. The dot, ·, means multiply.
- Each row
y slides right by (KROW · y) mod W pixels.
- Then each column
x′ of the result slides up by (KCOL · x′) mod H pixels. x′, said "x prime", is a column after the rows have slid.
- The picture is W × H = 512 × 168 pixels, with rows counted from the bottom and columns from the left, both starting at 0.
- There is no colour step.
From this Milestone on, the recipe only says how the picture was scrambled, like the Puzzle does. You work out how to undo it.
Your shader
Your input is u_encodedAsset: the Encoded Asset, the picture your shader reads and decodes.
The starter shader below, the code the editor starts with, is the Milestone 2 starter with this Milestone's keys. It draws the Encoded Asset as it is. Change it so each pixel reads its colour from where the shear moved it to.
This recipe has two steps, one after the other. Working backwards shows how each pixel finds where its colour ended up when there's more than one step.
A slide that's different for every row or column is shown in Shifting rows and columns.
As in Milestone 2, floor turns the dots on the screen into whole pixels of the picture, as Pixel coordinates explains. exactMod is a helper: a small function you call instead of GLSL's mod. It wraps round at the edges, and always gives an exact answer, as Wrapping explains: x wraps at W, and y wraps at H.
The first line, precision highp float;, asks for highp: the most precise numbers the device has. A key times a pixel number reaches tens of thousands, so this matters even more here. Precision explains why not to copy mediump from examples online.
You'll know when you've solved it: a building with a curved glass roof will appear.