Skip to content

Elevated

A mountain flight in 4,096 bytes

A 4K intro by Rgba and TBC that flies a camera over procedurally generated mountains, with music, from a Windows program of no more than 4,096 bytes. It won the PC 4K intro competition at Breakpoint 2009 and the Scene.org Award for best 4K intro of 2009. Its source code was published in 2016.

In the spring of 2008 iq, Íñigo Quílez of the Spanish group Rgba, won Breakpoint’s 4K graphics competition with Ixaleno, a still image of a mountain landscape generated by a 4,096-byte program. People asked him when imagery like that would run in real time. “I was answering ‘today’,” he wrote a year later, “the point really was how good I could do in 4 kilobytes.” Elevated was his answer, made with Mentor and Puryx of the Danish group TBC. It is a camera flight over rock, snow and water, set to a soundtrack that Quílez briefed as something epic, and the whole program, pictures and music together, fits in 4,096 bytes.

At Breakpoint 2009, held at Easter in Bingen am Rhein, Elevated won the PC 4K intro competition with 1,137 points. Second, on 916, was Untraceable, a 1 KB intro by TBC itself. Loonies’ Sult came third with 827.

Fast facts

  • By: Rgba and TBC.
  • Credits: iq (visuals), Mentor (synthesiser and code optimisation), Puryx (music).
  • Platform: PC, Windows with DirectX 9.
  • Released: April 2009, at Breakpoint 2009.
  • Size: no more than 4,096 bytes. The versions rebuilt in 2016 are 4,062 to 4,066 bytes.
  • Awards: 1st, PC 4K intro, Breakpoint 2009; Scene.org Award for best 4K intro of 2009.

How it came together

Quílez had a working prototype in OpenGL, but at about 3.5 KB without music or a script he thought it was “too big for 4k, not good enough for a 64k”. In his account of a chat with Mentor, Mentor looked at a screenshot and suggested “how about making a 4k together”. When Quílez objected that it was already 3.5 KB and unoptimised, Mentor replied: “we make it 4k”. Mentor ported the prototype to DirectX, added his own synthesiser and brought in Puryx for the music. Quílez asked for something epic, “something like The Lord of the Rings”, with a “wooaa” moment after the epic part. Two days later Puryx sent back a test track, and Quílez replied, “this is an instant win”.

The team did not always agree on the look. Quílez wanted a realistic landscape filmed with a hand-held TV camera. “The Danish part of the team”, he told the Function party in Budapest later that year, wanted something sharp and shiny, with smooth camera moves and “more action in the scene”, such as flashes in the sky. They kept his film grain, brightness flicker and camera shake, and when Mentor sent a version with flashes of light in the sky, Quílez agreed it could work. “For two weeks we fought against the entropy,” Quílez wrote in the release notes, a day before the party, adding that the team had not slept much but would make the deadline.

How it fits in so little

Elevated contains no stored geometry, textures or sound samples. Everything comes from code. The release notes explain the method: the landscape is a “(too) low density flat mesh displaced with a procedural vertex shader”. A flat grid of triangles is pushed up and down by a height function, and the graphics card draws it in the ordinary way. The texturing and lighting are then “deferred”: a second pass works out the colour of every pixel on the screen from the position the first pass stored there, and a third pass adds motion blur. The notes point out that this way the expensive surface calculations are made only once per pixel.

This set it apart from much of the 4K competition that year. Quílez described 2009 as “the year of the raymarching”, when many intros drew shiny objects by stepping a ray through a distance field for every pixel. Pure ray marching made shading easy but interesting geometry hard, he said, while triangles did the opposite. Elevated combined them: the triangles find what each pixel sees, and the full-screen shader shades it as a ray-marched intro would.

The height function is a sum of noise at many scales. In the Function 2009 slides Quílez showed it as a loop over 16 octaves of noise, each half the strength of the last, with his own twist, a “(failed) (and quick) attempt to erosion”. His noise function also returns its slope, and the running total of slopes damps each later octave. Without that divisor, the slides note, the code is the traditional fractal sum.

Code
float terrain( vec2 p )
{
    float a = 0.0;
    float b = 1.0;
    vec2 c = vec2(0.0);
    for(int i=0; i<16; i++ )
    {
        vec3 n = noise2f(p);
        c += n.yz;
        a += b*n.x / (1.0+dot(c,c));
        b *= 0.5;
        p = mat2x2(1.6,-1.2,1.2,1.6)*p;
    }
    return a;
}

The same function does several jobs. It drives the surface detail and the blending between materials, so the textures follow the shape of the land. Evaluated with fewer octaves, it gives a smoothed version of the terrain whose lighting darkens the far sides of mountains: fake soft shadows, since the intro computes no real ones. It also keeps the camera above the ground, which meant the camera had to be calculated on the graphics card too, “as only the GPU knows the procedural definition of the landscape”. Fed with time instead of position, it supplies the shake of the hand-held camera.

The camera paths are nearly free. Each path is two cosine waves for each horizontal axis, whose frequencies and phases are read from the same random texture the noise uses, so a starting point in that texture defines a whole path. With speed, height offsets and field of view, each camera shot takes 8 bytes. The team looked through 512 of the 65,536 possible paths to choose their shots. Mentor added support for GNU Rocket, a synchronisation tool by kusma and skrebbel, and the program was packed by Crinkler, a compressing linker for 4K intros written by Mentor and Blueberry of Loonies.

All this was heavy work for a 2009 graphics card. The release notes say an early version ran at 30 frames a second on a GeForce 7900, “but size optimizations forced us to ask you for a pretty decent graphics card, like a geforce 8800gtx or hd4850”.

Reception and later life

Besides the Breakpoint win, Elevated won the Scene.org Award for best 4K intro of 2009, against a field that included Sult and Loonies’ Amiga 4K Luminagia. It was also nominated for best technical achievement and for the public’s choice.

Quílez moved to Pixar that year. His résumé lists Elevated alongside his film work, as “the 4 kilobytes realtime procedural terrain demo winner of Breakpoint”. In 2016 the intro was rebuilt to run on Windows 10, and its full source code was published on scene.org under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 licence: assembly language for the intro and Mentor’s synthesiser, the music data, a debug build and the Visual Studio 2015 project, with Crinkler included. A link to it on Hacker News in June 2016 drew nearly 150 comments.

Sources

See also

Checked. Verified against primary sources and signed off by a person.