Computer Graphics Introduction Introduction Computer graphics is concerned with all aspects of producing pictures or images using a computer. The field began humbly almost 50 years ago, with the display of a few lines on a cathode-ray tube (CRT); now, we can create images by computer that are indistinguishable from photographs of real objects. APPLICATIONS OF COMPUTER GRAPHICS The development of computer graphics has been driven both by the needs of the user community and by advances in hardware and software. The applications of computer graphics are many and varied; we can, however, divide them into four major areas: 1. Display of information 2. Design 3. Simulation and animation 4. User interfaces Although many applications span two or more of these areas, the development of the field was based on separate work in each. A GRAPHICS SYSTEM A computer graphics system is a computer system; as such, it must have all the components of a general-purpose computer system. Let us start with the high-level view of a graphics system, as shown in the block diagram in Figure There are five major elements in our system: 1. Input devices 2. Processor 3. Memory 1 Compu uter Graphics Introducti I ion 4. Fra ame bufffer 5. Ou utput devvices Pixels s and th he Frame Buffe er Prese ently, almost all graphiccs system ms are raster b based. A picture is produce ed as an n array —the — rastter— of picture p elements, or pixels s, within the t graphiccs system m. Each pixel corrresponds to a lo ocation, o or small area, intthe image. Collectivvely, the pixels p are e stored in a part of o memorry called the frame e buffe er. The frrame bufffer can b be viewed as the core ele ement of a graph hics system. Its reso olution—tthe numb ber of pix xels in th he frame e buffer— —determin nes the dettail that you y can see s in the e image. The depth, or pre ecision, of o the fram me buffer, defined as a the nu umber off bits thatt are use ed for eacch pixel, determin nes propertties such as how many co olors can n be reprresented on a giv ven syste em. For exa ample, a 1-bit-dee ep frame e buffer allows a only two co olors, whe ereas an 8bit-deep frame buffer b allo ows 28 (2 256) colo ors. In full-color syystems, th here are 24 (or morre) bits pe er pixel. Such S sysstems can n display sufficien nt colors to t represe ent most im mages rea alistically y. 2 Computer Graphics Introduction Objects and Viewers Two basic entities must be part of any image-formation process, be it mathematical or physical: object and viewer. The object exists in space independent of any image-formation process and of any viewer. In computer graphics, where we deal with synthetic objects, we form objects by specifying the positions in space of various geometric primitives, such as points, lines, and polygons. In most graphics systems, a set of locations in space, or of vertices, is sufficient to define, or approximate, most objects. For example, a line can be specified by two vertices; a polygon can be specified by an ordered list of vertices; Every imaging system must provide a means of forming images from objects. To form an image, we must have someone or something that is viewing our objects, be it a person, a camera, or a digitizer. It is the viewer that forms the image of our objects. Light and Images The preceding description of image formation is far from complete. For example, we have yet to mention light. If there were no light sources, the objects would be dark, and there would be nothing visible in our image. Light travels in straight lines, from the sources to those objects with which it interacts. An ideal point source emits energy from a single location at one or more frequencies equally in all directions. More complex sources, such as a light bulb, can be characterized as emitting light over an area and by emitting more light in one direction than another. 3 Compu uter Graphics Introducti I ion Image e Forma ation Mo odels There e are mu ultiple ap pproachess to how w we can n form im mages fro om a sett of objectss, the light-reflectin ng properrties of th hese obje ects, and the prope erties of the t light so ources in the scene. We ca an start building an n imaging g model by b following light fro om a sourrce. Ray trracing and a pho oton ma apping Theyy are imag ge-forma ation tech niques th hat are ba ased on tthese ide eas and th hat can forrm the ba asis for prroducing compute er-genera ated imag ges. We can c use the t ray-traccing idea to simula ate physiical effec cts as com mplex as we wish, as long as we are willing to o carry ou ut the req uisite com mputing. THE P PROGRA AMMER R'S INTE ERFACE E The iinterface between n an appliication prrogram and a grap phics sys stem can be specifie ed throug gh a set of functi ons that resides in a gra phics library. The ese nterface (API). The specificcations are a called d the ap pplication n program mmer's in T applica ation prog grammer's model of the sy ystem is shown in n Figure below. The T 4 Compu uter Graphics Introducti I ion applica ation prog grammer sees onlyy the API and is thus shiellded from m the deta ails of both the hard dware an nd the so oftware im mplementtation of the graphics libra ary. The software drrivers are e responssible for interpretin i ng the ou utput of the t API and a convertting these . e data to a form th hat is und derstood by the pa articular hardware h GRAP PHICS ARCHITE A ECTURES On o one side of o the AP PI is the a application program m. On the e other side s is som me combin nation of hardware e and sofftware that implem ments the e function nality of the t API. 1. D Display Process sors The earliest attempts s to bu ild special-purpose graph hics sys stems we ere concern ned primarily with h relieving g the gen neral-purp pose com mputer fro om the ta ask of refrreshing the t display conttinuously. These display y processors had h conven ntional arrchitecturres (Figu re 1.29) but included insstructions s to display primitivves on the e CRT 5 Compu uter Graphics Introducti I ion 2. P Pipeline Archite ectures The concept of pipelin ning is illu ustrated in Figure e 1.30 forr a simple e arithme etic calculation. In our o pipeliine, there e is an adder a and d a multiiplier. If we w use this t configu uration to o compu ute a + (b * c), c then the calcculation takes one o multiplication an nd one addition th he same amount of work rrequired if we use ea single p processo or to carry y out both h operations. How wever, su uppose th hat we ha ave to carryy out the same co omputatio on with many m values of a,, b, and c. c Now, the t multiplier can pa ass on the results of its calcu ulation to the adde er and ca an start its i next multiplica m tion while e the add der carries out the second step s of th he calculation on the first set of da ata. Hence, wherea as it takess the sam me amou unt of time to calc culate the e results for any one o set of d data, whe en we are e working g on two sets s of da ata at one e time, ou ur total tim me for calcculation iss shortened marke edly. Here the rate e at which h data flo ows throu ugh the sysstem, the throughp put of the e system m, has been doubl ed. Note e that as we add mo ore boxess to a pipeline, the e latency of the sy ystem inccreases and we must balance e latencyy against increase d through hput in evaluating g the perfformance e of a pipeline. We ccan consttruct pipe elines for more com mplex arithmetic ccalculations that will w 6 Compu uter Graphics Introducti I ion afford d even greater g increases in throug ghput. Off course, there is no pointt in building g a pipeline unles ss we wi ll do the same operation on many y data se ets. where la But tha at is just what w we do in co omputer graphics, g arge sets s of verticces must be e processsed in the e same m manner. The G Graphics s Pipelin ne We sstart with h a set of o objectss. Each object comprisess a set of o graphical primitivves. Each h primitiv ve comprrises a set s of ve ertices. W We can think t of the t collectio on of prrimitive ty ypes and d vertice es as defining th e geome etry of the t scene. In a co omplex scene, s th here ma ay be thousands— —even millions— —of verticess that deffine the objects. o W We must process all these e vertices in a similar manner to form an image e in the fframe bufffer. If we e think in terms off processing the geo ometry of o our ob bjects to obtain an a image e, we can n employ y the blo ock diagram m in Figu ure 1.31, which shows the four major stteps in the imaging processs: 1. Ve ertex proccessing 2. Clipping an nd primitiv ve assem mbly 3. Ra asterizatio on 4. Fra agment processin p ng 7 Computer Graphics Introduction Exercise: An interesting exercise that should help you understand how rapidly graphics performance has improved is to go to the Web sites of some of the GPU manufacturers, such as NVIDIA and ATI, and look at the specifications for their products. Often the specs for older cards and GPUs are still there. How rapidly has geometric performance improved? What about pixel processing? How has the cost per rendered triangle decreased? 8