Saturday, 8 January 2011

Block 3 Part 1 section 5 Activities


Block 3 Part 1 section 5 (Computer Game Technology) - I thought I'd share my answers for Activities 31 to 34 (images not included):

The Wizardry of Id
D. Kushner
August 2002
IEEE Spectrum.

PART 1 (for Activity 31)
[...] Through its technologically innovative games, Id has had a huge influence on everyday computing, from the high-speed, high-color , and high-resolution graphics cards common in today’s PCs to the marshalling of an army of on-line game programmers and players who have helped shape popular culture. 

[...]

To bring these games to the consumer PC and establish Id as the market leader required skill at simplifying difficult graphics problems and cunning in exploiting on-going improvements in computer graphics cards, processing power, and memory size.
To date, their games have earned over US $1 50 million in sales, according to The NPD Group, a New York City market research firm.

It All Began With a Guy Named Mario
The company owes much of its success to advances made by John Carmack, its 31-year -old lead programmer and cofounder who has been programming games since he was a teenager .

Back in the late 1 980s, the electronic gaming industry was dominated by dedicated video game consoles. Most game software was distributed in cartridges, which slotted into the consoles, and as a consequence, writing games required expensive development systems and corporate backing. 

The only alternative was home computer game programming, an underworld in which amateurs could develop and distribute software. Writing games for the low-powered machines required only programming skill and a love of gaming. 

Four guys with that passion were artist Adrian Carmack; programmer John Carmack (no relation); game designer Tom Hall; and programmer John Romero. While working together at Softdisk (Shreveport, La.), a small software publisher , these inveterate gamers began moonlighting on their own titles.

At the time, the PC was still largely viewed as being for business only. It had, after all, only a handful of screen colors and squeaked out sounds through a tiny tinny speaker . Nonetheless, the Softdisk gamers figured this was enough to start using the PC as a games platform.

First, they decided to see if they could recreate on a PC the gaming industry’s biggest hit at the time, Super Mario Brothers 3. This two-dimensional game an on the Super Nintendo Entertainment System, which drove a regular television screen. The object was to make a moustached plumber , named Mario, leap over platforms and dodge hazards while running across a landscape below a blue sky strewn with puffy clouds. As Mario ran, the terrain scrolled from side to side to keep him more or less in the middle of the screen. To get the graphics performance required, the Nintendo console resorted to dedicated hardware. ‘We had clear examples of console games [like Mario] that did smooth scrolling,’ John Carmack says, ‘but [in 1990] no one had done it on an IBM PC.’

PART 2 (for Activity 32)
After a few nights of experimentation, Carmack figured out how to emulate the side-scrolling action on a PC. In the game, the screen image was drawn, or rendered, by assembling an array of 1 6-by-1 6-pixel tiles. Usually the on-screen background took over 200 of these square tiles, a blue sky tile here, a cloud tile there, and so on. Graphics for active elements, such as Mario, were then drawn on top of the background.

Any attempt to redraw the entire background every frame resulted in a game that ran too slowly, so Carmack figured out how to have to redraw only a handful of tiles every frame, speeding the game up immensely. His technique relied on a new type of graphics card that had become available, and the observation that the player’s movement occurred incrementally, so most of the next frame’s scenery had already been drawn. 

The new graphics cards were known as Enhanced Graphics Adapter (EGA) cards. They had more on-board video memory than the earlier Color Graphics Adapter (CGA) cards and could display 1 6 colors at once, instead of four . For Carmack, the extra memory had two important consequences. First, while intended for a single relatively high-resolution screen image, the card’s memory could hold several video screens’ worth of low-resolution images, typically 300 by 200 pixels, simultaneously, good enough for video games. By pointing to different video memory addresses, the card could switch which image was being sent to the screen at around 60 times a second, allowing smooth animation without annoying flicker . Second, the card could move data around in its video memory much faster than image data could be copied from the PC’s main memory to the card, eliminating a major graphics performance bottleneck.

Carmack wrote a so-called graphics display engine that exploited both properties to the full by using a technique that had been originally developed in the 1 970s for scrolling over large images, such as satellite photographs. First, he assembled a complete screen in video memory, tile by tile - - plus a border one tile wide [Figure 1 5].
If the player moved one pixel in any direction, the display engine moved the origin of the image it sent to the screen by one pixel in the corresponding direction. No new tiles had to be drawn. When the player’s movements finally pushed the screen image to the outer edge of a border , the engine still did not redraw most of the screen. Instead, it copied most of the existing image - - the part that would remain constant - - into another portion of video memory. Then it added the new tiles and moved the origin of the screen display so that it pointed to the new image.

In short, rather than having the PC redraw tens of thousands of pixels every time the player moved, the engine usually had to change only a single memory address - - the one that indicated the origin of the screen image - - or , at worst, draw a relatively thin strip of pixels for the new tiles. So the PC’s CPU was left with plenty of time for other tasks, such as drawing and animating the game’s moving platforms, hostile characters, and the other active elements with which the player interacted.

PART 3 (for Activity 33)
[Carmack] had been experimenting with 3-D graphics ever since junior high school, when he produced wire-frame MTV logos on his Apple II. Since then, several game creators had experimented with first-person 3-D points of view, where the flat tiles of 2-D games are replaced by polygons forming the surfaces of the player’s surrounding environment. The player no longer felt outside, looking in on the game’s world, but saw it as if from the inside. 

The results had been mixed, though. The PC was simply too slow to redraw detailed 3-D scenes as the player’s position shifted. It had to draw lots of surfaces for each and every frame sent to the screen, including many that would be obscured by other surfaces closer to the player .

Carmack had an idea that would let the computer draw only those surfaces that were seen by the player . ‘If you’re willing to restrict the flexibility of your approach,’ he says, ‘you can almost always do something better .’

So he chose not to address the general problem of drawing arbitrary polygons that could be positioned anywhere in space, but designed a program that would draw only trapezoids. His concern at this time was with walls (which are shaped like trapezoids in 3-D), not ceilings or floors.

For his program, Carmack simplified a technique for rendering realistic images on then high-end systems. In raycasting, as it is called, the computer draws scenes by extending lines from the player’s position in the direction he or she is facing. When it strikes a surface, the pixel corresponding to that line on the player’s screen is painted the appropriate color . None of the computer’s time is wasted on drawing surfaces that would never be seen anyway. By only drawing walls, Carmack could raycast scenes very quickly.

Carmack’s final challenge was to furnish his 3-D world with treasure chests, hostile characters, and other objects. Once again, he simplified the task, this time by using 2-D graphical icons, known as sprites. He got the computer to scale the size of the sprite, depending on the player’s location, so that he did not have to model the objects as 3-D figures, a task that would have slowed the game painfully. By combining sprites with raycasting, Carmack was able to place players in a fast -moving 3-D world. The upshot was Hovertank, released in April 1991. It was the first fast-action 3-D first-person action shooter for the PC.
[...]

Instant Sensation
For Id’s next game, Wolfenstein 3D, Carmack refined his code. A key decision ensured the graphics engine had as little work to do as possible: to make the walls even easier to draw, they would all be the same height.

This speeded up raycasting immensely. In normal raycasting, one line is projected through space for every pixel displayed. A 320-by-200-pixel screen image of the type common at the time required 64 000 lines. But because Carmack’s walls were uniform from top to bottom, he had to raycast along only one horizontal plane, just 320 lines [Figure 1 6].

[...]
By this time, Carmack was programming for the Video Graphics Adapter (VGA) cards that had supplanted the EGA cards. VGA allowed 256 colors - - a big step up from EGA’s 1 6, but still a limited range that made it a challenge to incorporate all the shading needed for diminished lighting effects.

The solution was to restrict the palette used for the game’s graphics, so that 16 shades of each of 1 6 colors could be accommodated. Carmack then programmed the computer to display different shades based on the player’s location within a room. The darkest hues of a color were applied to far sections of a room; nearer surfaces would always be brighter than those farther away. This added to the moody atmosphere of the game.

Activity31
How would you describe, in your own words, the content of this first part of the article? Try making yourself a mindmap or a set of brief notes. I felt that it fell naturally into three main sections. Do you agree?

Referring to the first part of “The Wizardry of Id” (D. Kushner, August 2002, IEEE Spectrum)
The article introduces Id as a successful company influential upon everyday computing through technologically innovative games, which it says needed skill and cunning to bring to the PC market.
It introduces the 4 founders who wrote games for PCs at a time when the market was dominated by games consoles more suited to the purpose. They began by trying to recreate the hit game Super Mario Brothers 3.
This part of article seemed to me to be in two parts.

Activity 32
In your own words, write a few sentences about how Carmack managed to speed up the scrolling. Think about the keywords ‘speed’, ‘memory’ and ‘image updating’.

Carmack figured out how to draw only a few 16x16 tiles every frame. The then new EGA graphics cards could hold several screens’ worth of low resolution graphics, and the fact that they could move data around in this memory very quickly. He wrote a graphics engine that exploited these properties by assembling a complete screen in the video memory, adding tiles to the edges as necessary when the game player ‘moved’, then changing the starting address the starting address of the screen image origin to effect ‘scrolling’. This saved the PC having to redraw tens of thousands of pixels every time the player ‘moved’.

Activity 33
(a) What is raycasting? How did Carmack simplify the technique? (b) How did Carmack obtain sufficient shades to produce an adequate display of the gaming environment?

(a) Raycasting is the rendering of scenes by extended lines from the players position to the direction in which they are facing. When a line strikes an object surface, a pixel is rendered in an appropriate colour at that position (this way, object surfaces that would not be seen anyway are not rendered, saving a great deal of time.
Carmack simplified this technique by only rendering walls, and making them all the same height. This meant that instead of having to raycast using up to 64,000 lines (one for each pixel in a 320x200 screen), he only needed to raycast only the horizontal plane, which could be done with just 320 lines.
(b) Carmack obtained sufficient shades to produce an adequate environment display by restricting the colour palette used to 16 shades each of 16 colours (the new VGA cards allowed a maximum of 256 colours on the screen). The darkest shades of these colours were applied in far sections of a room; lighter shades for those closer.

Activity 34
Spend a few minutes reviewing your work on this extract, including your responses to Activities 31- -33. Given my comments on the activities, how satisfied were you with your answers? Did you find parts of the extracts difficult to understand? If so, which?

When compared to the comments given at the end of Activities 31 to 33, I am fairly satisfied with the answers that I have given – with the possible exception of 31, where I could have better described the content of the first part of the article. I extracted relevant technical details (by highlighting text in the study book), and my answers to 32 and 33 compared fairly well with the given comments.
I found the article moderately easy to read, as I had some basic prior knowledge of both video cards, and what raycasting (or “raytracing”) was. I do agree with the study material authors comments about quoted figures not being particularly helpful though!

No comments:

Post a Comment