Milestone 4: colour + shear

The Encoded Asset for this Milestone is a scrambled picture. Its pixels have moved, as in Milestone 3, and then its colours were changed, as in Milestone 1. Your shader undoes both: a small program, written in a language called GLSL, that runs on the graphics card and draws a picture.

This Milestone is practice for the Puzzle: the last and hardest picture to decode, in the next tab.

The recipe

This recipe has two keys: the numbers that say how far it moves the pixels. They are KROW = 365 and KCOL = 145.

The picture is W × H = 512 × 168 pixels, with rows 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.

Encoding: two steps, one after the other.

  1. 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.
    • First, 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.
  2. 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).

The Puzzle uses this same encoding, on a picture of the same size. The only difference is that the Puzzle doesn't tell you its keys.

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 3 starter with this Milestone's keys. It draws the Encoded Asset as it is. Change it so it undoes both steps of the recipe.

When a recipe has more than one step, your shader undoes them in reverse order. Working backwards shows how.

The colour step moves a colour's three numbers round, as Working with colour shows. The shear slides every row and every column by a different amount, as Shifting rows and columns shows.

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. As before, floor turns the dots on the screen into whole pixels of the picture (Pixel coordinates), and highp asks for the most precise numbers the device has (Precision).

You'll know when you've solved it: a long brick building with rows of windows will appear, in its true colours. Keep your shader: it's a good place to start the Puzzle.

Hints