december/january 1996

GAME DEVELOPER MAGAZINE GGAMEAEM GAME PLAN

Spare a Quarter for Microsoft? Editor Alex Dunne irst, it conquered the desktop. of the game. This kind of work could be [email protected] Then it set its sights on the done by one or two developers familiar Managing Editor Tor Berg [email protected] Internet. Now Microsoft is tar- with the game engine, and perhaps a spe- Editorial Assistant Chris Minnick geting the arcade? That’s right. cialist in coin-op development. Market- [email protected] Microsoft is launching an ini- ing doesn’t take a very big bite out of Contributing Editors Larry O’Brien tiative to make Windows the your budget in the coin-op world, so [email protected] operating system for the next you’d save some money on that front. All Chris Hecker [email protected] generation of coin-op games. in all, you’re not looking at a tremendous David Sieks UnveiledF at Microsoft’s recent Judge- outlay to port a game to coin-op using [email protected] ment Day event (its second annual Win- Microsoft’s model. Web Site Manager Phil Keppeler dows 95 games showcase), the initiative That begs the question: What kind [email protected] is still in its early stages, but could turn of cash could you expect from a coin-op Cover Photography Carter Dow Photography the coin-op industry on its ear if it gains port of a Windows-based game? 4th enough momentum. Wave, a market research firm, worked up Publisher Veronica Costanza Basically the plan goes like this: A some numbers in an attempt to answer Group Director Katie Brennan number of hardware companies would that. 4th Wave assumed an installed base Special Projects Manager Nicole Freeman produce Windows-based coin-op of approximately 15,000 Windows-based [email protected] machines, which would probably be coin-op machines in the first year of Advertising Sales Staff powered by Pentium Pros or equivalently availability (starting in mid-1997) and Western Regional Sales Manager powerful processors. You, the game projected that each machine would run a Steve Nikkola (415) 905-2256 [email protected] developer, would ship games for the little over two games during that time- Western Account Manager coin-op market in the same manner that span, creating a market for about 32,000 Barbara Wren (415) 356-3362 you currently ship into the home market. title-units. If you assume a traditional [email protected] After telling the manufacturer of the distribution spread, then of the top 15 Eastern Sales game which standard controls your game games, one would sell about 9,600 units; John Travers (212) 615-2682 requires, and perhaps creating the jazzy four would sell about 3,100 units each; [email protected] artwork for the playfield and marquee, and ten would sell approximately 1,000 Marketing Manager Susan McDonald the manufacturer would just slap the units each. Assume conservatively that Marketing Graphic Designer Azriel Hayes proper components into place and ship your title is in the bottom 10—that’s Advertising Production Coordinator Denise Temple your game. 1,000 units sold at about $750 each, of Director of Production Andrew A. Mickus This is a big leap from today’s coin- which you, the publisher, get a fair chunk Vice President/Circulation Jerry M. Okabe op games, most of which require special- (probably around two-thirds). That’s Group Circulation Manager Mike Poplardo ized hardware under the hood. In many about a $500K return for your two or Assistant Circulation Manager Jamai Deuberry cases, this hardware acts as a form of three person porting effort. Granted, Subscription Marketing Manager Melina Kaplanis copy protection so that the game can’t be these are extremely rough numbers, but Newsstand Manager Eric Alekman pirated. Microsoft’s plan would remove it’s something to chew on. Reprints Stella Valdez (916) 729-3633 the need for game-specific hardware and Microsoft makes no bones about in its place use an as-yet-unspecified another aspect of this initiative that Chairman/CEO Marshall W. Freeman form of copy protection. benefits them greatly. A Windows-based President/COO Donald A. Pazour In terms of your resources as a game in an arcade is an advertisement for Senior Vice President/CFO Warren “Andy” Ambrose developer of PC games, it probably the home version of the game. That’s Senior Vice Presidents David Nussbaum, Darrell wouldn’t involve many additional per- great for you, because it could boost your Denny, Ted Bahr, Wini D. Ragus, Regina Ridley son-hours of time to tweak a game for sell-through to consumers. It’s great for Vice President/Production Andrew A. Mickus coin-op using this model. You’d want to Microsoft because people have to buy Vice President/Circulation Jerry Okabe simplify your game for the arcade ver- copies of to play your game. Senior Vice President/ sion, and tune it up to get as much speed That demon seems to lurk behind every- Software Development Division Regina Starr Ridley out of it as you could. You would also thing they do, doesn’t it? ■ want to change your levels around so that Alex Dunne Miller Freeman they weren’t identical your home version Editor A United News & Media publication

6 GAME DEVELOPER • DECEMBER 1996/JANUARY 1997 http://www.gdmag.com/ SEZ U!

WHICH WAY DO I GO? worked. I originally tested the code in the article Developer. He touched upon many key points Dear Editor: on both IPX and modem servers, but I admit that I was pleased to read about. ould you recommend developing that the DirectX 1.0 DirectPlay implementation I ordered 3D Studio Max and am happier with games for DOS using Watcom C/C++ acted a little flaky at times. this investment having read such a review from W10.6 with DOS/4GW, or games that someone who clearly knows what constitutes an run on Win32s using Visual C++ 4.1 and the BENCHMARKING COMPILERS outstanding program. DirectX 2 SDK? Dear Editor: Anonymous Dan Mintz read Chris Hecker’s article “More Compiler Via Internet Via Internet Results, and What To Do About It” in the IAugust/September 1996 issue and have a DELAY OF GAME Chris Hecker replies: question. Dear Editor: It actually doesn’t matter. The important parts How were the timings measured? Did he read Dan Teven and Vincent Lee’s article of game programming, such as mathematics, count clock cycles from the assembler code, or “Optimizing CD-ROM Performance under user interface, gameplay tuning, artificial intel- did he run timed benchmarks? If he ran timed IDOS/4GW” (August/September 1996). We ligence, and so on, are totally platform indepen- benchmarks, what operating systems were used play all of our game’s music off of CD audio dent. I’d say start with whatever is easiest or for each test? tracks, and when I use the STOP and PLAY com- cheapest, and learn to write good code. If you Also, his Macintosh bias needn’t have been mands, there’s a long delay (the game stops for do that, you can write for whatever platform included in the article. The PowerPC 604 is not a period of one to two seconds). MSCDEX docu- you’d like. “a pretty fair comparison” to a Pentium. Every- mentation states that these two functions one (except Hecker apparently) gives the “fair should return immediately, but that isn’t hap- DIRECTPLAY DIFFICULTY comparison” nod to the PowerPC 604 vs. the pening. Any ideas? Dear Editor: Pentium Pro at similar clock speeds. I would be Pablo Testa enjoyed Michael Morrison’s article “Network- interested in those results. Via Internet ing Your Game Using DirectPlay” (June/July Randy Rynkewicz I1996). I used it as a tutorial for learning Via Internet Dan Teven replies: DirectPlay. I discovered a problem when running Although you’re working with the CD audio calls the TicTacToe game in conjunction with the TCP Chris Hecker replies: and not using the “seek” call, this problem and IPX service providers. Morrison’s code was I timed the functions by doing a bunch of loops sounds very similar to one Vince Lee and I men- failing in the IDirectPlay::EnumPlayers call. I and using Microseconds on the Mac and tioned in our article. Because the MSCDEX notice he calls IDirectPlay::Open prior to call- QueryPerformanceCounter on Windows 95. I interface is synchronous and some calls may ing EnumPlayers, which the DirectPlay docu- timed the non-Windows 95 compilers’ outputs not return quickly, you need to use a multi- mentation warns against. I modified the code to by linking in their object modules into my Win- threaded architecture if you want to keep these delay calling Open until after EnumPlayers was dows 95 timing program. Most of the compilers calls from slowing down your game. Whenever called, and everything worked fine (at least in output COFF objects, and I converted the others. you want to stop a track or play a new one, your the TCP and IPX worlds). I assume Morrison’s I’ve never been accused of having a Macin- program should create a new thread to issue code worked as published when using the tosh bias before. By “a pretty fair comparison,” the MSCDEX call. Meanwhile, the rest of your modem server provider. Why is that? I meant my 132Mhz PPC and the 133Mhz Pen- program can continue to execute. Matt D’Ercole tium were similar systems from a clock-rate Windows 95 features multithreading support. Via Internet and memory standpoint. Cross-architecture If you’re developing for real-mode DOS, there comparisons are basically impossible to get are commercial libraries available. Multithread- Michael Morrison replies: right anyway, so it was meant as more of a side ing libraries also exist for the DOS/4GW, Phar I double checked both the DirectX 1 and 2 docu- comment than a well-researched result. Lap, and Causeway DOS extenders. mentation and they both mention calling The length of the delay also will depend on the EnumPlayers after calling Open to connect to a SIEKS SIZZLES CD-ROM driver you’re using. Some drivers dis- session. In fact, I’m not sure how DirectPlay Dear Editor: able interrupts for long periods of time and can could know about other players without being avid Sieks wrote an intelligent assess- interfere with a preemptive multitasker. If this connected to a session via Open. However, it ment of 3D Studio Max in the is the case, creating another thread won’t cure sounds like the change you made to your code DAugust/September 1996 issue of Game the delay.

GAME DEVELOPER • DECEMBER 1996/JANUARY 1997 9 http://www.gdmag.com BIT BLASTS

Dear Santa... Tor Berg

paths that are fully editable. And support librium has also included bandwidth X-ponents for QuickDraw 3D for Windows lets conservation tools for multimedia and MicroHelp Inc. has shipped its new you import and export 3DMF objects. web graphics. Over 90 file formats are development package, Game+Multime- Infini-D 3.5 for the MacOS is supported, and the list is optimized for dia X-ponents. X-ponents are program- available now. The Windows 95/NT the Windows 95 and NT environments. ming objects that encapsulate Micro- version is scheduled to ship at the end of DeBabelizer for Windows will soft’s DirectX programming interfaces, November. List price is $649. ship in the last quarter of 1996, and combining object-oriented development ■ Specular International Ltd. will list at $595. practices with the power and speed of Amherst, Mass. ■ Equilibrium accessing hardware directly. (413) 253-3100 Sausalito, Calif. http://www.specular.com X-ponents are optimized for Inter- (415) 332-4343 http://www.equilibrium.com net download and are based on the ActiveX framework. They are divided MotionStar into component families including: For more realistic character animation, Geppetto MhDirectDraw, which encapsulates you might want to look into a magnetic QuantumWorks has made its per- interfaces that directly access video mem- motion sensor. Ascension Technology formance animation system avail- ory and the bit manipulation capabilities Corp. has just released it’s MotionStar able to the public. of the hardware; MhDirectPlay, which Wireless magnetic tracker. Geppetto is designed for lip sync, eases the connectivity of games over Wireless technology has really facial control, and overall expressiveness. modem links or networks; MhDirect- improved this magnetic tracking system. The built-in gesture recognition system Sound, which encapsulates the Direct- Although magnetic tracking is cheaper can map any input data combination to Sound and DirectSoundBuffer interfaces, than optical systems, the cabling was any set of control points on the avatar’s enabling hardware and software sound heavy and restricted motion. The geometry. Geppetto has the advantage mixing and playback; and others. MotionStar yields real-time results and of being open and extensible. 3D appli- MicroHelp Game+Multimedia X- doesn’t require a line-of sight between cation developers can integrate Geppet- ponents lists for $249. the sensors and the transmitter. to libraries into their own applications, ■ MicroHelp Inc. The tracker has a range of up to 20 and the system supports input devices Marietta, Ga. feet diameter, with the transmitter in from the high end (Motion Analysis’s (770) 516-0899 the center. Up to 14 sensors are mount- Face Tracker) to the low end (off-the- http://www.microhelp.com ed at key points on the model. Motion shelf MIDI controllers). Geppetto also cues can be derived for animation soft- has the ability to output sound and ani- Infini-D 3.5 ware from Alias/Wavefront, Softimage, mation data as .AVI image files, 3D Specular International Ltd. is set to MediaLab, 3D Studio, and others. dynamic deformation databases, 3D release a Windows 95/NT version of its ■ Ascension Technology Corp. function curves, MIDI sound events, Infini-D 3.5 3D modeling and render- Burlington, Vermont and .WAV files. ing software. Following the MacOS ver- (802) 860-6440 Geppetto runs on a high-end Win- http://www.ascension-tech.com sion that shipped last summer, this dows 95/NT box. The system is avail- release will feature full support for able in a range of configurations, from a Apple’s QuickDraw 3D and QuickTime DeBabelizer software-only product—which includes on a Windows platform. Also on the moving-to-Windows front, the MIDI controller and a year of sup- Infini-D 3.5 offers a spline-based Equilibrium, maker of the DeBabelizer port—sold for $8,000, to a complete modeler and photorealistic rendering. automated graphics processing software turnkey package—including the Face Interesting effects include animated for the MacOS, has developed a Win- Tracker, road cases, a spycam system, Boolean rendering, with which you can dow 95/NT version of its product. and rack-mounted hardware—for about “carve” your 3D objects using any 3D DeBabelizer automatically prepares $50,000. shape as a tool, and animated lens flare images, animations, and digital video ■ QuantumWorks Corp. effects that you can edit on the screen. through file-format conversion, batch Sherman Oaks, Calif. Animations are handled with an event- processing, color-palette reduction, (818) 906-3322 http://users.aol.com/setpci/qw.htm based sequencer and on-screen motion image processing, and scripting. Equi-

12 GAME DEVELOPER • DECEMBER 1996/JANUARY 1997 http://www.gdmag.com BEHIND THE SCREEN

Physics, Part 2: Angular Effects

just want to block the door with them rotational) effects in today’s games that take advantage of the something heavy, so the bad guy games is that programmers perceive expressive power of angular effects, or can’t get in. Is that too much to ask? angular physics to be difficult to under- at the very least, let you shoot your I want to flip over his car with a stand and implement. High-school friend’s feet out from under her in a carefully placed explosion, I want to physics courses (where we all learned deathmatch game. jam the huge gears to which I’m F=ma) usually don’t cover angular strapped before they crush me, and effects, and it’s not immediately clear Recap I want to rig up a seesaw-type thing how to translate a force applied to an Whenever I’m writing a series of Ito catapult a nice flaming present over object into a spin for that object. While columns on a single topic, I always his castle’s protective wall. You might the dynamics of angular motion are reread my last column before starting the think that my antagonist is the one stop- slightly more difficult to understand latest one so I can figure out where I left ping me from doing these things, but the than the dynamics of linear motion, off. I just got finished doing that with person stopping me is actually the pro- they’re not that much more complicated. the first part of this series on physics, grammer behind the game’s physics Anybody who can implement a linear and wow, we covered a lot of ground, engine, because at the heart of each of physics engine based on the material we and without any code or references to these tasks lies an angular effect. Few covered in the last column will be able boot! Before we get started, let’s quickly games today try even to model angular to implement one that supports angular review the material from last time. effects, let alone try to get them right. effects based on the information in this Table 1 contains the important The main reason for the lack of column. Hopefully, once this knowl- results for doing linear rigid body support for angular (you might call edge is out there, we’ll start to see dynamics. Eq. 1 shows that the position vector (denoted by r), the velocity vector Table 1. Important Equations from Part 1 of This Series (v), and the acceleration vector (a) are all related by derivatives (and integrals in Eq. 1 Relationship of d 2r dr˙ dv the opposite direction). As a reminder, position (r), velocity (v), = = = = = we denote differentiation with respect to 2 ˙˙r v˙ a and acceleration (a) dt dt dt time with a dotted vector, so “ rÇ ” is the same as dr/dt, and “ ÇÇr ” is the same as the second time derivative. Eq. 2 shows how Eq. 2 Force (F) equals the dp d(mv) force is related to linear momentum derivative of linear F = p˙ = = = mv˙ = ma momentum (p), or dt dt (mass times velocity), mass, and accelera- mass (m) times tion. Eq. 3 gives the definition of the acceleration center of mass, which is the point where all the masses and distances balance each Eq. 3 Center of Mass (CM) CM = i i other out. Eq. 4 says that the total linear Mr ∑ m r momentum for a rigid body is the sum of i all the momentums, which, luckily for us, Eq. 4 Total linear momentum CM simply equals the momentum of the cen- T i i d(Mr ) CM equals the momentum p = ∑m v = = Mv ter of mass (CM). Eq. 5 is the real gem; of CM i dt it uses Eq. 4 to show that the accelera- tion of our object’s CM is related to the Eq. 5 Total force equals the T = T = CM = CM total mass (M) times F p˙ Mv˙ Ma total force–the vector sum of all forces CM acceleration currently acting on our object–by a sim- ple scalar, the total mass of the object.

14 GAME DEVELOPER • DECEMBER 1996/JANUARY 1997 http://www.gdmag.com So, to summarize the results from add another kinematic quantity, orienta- the last column, we first find the total tion (denoted by Ω, capital omega), to Chris Hecker force on our CM by summing all the that configuration so we can support our forces applied to the body (including angular effects. To define Ω, we need to things like gravity, the bad guy’s tractor pick a coordinate system fixed in our To properly model beam, the nearby explosion, our engine rigid body and a fixed world coordinate thrust, whatever). Then, we divide this system, and specify Ω as the angular dif- vector sum by the total mass to get the ference between them in radians, as

CM acceleration, and then integrate that shown in Figure 1. In the figure, xw,yw acceleration over time (using the numer- are the world axes, and xb,yb are the body physics in your game, ical integration techniques mentioned at axes. Ω is positive in the counterclock- the end of the last column) to get our wise direction. At this point, it should be body’s new velocity and position. clear why we’re learning 2D dynamics Although Eq. 5 is a nice piece of before moving up to 3D: The orienta- work, you’ll notice that it contains no tion in 2D is just a scalar (the angle you have to concept of where the forces act on the between the coordinate systems in radi- body, which is the key to figuring out ans), while specifying an orientation in how those forces rotate the body. Eq. 5 3D is much more complicated. isn’t wrong—it’s exactly right for calcu- As our body rotates in the world, understand rotational lating the linear acceleration—we’re just Ω changes. This change leads us to our missing half the story. But let’s start at next new kinematic quantity, angular the beginning… velocity (denoted by ω, lowercase omega). In contrast with the position What’s Your Angle? and its linear velocity, we don’t usually effects. See how The last column ignored rotation, so we signify the angular velocity by “ΩÇ .” only needed the position vector and its However, we sometimes signify the derivatives to describe our rigid body’s velocity’s time derivative, or angular configuration in 2D. We now need to acceleration—which is our final new kinematic quantity—with “ωÇ ,” and angular momentum, Figure 1. The Definition of Ω sometimes with an α (lowercase alpha). y Don’t blame me, I don’t make these w x w rules, and every book I read has a slightly different convention. Our yb angular analog to Eq. 1 is torque, and other x b d 2Ω dω Ω = = ωÇ = α yw 2 dt dt (Eq. 6) Much like Eq. 1, if we differentiate forces can be ω with respect to time, we get α; and if we integrate α over time, we get ω, and xw so on. Clearly, as in our analytic integra- tion example for linear movement in the previous column, if we know the angular modeled in a game.

http://www.gdmag.com GAME DEVELOPER • DECEMBER 1996/JANUARY 1997 15 BEHIND THE SCREEN

Figure 2. C=Ωr B =ω OB (Eq. 7) v r ⊥ d (Ωr ) dΩ = r =ωr Eq. 7 introduces a bunch of new dt dt (Eq. 8) notation, so let’s take it apart one piece The radius drops out of the deriva- at a time. First, I’m using superscripts tive because it’s constant (B is simply C to denote which parameters “belong” to rotating, not translating as well), and the which points, so vB is the velocity of time derivative of Ω is ω by Eq. 6. Thus, B point B in our body. Similarly, r OB the magnitude of B’s velocity vector is ωr. means the vector from the origin of our If we look at Eq. 7, we see that it Ω r body O to point B. The funny upside- gets the magnitude correct because the down T subscript is the “perpendicular perpendicular operator clearly does not O operator,” which takes a vector (like r in effect a vector’s length, and rOB is the Eq. 7) and rotates it counterclockwise radius vector from the origin to B. We’re by 90 degrees. In other words, it creates halfway done. acceleration α, we can integrate it twice a new vector that’s perpendicular to the To show that the direction of the to find the new orientation; but the key old vector. In 2D, the perpendicular of velocity in Eq. 7 is correct, we’ll start by is we need to know α to do this. a vector (x,y) is just (-y,x), as you can convincing ourselves the velocity vector’s As you might expect, our goal for easily verify on a piece of graph paper. direction must be perpendicular to the this column is to derive angular analogs I’ll say more on this operator shortly. radius vector. This assumption makes for each of the linear physics equations Finally, the perpendicular vector is sense intuitively, because a point rotating in Table 1, and then link the linear and scaled by the angular velocity ω to give around another fixed point can only move angular equations together so we can the linear velocity vB. So, in English, perpendicularly to the vector between the take a given force on our object and use Eq. 7 says the velocity of a point on a points at any instant; it can’t move closer it to calculate the linear acceleration a, rotating body is calculated by scaling or farther away, or the movement and the angular acceleration α. Finally, the perpendicular vector from the origin wouldn’t be a simple rotation. We could we can numerically integrate these accel- to the point by the angular velocity. make this assumption rigorous using a erations to find our body’s new position How in the heck did I come up with tiny bit of vector calculus, but I’m running and orientation. this thing? Well, I read about it in a out of space, so we’ll consider ourselves The first way we’ll link the linear book, but that’s obviously not very illu- convinced. (If you want to prove it to and angular quantities together is with a minating, so let’s prove for ourselves yourself, try differentiating the dot prod- neat and not-so-obvious trick using angu- that it works. uct of a fixed length vector with itself.) lar velocity. When we’re doing dynamics, We’ll prove Eq. 7 does what I say it Finally, we need to make sure the we often need to find the velocity of an does in two stages. First, we’ll prove that sign of the velocity vector is correct, arbitrary point on our object. For exam- the magnitude of the resulting velocity since there are actually two vectors of the ple, when we cover collision response, vector is correct; then, we’ll prove it’s same length that are perpendicular to the we’ll need to know the velocity of the col- pointing in the right direction. To prove radius: v and -v. Since we’re measuring liding points to figure out how hard they the first part, we’ll use Figure 2. Figure 2 Ω in the counterclockwise direction, ω is hit each other. If our bodies aren’t rotat- shows our point B moving Ω radians positive when the point is rotating coun- ing, the velocity of any point in the body during the body’s rotation, with the terclockwise. The perpendicular operator is the same; we can just keep track of the radius vector from the origin to B as r velocity of the body’s CM and be done units long. B has moved C units of Figure 3. Linear Velocity with it. However, if our bodies are rotat- arclength on the circle, where C=Ωr by from Angular Velocity ing, then every point in them might have the definition of radians. (Radian mea- a different velocity. Obviously, we can’t sure is the measure of arclength scaled by keep track of the velocity of each of the the radius of the circle. The circumfer- infinity of points in our rigid body, so we ence of a circle is the well-known formu- B ω OB need a better way. la 2πr, because it’s 2π [or 360 degrees] v = r⊥ A simple way to find the linear worth of arclength.) velocity of any point inside an object A point’s speed is its change in B uses that object’s angular velocity. Let’s position over time. Thus, we can find B’s first cover the case of a body rotating speed—which is another way of saying ω rOB with one point, the origin O, fixed, so the magnitude of its velocity vector—by the body is rotating but not translating. differentiating the equation for its move- O Eq. 7 shows how to calculate the velocity ment with respect to time. C=Ωr is the for a point B on this rotating body. equation for its movement.

18 GAME DEVELOPER • DECEMBER 1996/JANUARY 1997 http://www.gdmag.com points in the counterclockwise direction with the point’s linear momentum. This “rotating around” point A; that “rotating- relative to the radius vector. So, as Fig- operation is called the “perp-dot prod- around force” is called the torque. Eq. 11 ure 3 shows, Eq. 7 checks out. uct.” (It’s sort of the 2D analog to the lets us calculate the torque—and hence We can extend Eq. 7 to cover 3D cross product, but that discussion the angular momentum, if we integrate simultaneously rotating and translating will have to wait for another time.) that torque—from an applied force and bodies. We will consider any movement If you take Eq. 10 and draw out its position of application. of a rigid body as a simple translation of what it’s doing on a piece of paper—I’ve However, we still don’t have any a single point in the body and a simple drawn an example in Figure 4—you’ll relationship between the torque and the rotation of the rest of the body around see it produces a number that’s a mea- kinematic angular quantities we need to that point. This is known as Chasles’ sure of how much of B’s linear momen- spin our object around—such as the angu- Theorem, for those keeping score. tum is “rotating around” A. That is, if lar acceleration, angular velocity, or orien- Chasles’ Theorem breaks up our B’s linear momentum is aiming right at tation; so we can’t really do anything with motion into linear and angular compo- A or directly away from A, Eq. 10 is 0 our newfound dynamic quantities until nents. We consider the origin O in Eq. 7 (since r-perpendicular will form a right we’ve derived a few more equations. as the single translating point, then use ω angle with p, and the dot product will be to keep track of the rotation around O, 0). As more of B’s momentum is direct- The Moment We’ve All Been which gives us the general form of Eq. 7. ed perpendicular to A, Eq. 10 produces a Waiting For B = O +ω OB larger angular momentum. As you can Before we can examine the relationship v v r ⊥ (Eq. 9) see in Figure 4, the dot product in Eq. between the dynamic and kinematic Eq. 9 says we can calculate the 10 is measuring the cosine of θ between quantities, we need to define the total velocity of any point in a moving body by rAB-perpendicular and pB, which is what angular momentum, much as we have taking the known linear velocity of our you’d expect from a dot product. How- defined the total linear momentum in Eq. body’s origin and adding to it the velocity ever, if we look at it another way, the 4. I didn’t forget the angular equivalent of generated from the body’s rotation. perp-dot product is measuring the sine the CM in Eq. 3; it will come to us in the of φ between our original unperpendicu- total angular momentum equation. A Moment-us Occasion larized rAB and pB (the sine is another The total angular momentum about Now we’re in a position to work on the clue to the similarity between the perp- point A is denoted LAT and is defined by angular analog of Eq. 2, the force equa- dot and the 3D cross product). Eq. 12. tion. We’ll start by defining the angular Whichever way we look at it, Eq. 10 is AATii=◊ momentum, LAB, of one point, B, about producing a measure of how much of B’s L  rp^ i another point, A, as follows: linear momentum is in the “rotating- Aiii AB AB B around direction” with respect to A. =◊rvm L=◊rp  ^ ^ (Eq. 10) In the same way we used the linear i (Eq. 12) The angular momentum of a point momentum’s derivative to define force, Eq. 12 is a summation of all the differs from the linear momentum of a we’ll use the angular momentum’s deriv- angular momentums of all the points, as point in that the angular version is mea- ative to define force’s angular twin, measured from point A. On the right- sured from a specific position in space. torque (denoted by τ, lowercase tau). hand side, I’ve used the definition of linear

That is, while linear momentum is just a AB B momentum to expand p into mass times AB property of a given point (its mass times dL d()r^ ◊ p velocity (mv) because we’re going to t AB == its velocity), the angular momentum of dt dt manipulate this term to turn Eq. 12 into the point must be measured from anoth- something more manageable. As it stands, AB B AB B er place in the world. The superscript =◊rarF^^ m =◊ notation in Eq. 10 shows this. The nota- (Eq. 11) Figure 4. Angular Momentum tion LAB says that the first superscript, A, To save space, I actually cheated a bit is the point about which the momentum in Eq. 11 and left out a couple of tricky is measured, and the second superscript, steps involving the product rule for deriva- B, is the point whose angular momen- tives. Still, when all is said and done, the pB tum is being measured. Think about an torque ends up being related to the force AB θ φ AB B arrow from the first superscript to the at a specific point by the perp-dot product. L = r⊥ p second; A is “looking at” B’s momen- At last, we find a dynamics equation tum. This arrow from A to B is the that uses the point where a force was B radius vector between the two points, applied, which is ignored in the equa- AB designated by r AB. So, the angular tions for linear movement. Eq. 11 uses r momentum of a point is the dot product the perp-dot product to measure how of the “perpendicularized” radius vector much of the force applied at point B is A

http://www.gdmag.com GAME DEVELOPER • DECEMBER 1996/JANUARY 1997 19 BEHIND THE SCREEN

if we want to calculate the total angular I’ll describe Eq. 13 one step at a 13 constant for each body, so we can cal- momentum for our object, we’d have to time. First, we substitute Eq. 7 into Eq. culate it offline before we begin. To sum all of the angular momentums for 12 to get the first summation in Eq. 13. rephrase in English, IA is the sum of the each of the points. For a rigid body com- This substitution lets us write the angu- squared distances from point A to each posed of surfaces rather than separate lar momentum in terms of the angular other point in the body, and each points, we’d have to perform an integra- velocity. Next, we bring the ω out of the squared distance is scaled by the mass of tion instead of a discrete summation. summation because it’s the same for all each point. Much like the CM, if the Luckily, we can simplify this calcu- the points (the angular velocity is body is continuous rather than made lation by introducing a new quantity, defined for the body, not the points from discrete points, the summations called the moment of inertia, in the same individually), and we write the mass for above would turn into integrals. Howev- way we introduced the CM to simplify point i on the left-hand side so we can er, the moment of inertia would still the equations for linear movement. We see that we’re really taking the dot prod- exist and be defined the same way. start by remembering that Eq. 7 gives us uct of the radius vector with itself. This The definition of the moment of an alternate way of writing the velocity dot product is just the radius vector’s inertia about a point is a mouthful, but of a point in terms of the angular veloci- length squared. (The dot product of any think of IA as a measure of how hard it is ty. If we treat the point A in Eq. 12 as vector with itself is the length squared; to rotate the body about point A. For the origin in Eq. 7, and the point index i remember the perpendicular operator example, think about a pencil (a 2D pen- in Eq. 12 as the point B in Eq. 7, we can doesn’t change a vector’s length.) Finally, cil). If we measure the moment of inertia substitute Eq. 7 into Eq. 12 and write we write the letter IA to designate the about the middle of the pencil, we get a AAATiii=◊w moment of inertia about point A. The certain value by summing the mass-scaled L  rr^^m moment of inertia for a 2D rigid body is squared distances. However, if we mea- i a particularly nice number, because the sure the inertia about the tip of the same iiA A i =◊w m r^^ r points that make up the body can't pencil, we get a much larger value, i change their mass or their distance from because the squared term in Eq. 13 makes iiA 2A ==ww m (r^ ) I the measurement point. These two the masses that are farther away (toward i (Eq. 13) properties make the summation in Eq. the eraser of our pencil) contribute much

20 GAME DEVELOPER • DECEMBER 1996/JANUARY 1997 http://www.gdmag.com more to the value. This is saying mathe- tation via integration—by dividing the 6. Divide the total torque by the matically what we all know intuitively: torque by the moment of inertia. moment of inertia at the CM to find the Turning a pencil about its center is a lot angular acceleration (Eq. 14). easier (read: takes less force) than turning The Dynamics Algorithm 7. Numerically integrate the linear it about one of its ends. We may not recognize it through the acceleration and angular acceleration to Finally, we’re ready to provide a use- flurry of equations, but that’s all of it. update the position, linear velocity, ori- ful link between the angular dynamics We’ve developed enough equations to do entation, and angular velocity (see last equations and the angular kinematics great 2D dynamics with arbitrary forces issue). equations. If we differentiate Eq. 13, we and torques moving and spinning our 8. Draw the object in the new posi- get the total torque on the left side, and on objects around. How do we use all these tion, and go to Step 3. the right side we get the moment of iner- equations? Here’s the basic algorithm: There are only two steps in the tia times the angular acceleration. (IA is 1. Calculate the CM and the above algorithm that I haven’t yet constant so it drops out of the derivative.) moment of inertia at the CM. explained. First, how does one calculate 2. Set the body’s initial position, the moment of inertia in Step 1 for a dL(I)AAT d w t AT == orientation, and linear and angular continuous object? Second, how do you dt dt velocities. figure out the forces on an object for == IAAwa˙ I (Eq. 14) 3. Figure out all of the forces on Step 3? The answer to the first question the body, including their points of can be found in the sample program ref- This equation is the angular equiva- application. erenced at the end of this article (you lent of Eq. 5; it’s basically F=ma for 4. Sum all the forces and divide by perform an integration over the surface angular dynamics. It relates the total the total mass to find the CM’s linear of the object). Most dynamics books torque and the body’s angular accelera- acceleration (Eq. 5). have the moments of inertia for common tion through the scalar moment of iner- 5. For each force, form the perp- shapes listed in the back, so you don’t tia. If we know the torque on our body, dot product from the CM to the point of usually have to derive them from scratch. we can find its angular acceleration—and force application and add the value into The answer to how to compute the therefore, the angular velocity and orien- the total torque at the CM (Eq. 11). forces in Step 3 depends on the applica-

http://www.gdmag.com GAME DEVELOPER • DECEMBER 1996/JANUARY 1997 21 BEHIND THE SCREEN

tion, but a few general guidelines apply. velocity. You could do a simple drag fails, you’ll start to spin unless you adjust First, forces like gravity that always point model and just apply the force to the your rudder to provide another force to in the same direction (down, in gravity’s CM, or you could figure out which parts counteract the torque!) If you have case) don’t induce torques on an object of your object would have drag and apply something like a tractor-beam, should it since they pull on all points at the same specific drag forces to those parts, which act like gravity and be torque-free, or time and in the same direction; thus, we might induce torque on your object. The should it be applied at a specific point on just apply those forces directly to the forces experienced during a collision are the object so the object turns toward the CM. A spring-like force applied to a slightly more complicated, and will have beam as it’s pulled? You’ll have to decide specific point on an object will induce to wait until the next column. Forces that. The key is not to be afraid of torques, so we handle it normally. As we from rocket engines would probably be experimenting with different forces cal- saw in the last issue, drag is just a force treated as forces with a point of applica- culated in different ways—now that directed in the opposite direction of your tion. (That way, if one of your engines you’ve got a real 2D dynamics simulator, you can try all sorts of forces. I’ve placed a bunch of references and some code on my Web site because there’s no more room left here. The sample app implements the 2D dynam- ics algorithm on some objects attached by a spring; they spin and move around, and even collide with walls with rota- tions, which we’ll cover next time. Check out http://ourworld.compuserve.com/ homepages/checker for a list of refer- ences and the sample application for Win32 and Macintosh. ■

Every once in a while, Chris Hecker experiences a moment of inertia, but it usu- ally passes pretty quickly. Forces may be applied at [email protected].

OOPS!

got a great e-mail from Jan Vondrak ([email protected]) the other day. Jan pointed out, much to my chagrin, that the final assembly code for the texture- Imapping series had a big performance flaw in it (in addition to the ones I list at the top of the file): Very soon after issuing the fdiv that ostensibly over- laps with the rasterization loop, I issue an imul. Well, on the Pentium, imul uses the floating point unit, so it's going to stall on the fdiv, and I won't overlap. Oops! I was so rushed just getting the code working that I didn't notice this bug. I moved the fdiv below the imuls and got a speedup, and as the comment in the file says, that code is fertile ground for opti- mization. Thanks to Jan for pointing this out!

22 GAME DEVELOPER • DECEMBER 1996/JANUARY 1997 http://www.gdmag.com 3D HARDWARE

3D Hardware Acceleration Demystified, Part 1

e’ve all been hearing about For this series of articles, I’m going web pages at these companies are a good it, we’ve all been waiting for to concentrate on the standard, frame- source of detailed information on some it, and finally it’s here—the buffer–based, triangle and polygon 3D of these topics. much ballyhooed and graphics accelerator. A game communi- hyped Dawn of the Age of cates with the 3D accelerator, which Who Has What? Affordable 3D Hardware. hangs off the PCI bus (the few non- So the question is: “Who has what?” But, as with any new tech- PCI bus accelerators in the market have Not all manufacturers support all, or nology, along with all of fallen by the wayside), by writing to even most, of the prominent features of theW claimed benefits of cheap, high- memory-mapped register sets or by hav- 3D accelerators. Even finding a set of quality, fast 3D graphics on every desk- ing the device asynchronously bus mas- features that define a safe lowest com- top, there’s a lot of confusion among ter command data from system memory mon denominator is pretty difficult. At consumers and developers. This is the (sometimes referred to as DMA). The this point, just about the only thing a first in a two-part series of articles about accelerator has a frame buffer, where programmer can assume is available is 3D graphics acceleration aimed specifi- images are rendered, and a place to store perspective-correct texture mapping (if it cally at you, the game developer. “other stuff,” such as a Z-buffer or tex- isn’t, then that chip won’t be around for ture maps. On low-cost solutions, very long). After that, it’s a toss up. An Overview of the 3D everything can be stored in the frame Features can generally be classified Accelerator buffer, with a potential decrease in per- in two groups—functional and aesthetic. In the most general sense, a 3D acceler- formance because of memory bandwidth Functional features are required for ator is some type of hardware that accel- limitations (see the Sidebar, “Why Ain’t proper game play; lack of a functional erates all or part of the 3D pipeline. The My Accelerator Accelerating?”). How- feature means that some fundamental majority of the current crop of low-cost ever, some of the more expensive archi- algorithm or technique just quits work- 3D chips only speed up rasterization, tectures provide dedicated memory for ing. Functional features include Z- which is usually the most time-consum- texture maps (’s buffering, alpha blending, alpha testing, ing part of the 3D graphics pipeline on a Voodoo Graphics) or the Z-buffer chromakeying, texture mapping, fog, PC. How this hardware is implemented ( Permedia) to achieve higher and some minimal form of lighting. can vary a lot—from hard-wired ASICs performance. Aesthetic features, on the other hand, to RISC engines to programmable don’t affect game play and only make DSPs—but the theme is the same: Some Features things look better. These features type of data describing a graphics primi- The number of features a particular include MIP mapping, bilinear or trilin- tive is sent to the hardware, which in accelerator will support varies, but most ear blending, antialiasing, colored lights, turn draws the specified primitive (hope- modern accelerators support some type and fog. fully allowing the CPU to execute other of texture mapping and lighting, and Astute readers may have noticed tasks in parallel). Most of today’s accel- many support alpha blending, Z-buffer- that I listed fog twice. The reason is that erators use the well-understood concepts ing, and bilinear filtering. More exotic fog can be noncritical, such as when it’s of triangles and polygons to describe features, such as per-pixel MIP map- used for mood and ambiance, or data, but some more adventurous com- ping, are available on a few ; absolutely critical, such as when it’s used panies are experimenting with more however, these features will become to hide a far clipping plane or when it unconventional approaches to rendering. more prevalent as future generations unfairly shifts the balance in a multiplay- It remains to be seen whether developers arrive. Many 3D chip companies are er game (Player A doesn’t have fog and and consumers will adopt these radical busy trying to educate developers about thus, can see farther than Player B). architectures. high-quality 3D graphics, and thus the Thankfully, fog usually can be faked

24 GAME DEVELOPER • DECEMBER 1996/JANUARY 1997 http://www.gdmag.com Brian Hook with alpha blending or lighting hacks; so will attest, enabling features can exact a lack of fog may be inconvenient, but huge price on performance. If you’d like usually isn’t a killer. to know what some of the performance So what features should you imple- hurdles PC 3D accelerators have to deal Exaggerations, ment? That decision is up to you, but with, see the sidebar. somewhere between what you need, In an effort to make things a little what’s out there, and what you would more sane, I’ve written a very trivial like is a middle ground that will define benchmark that tests a combination of the minimum feature set your game will throughput (the number of triangles require. If you use a Z-buffer in your that can be set up and sent to the host bribes, and lies. In software renderer, then odds are that any per second) and fill rate (the number of 3D accelerator you use will have to have pixels that can be processed per sec- one, too. ond). Throughput is usually limited by a combination of setup complexity, Performance PCI bandwidth requirements, and the hotly contested Rule Number One: Don’t ever trust a hardware flow-control. Fill rate is usu- 3D chip manufacturer to give you a ally limited by memory bandwidth. If straight answer when it comes to perfor- you’d like to know more about these mance. Almost every 3D chip manufac- performance bottlenecks, I once again turer around today blatantly misleads refer you to the sidebar. The results of 3D chip market, some consumers (and developers) when it these tests (and feature comparison comes to performance numbers. Claim- charts) will be presented in the second ing features is fairly objective—it’s there part of this article published in the next or it isn’t (albeit often times certain fea- issue. tures have caveats associated with their Setup complexity affects the use). But performance numbers, well, amount of work the host CPU has to companies will do that’s a different story altogether. When perform to compute a triangle’s descrip- quoting ambiguous numbers like “trian- tion in a format suitable for the 3D gles per second” or “megapixels per sec- accelerator. Typically, the more features ond,” various semiconductor companies that are enabled the longer setup will take the liberty of skewing tests a wee so take because more parameters must be anything to get game that they won’t look so bad in certain sit- computed. Also, issues such as data for- uations. Be wary of manufacturers’ mat conversion and parameter packing claims. come into play during triangle setup. If The biggest complaint I have is that an application does everything in float- we’re fed some pretty good looking per- ing point and the hardware wants every- formance numbers along with some thing in fixed point, a significant chunk developers in their pretty good looking feature lists, but of time is going to be spent converting we’re never told exactly how these fea- floats to fixed-point integers. And if reg- tures affect real world performance. And isters are densely packed, the packing as anyone who has been disappointed operation performed by software is going with the performance of a 3D accelerator to exact a performance penalty also. corner.

http://www.gdmag.com GAME DEVELOPER • DECEMBER 1996/JANUARY 1997 25 3D HARDWARE

PCI bandwidth requirements are both buffers are in use. Triple buffering ware through a proprietary hardware determined by the number of triangle can help alleviate this problem, but interface library (if one is available). parameters that must travel across the requires yet more memory for a third Still, these methods only address the PCI bus to the accelerator—a direct cor- display buffer. Most of today’s inexpen- physical aspects of coding for 3D hard- relation usually exists between features sive 3D accelerators have very shallow ware. Other issues rear their heads, enabled and PCI bandwidth require- FIFOs and probably will stall incoming such as how you structure your 3D ments. More features require more para- rendering commands during this little pipeline to deal with 3D accelerators meters, which in turn requires more hiccup in the rendering cycle. Stalled best and how to deal with data conver- bandwidth, which results in reduced rendering commands can generate PCI sion issues. peak performance. bus stalls, which wreaks havoc on system Finally, hardware flow-control can be performance. Some architectures deal Hitting the a big performance killer. If an application with this problem a little more elegantly. Hardware Directly must poll a busy bit or determine whether With Rendition’s Verite, you can imme- Sure, you can hit the hardware direct- or not enough FIFO slots (a FIFO is diately begin rendering new primitives ly, but it’s about as fun as beating your where incoming register writes are queued into an unused DMA command buffer, head with a blunt, heavy object. Don’t until the card is ready to process them) are and 3Dfx Interactive’s FIFOs are so big do it. These aren’t the good old days of available on the accelerator before render- that the odds of a PCI stall are greatly sound hardware, when you had a ing a new primitive, then performance can reduced. handful of registers in I/O space, a plummet dramatically. few commands, and voilá, you had bad I didn’t test buffer management, a How Do I Use It? FM sound. Register-level program- potentially major performance drain. Programming for the various 3D accel- ming of 3D accelerators is difficult. One of the most irritating bottlenecks is erators boils down to one of three Very difficult. I’m not talking weeks, waiting for a page swap to complete— options: hitting the hardware directly, I’m talking about months of work for you’re displaying frame A, you’ve just using some third-party API (such as each 3D accelerator. Not only that, but finished rendering frame B, now you’re Microsoft’s or SGI’s some 3D accelerator manufacturers stuck with nowhere to render to because OpenGL), or interfacing to the hard- won’t release their register specifica-

26 GAME DEVELOPER • DECEMBER 1996/JANUARY 1997 http://www.gdmag.com 3D HARDWARE

tions to developers, mostly because The perennial favorite API among er support isn’t an issue. Most major support becomes a nightmare the engineers has been SGI’s OpenGL, game companies have signed up to minute developers try and work at the which is broadly available in the UNIX support it, so developer support isn’t a register level. market and is part of the standard problem. Is Direct3D the no-brain The moral is: If you think you want Microsoft Windows NT distribution. solution? In a nutshell, no. Many com- to program registers directly, you’re Unfortunately, OpenGL hasn’t had plaints about DirectX have been sur- wrong. You can try it, but hey, I tried to much luck in the games market, mostly facing recently from developers, and warn you. because of lack of features, lack of until Microsoft addresses these prob- availability, and poor software-only lems, Direct3D isn’t the shoe-in we Using a Third-Party API performance. However, to some may have imagined. The easiest way to support 3D hardware degree, most of these issues have been Other commercial graphics is to use someone else’s high-level 3D resolved—whether or not it’s too late libraries, such as Argonaut Brender and graphics library. These things have been for OpenGL in the games market Criterion Renderware, have announced surfacing recently like earthworms after a remains to be seen. their support for 3D acceleration. Still, rainstorm, so you have quite a few choic- Microsoft’s Direct3D is probably these libraries haven’t really caught on es, including Microsoft’s Direct3D, the most obvious candidate for use, in the game development community, SGI’s OpenGL, and various other com- and its prospects look good. Most 3D and the introduction of Direct3D has mercial libraries from Criterion and hardware manufacturers have or will made their futures look a little less than Argonaut. have Direct3D drivers, so manufactur- bright.

WHY AIN’T MY ACCELERATOR ACCELERATING?

he first comment most developers make when they start working with 3D accelerators is something like, “Boy, this isn’t near- ly as cool as I thought it was going to be.” Because of the rather excessive hype about 3D acceleration, consumer and devel- oper expectations were raised to unrealistic levels before any products ever shipped. So the question posed is, “Why isn’t this $250 accelerator giving me the equivalent features and performance of a $100,000 Silicon Graphics workstation?” To an T outsider, this would seem to be a stupid question, but if you go back and look at what was promised by all the parties involved, this was essentially the expectation set before the public. Aside from the literal answer (“If it was that easy, Silicon Graphics would’ve done it a long time ago.”), some other reasons for the lackluster performance of most of today’s 3D accelerators include the fact that low-cost 3D acceleration still isn’t well understood, the bottlenecks that games encounter haven’t been well-defined, and, more importantly, some significant technological hurdles have to be dealt with to achieve high performance in terms of fill rate and triangle throughput. Time and experience will solve the first two problems, but right now chip designers are fighting certain unavoidable physical limitations to achieve high performance: memory bandwidth, PCI bus bandwidth, CPU speed, and cost constraints.

Memory Bandwidth Memory bandwidth, or the lack thereof, is probably the biggest issue facing 3D hardware designers when it comes to reaching high fill rates. The general axiom is the more times memory is accessed to perform a task, the slower that task will be in relation to the theoretical limit of performance. To make matters worse, display refresh eats a certain amount of bandwidth, and this overhead goes up with color depth, screen resolution, and refresh rate. If you like running your display at 1,280 x 1,024 x 24bpp at 75Hz, keep in mind that you need 295MB/sec of memory bandwidth just to refresh, whereas lowly VGA with its 320 x 200 x 8bpp at 60Hz resolution requires less than 4MB/sec. So merely running at high resolution with high refresh can hurt performance, and we haven’t even started turning on features yet! Some more expensive RAM technologies, such as VRAM and WRAM, can reduce or eliminate the effects of screen refresh on performance, but they are more expensive than the more commonplace EDO and SDRAMs. What Are They Doing About It? Given that we’re not exactly starting off with a lot of memory bandwidth to begin with, semiconductor companies have employed dif- ferent techniques to try and get over the bandwidth barrier. The most brute-force (and expensive) approach is to use multiple and/or wider memory interfaces, which allows more data to be processed simultaneously. An example of this would be separate frame buffer and texture memory interfaces, which allows texture memory accesses to occur in parallel with frame buffer accesses. This greatly minimizes the effects of texture mapping on performance. The 3Dfx Interactive Voodoo Graphics chip set uses two wide memory inter- Cont’d on page 30

28 GAME DEVELOPER • DECEMBER 1996/JANUARY 1997 http://www.gdmag.com 3D HARDWARE

Using a Proprietary prone, and requires a few attempts Porting Hardware Interface Library before you get it right. Not only that, Pre-Hardware Software By definition, no commercial graphics you can rest assured that each hardware to Support Hardware library will match the performance of a library you support is going to have its In general, developers will have to game-specific graphics library written by own peculiar quirks to sort out. For support 3D hardware in either a “pre- a competent 3D programmer. This fact example, some libraries won’t work 3D hardware” pipeline or in a “post- shouldn’t reflect poorly on commercial with a register-based calling conven- 3D hardware” pipeline. Shoehorning libraries; no single graphics library has the tion, some won’t work with your DOS support for 3D hardware in a pre-3D ability to be all things to all people. extender or compiler, some have name accelerator pipeline is not a trivial Assuming that you implement your clashes with other libraries, and don’t task. Many software renderers have own graphics pipeline for performance work at all because they were written odd quirks that work great in software reasons, you won’t have the luxury of a by someone who knows nothing about but not so great in hardware. Com- turnkey hardware abstraction layer 3D or game programming. You just pensating for these quirks can be time (HAL) with associated drivers. Thus, if have to deal with these problems as consuming. you want to have 3D acceleration, then they arise. If a software renderer does a lot of you have to support every 3D accelerator In general, if you are going to sup- operations per pixel, the difficulty in directly. This support is handled port a few accelerators with similar per- porting to 3D hardware is increased. If a through a proprietary graphics library (if formance and/or features, then doing software renderer works only with the one is available), such as 3Dfx Interac- your own HAL isn’t going to drive you notion of “vertex-lit, texture-mapped tive’s Glide Rasterization Library, Cre- to the bottle. But if you want to support polygons,” then adding 3D acceleration ative Labs’ CGL, or Rendition’s all bazillion of the existing 3D chips on should be trivial. Another big hurdle is Speedy3D. the market, and support them well, converting from 8-bit paletted VGA- Now you’re in the position of then expect to spend a pretty good style rendering (with associated color designing and implementing your own chunk of time writing software for tables, artwork, and palette tricks) to HAL, which is time consuming, error them. true 16-bit RGB rendering; this conver-

CONT’D FROM PAGE 28

faces, one for the frame buffer and the other for texture RAM, and achieves some pretty phenomenal performance as a result, even with bilinear blending, Z-buffering, and alpha blending enabled simultaneously. 3D accelerator manufacturers also employ techniques such as small on-chip caches that hold frequently fetched data, reducing the load on the main memory interface. These caches are very popular because of their cost effectiveness; however their performance and flexibility generally aren’t on the same level as multiple dedicated memory buses.

How Do Features Correlate to Reduced Bandwidth? The next logical step is to determine what features consume memory bandwidth, which in turn allows us to make assumptions about what features are generally considered performance hogs. Features that consume memory bandwidth include: higher color depths (fewer pixels can be read/written at a time), texture mapping (a texel has to be fetched per pixel), bilinear filtered texture mapping (four texels fetched per pixel), trilinear filtered texture mapping (eight texels fetched per pixel), alpha blend- ing (one frame buffer memory read per pixel), and Z-buffering (one Z-buffer memory read and potentially one Z-buffer memory write per pixel).

PCI Bus Bandwidth A lot of manufacturers complain that PCI bandwidth is the biggest obstacle to delivering raw triangle throughput. While this complaint is usually true, I don’t see most developers complaining about triangle throughput—most are complaining about low fill rate. But I’ll address this issue here anyway to be thorough. Assume that an accelerator takes 32-bit parameter values (floating point or fixed point), and that each triangle consists of 6 + 3N parameter writes (6 for X,Y at each vertex, and 3N being the number of extra parameters required to represent the triangle in this ren- dering mode). This information is the minimum amount necessary to identify a single triangle. Thus, an RGB-shaded, perspective-cor- rect texture mapped, Z-buffered triangle will usually require around 27 parameters (R, G, B, S/W, T/W, 1/W, and Z, times three ver- tices, along with X,Y at each vertex), or 108 bytes per triangle. Cont’d on page 32

30 GAME DEVELOPER • DECEMBER 1996/JANUARY 1997 http://www.gdmag.com sion sometimes involves a lot of work 3D accelerators accept data in one type and structure conversion will converting artwork and crazy palette of two basic methods—register writes become crucial to performance. For tricks to the Land of the Red, Green, and DMA buffers. Unfortunately, these now, all I’ll say on the subject is that and Blue. two methods are ideally suited to differ- data type conversions (float to fixed ent 3D pipelines. Register writes often point, scaling float values, and so on) Using Your involve waiting on the 3D chip to finish and data structure copying (YourVertex 3D Pipeline with Hardware previous rendering operations, so the tri- to TheirVertex) can become very expen- How you structure your pipeline is very angle-at-a-time pipeline is ideal because sive when doing ultrahigh–polygon- important. Two basic 3D pipelines are while the card is rendering the CPU can count applications. prevalent: the “batch–up-triangles” be doing transformation, lighting, pro- pipeline and the “triangle-at-a-time” jection, and clipping operations in Why Bother? pipeline. The batch–up-triangles parallel. Communicating via DMA So, as a game developer, the question pipeline works sort of like this. buffers, on the other hand, achieves par- you may have by now is: “Why both- allelism at a higher scale—whole batches er?” A fair question to ask when you for all vertices of triangles are rendered while the CPU have limited resources and now you transform, light, project goes off and does other stuff. In that have to justify going off and support- for all triangles case, the batch–up-triangles pipeline ing a bazillion different 3D chips. You, render achieves better parallelism. as a game developer, should support a 3D accelerator for one of three rea- Whereas the triangle-at-a-time Data Conversion sons: You’re being bribed; you have no pipeline works like this. This issue isn’t huge right now; most choice; or, best of all, you just think game engines spend most of their time it’s cool. for all triangles doing rasterization instead of transfor- transform, light, project associated mation and lighting. However, in the Everyone Has a Price vertices future, when high–polygon-count games A fundamental fact of life is that game render become the norm, issues such as data developers are not supporting the cur-

http://www.gdmag.com GAME DEVELOPER •DECEMBER 1996/JANUARY 1997 31 3D HARDWARE

rent generation of 3D accelerators CONT’D FROM PAGE 30 because they think the hardware is cool. They’re supporting this stuff because Modern PCI chipsets can handle around 60-80MB/sec, so in a perfect world (trian- they’re being paid. These bribes, in the gle setup is free), 550-750K triangles of the above type can be sent across the PCI form of cash or veiled in the guise of bus per second. This rate is our unbreakable “speed of light,” and no manufacturer “bundling agreements,” can amount to will be able to beat those numbers with those types of triangles using today’s exist- hundreds of thousands or even millions ing PCI bus implementations. of dollars. With many of today’s games To make matters worse, a lot of 3D hardware requires that extra data be sent costing between one-half to several mil- down, such as error terms, condition flags, state variables, and area calculations; so lion bucks, getting that extra wad of the parameter counts given are a best case. Some 3D architectures try packing as cash for what is hopefully a few weeks much data into a register as possible, which reduces PCI bandwidth at the cost of of work is a fairly big incentive to add more time spent setting up a triangle. Whether or not this trade off is worthwhile is support for just about anything. Grant- debatable. ed, cash isn’t the coolest reason to sup- A game developer’s best solution to this problem is to reduce triangle parameter port some new technology, but it’s bet- count, which means render simpler triangles. A hardware designer’s best solution to ter than being noble and going bank- this problem is to support triangle strips, which reduces the amount of data that rupt because your project was six needs to be sent across the bus—N independent triangles require 3N vertices to be months late. sent across the PCI bus, but N triangles in a triangle strip require only 2+N vertices to be sent across the PCI bus. Note that triangle strips as a primitive are not very Market Realities Dictate common in most of today’s graphics libraries, but they will become more important in There comes a point when some new the future as bus bandwidth becomes a bigger issue. technology reaches critical mass in the marketplace, and you just have to sup- port it to be competitive. Thirty–two-bit CPU Bandwidth DOS games reached critical mass when Another huge hindrance to achieving raw triangle throughput is host-side triangle developers finally gave up the ghost of setup. Triangle setup consists of all the work necessary to compute the data a 3D supporting the 286 microprocessor; accelerator needs to render a triangle. Thankfully, most graphics libraries hide this sound reached critical mass when cus- bit of ugliness from the programmer, and you only work with an abstract DrawTrian- tomers demanded support for their gle() routine of one sort or another. Within that library, however, exists a lot of con- AdLib and SoundBlaster cards instead ditional code that sets up a triangle for you. For every parameter, N clock cycles will of annoying PC speaker beeps; VGA be spent computing relevant information for that parameter. Here, CPU bandwidth reached critical mass when customers becomes an issue—if triangle setup requires N cycles, then at most CPU_MEGA- wanted 256-color VGA instead of 16- HERTZ/N triangles can be set up per second, establishing a second, usually lower, color EGA games; Microsoft’s DirectX barrier to triangle performance behind PCI bus limitations. will reach critical mass because, well, The best way to solve the limitation of CPU bandwidth, aside from having faster Microsoft said so; soon, 3D accelerators CPUs, is to move triangle setup onto the accelerator itself. Future architectures will reach critical mass as well. At some will have triangle setup in hardware, and even some of today’s existing architec- point, 3D hardware is going to be ubiq- ture such as 3DLabs’ Delta and Rendition Verite provide this feature. From a soft- uitous enough that lack of support will ware perspective, the best way to reduce setup overhead is to reduce triangle be hindrance enough to lose significant parameter count, since this reduces the number of calculations that the CPU must sales. We haven’t reached that point yet, perform. but in a year or two we will. And even if you don’t believe that 3D acceleration is a major factor in sales, your publisher Cost probably does and will lean on you to When performance isn’t gated by external physical limitation, it’s probably going to add support for 3D acceleration. Harsh, be limited by tradeoffs the chip designers had to make meet cost goals. For example, but true. an alpha-blending unit can double as a lighting unit, reducing cost but also resulting in reduced performance when doing lighting and alpha blending simultaneously (or Because It’s Cool possibly even negating this ability outright). The law is simple—the more features To me, the best reason to support any you try and implement within a certain cost goal, the more compromises in quality new technology is that it’s amazingly and performance you’re going to have to make. awesome and people who play your game will think you’ve created the neatest thing since the self-cleaning garlic press. Unfortunately, writing a

32 GAME DEVELOPER • DECEMBER 1996/JANUARY 1997 http://www.gdmag.com 3D HARDWARE

game has very little to do with coding For Further Info 3Dlabs’ Permedia and a lot more to do with managing Argonaut’s BRender http://www.3dlabs.com/pm-top.htm people, budgets, and schedules; to con- http://www.argonaut.com/brender/ vince management that some new tech- 3Dlabs’ Delta nology must be supported (especially if Creative Labs’ CGL http://www.3dlabs.com/delta-top.htm it’s going to cost you two weeks of pro- http://www.creaf.com/wwwnew/tech/ duction time), that technology had bet- devcnr/3dbsuprt.html ter be pretty damn amazing. The downside is that very few of today’s 3D Criterion’s RenderWare accelerators are awe inspiring. As a http://www.canon.co.uk/csl/rw.htm matter of fact, far too many accelerators Brian Hook is a 3D graphics hard- are flat out underwhelming. Thus, Microsoft Direct3D ware and software consultant and most support for 3D acceleration tech- http://www.microsoft.com/mediadev/ author of numerous articles and a book nology is the result of bribery, rather graphics/d3dback1.htm on 3D games programming. He can be than magnanimity on the part of the reached at [email protected] or developer. Rendition’s Verite http://www.wksoftware.com. http://www.rendition.com/product.html Stay Tuned As you can probably tell, the topic of 3D SGI OpenGL ACKNOWLEDGEMENTS acceleration can be overwhelming. An http://www.sgi.com/Products/ I'd like to thank Walt Donovan of Rendi- entire book can be written on this topic. Dev_environ_ds.html tion, Andy Bigos of 3DLabs, and Gary In my next article, I’ll talk about perfor- Tarolli and Scott Sellers of 3Dfx Interac- mance, show you some benchmark pro- 3Dfx Interactive’s Voodoo Graphics tive for their help in the preparation of grams I’ve written, and then run some http://www.3Dfx.com/products this article. 3D accelerators through the wringer. ■ /voodoo.html

34 GAME DEVELOPER • DECEMBER 1996/JANUARY 1997 http://www.gdmag.com 3D PIPELINE

Inspecting the 3D Pipeline, Part 1

asterization has been the hot game. As it is presented in most 3D texts, between the two is clear: The width of a topic in game development for the projection of a point p takes the form single pixel is the width of the display the past few years. Image p w divided by the number of pixels trying to quality has improved more as x r fit in that width (the horizontal resolu- pdx¢ =+ a result of better techniques pz 2 tion). The height similarly follows suit. for rendering individual poly- p Standard monitor and TV set dis- gons than from anything else. y hr plays are about four-thirds as wide as pdy¢ =+ Accordingly, most game de- pz 2 , they are high. This proportion of hori- velopmentR literature skips quickly from where wr and hr are the width and height zontal to vertical size is called the aspect the 3D geometry aspects of rendering to of the screen (in pixels) at the current ratio of the display. It is usually the details of rasterization. resolution, and d is the distance from the expressed as a single number, the quo- In our scramble to have the fastest, viewer to the viewplane. tient of the width to the height—for the most robust rasterization in our games, Given the simplicity of the projec- standard TV or monitor, this would be 4 have we neglected 3D pipeline? Al- tion in this form, it is all too tempting to /3 = 1.33. Now, the screen resolution though information about rasterization take the projected points that it produces also has a width and height, and thus an is plentiful, finding information on the and let them spill out into the rasterizer. aspect ratio: at 640×480, the aspect ratio 3D pipeline, focusing on the game But, if we were to do so, we’d be forget- is also 1.33, and at 320×200, the aspect developer’s perspective, is still difficult. ting one underlying assumption that this ratio is 1.6. When we compare the A solid 3D pipeline is crucial. The projection makes: The pixels on the aspect ratio of the physical display with care you take in developing and design- screen are square. Besides the adjustment the aspect ratio of the screen resolution, ′ ′ ing your 3D pipeline will have a pro- for centering, both p x and p y are com- we can tell if the pixels are square. For found affect on the presentation of your puted in the same way—their equations example, 640×480 has the same aspect game. Your familiarity with the subtleties are identical. If we were to project an ratio as the monitor, 1.33, so the pixels and nuances of the 3D pipeline will dic- actual square, it would come out of the will be square. On the other hand, × 4 tate the control you have over your 3D projection as covering an equal number of 320 200 does not have a /3 aspect ratio, objects. In this article, we’re going to run pixels in both x and y. But if pixels are so the pixels will not be square. through the 3D pipeline and give it a wider than they are high, or higher than Fortunately, we can easily correct thorough inspection. In each section, they are wide, the sides of the square will this problem by compensating for higher we’ll tighten some loose bolts, we’ll pol- not be equal in length when drawn. The or wider pixels when we project. If we ish up rusty joints, and, when we’re fin- shape would leave the pipeline as a consider the physical dimensions of the ished, we should have a better under- square, but end up as a rectangle. I don’t screen to be wp by hp and the screen res- standing of how everything fits together. know how this sounds to you, but it sure olution to be wr pixels by hr pixels as sounds to me like there’s a screw loose. before, then all we need to do is solve Dealing with Aspect Ratios The question is, can we safely make the following proportion: Let’s start at the mouth of the 3D pipeline the assumption that pixels are always w h and work our way up. All of our polygons square? Sadly, we cannot. If you think r = a t w h spill out of the pipe at a specific place: the about it, the size of a pixel on a given dis- p p . perspective projection. This projection is play is determined by two factors: the This proportion says that the width responsible for producing the perspective dimensions of the display and the resolu- of a pixel is equal to the height of a pixel foreshortening that we expect in a 3D tion used on that display. The relationship multiplied by some scalar a. This scalar

36 GAME DEVELOPER • DECEMBER 1996/JANUARY 1997 http://www.gdmag.com Casey Muratori is our compensation for a possible equation change. To clarify these ques- inequality in the aspect ratios of the tions, we need to understand what our physical dimensions and the screen reso- requirements for d are, and then derive a lution; it scales the height so that it is good formula for computing d. Prior to rasterization, always equal to the width. Solving for a, First, what does d do in our equa- we get tion? Figure 1 shows two perspective pro- jections of a cube as viewed from above. hp w a = r The essential difference between the w h p r smaller value of d and the larger value, as significant math or you can see from the diagram, is in the w lines of projection for the cube. For the a = r smaller value, the lines diverge quickly, rh pr, which means that the change in projected where rp is the proportion wp/hp, which, size between far side of the cube and near determines a player’s as I mentioned previously, is the com- side is great. For the larger value, the lines mon way physical aspect ratios are given. diverge slowly, yielding little difference Now that we have a, all we need to between far and near. Since d controls the do is use it to scale the y values we gen- erate. This will shrink or expand all our Figure 1. Varying values of d field of view and the heights to compensate for nonsquare pixels. We can express it directly as part of the projection equation.

wr p y h pd¢y =+ rh p 2 d aspect ratio. Casey pr z . That’s all there is to it. Now your projection will work if you want your game to run at 640×480 on a film pro- d jector (r = 1.85), or 320×200 on a regu- p explains it all and lar monitor or TV (rp = 1.33).

Using Field of View We’ve tightened up one loose screw in our projection, but the rest of the equa- tion’s still a bit rusty. When I look at the finishes up with a dot projection equation, the multiplier d raises a lot of questions. From the equa- tion alone, it is not clear what value d should have, or how that value needs to change as the other parameters of the product primer.

http://www.gdmag.com GAME DEVELOPER • DECEMBER 1996/JANUARY 1997 37 3D PIPELINE

Figure 2. Different-sized viewplanes and d view, it does not uniquely determine that breadth. Small Viewplane Large Viewplane As the screen resolution changes, d must also change to compensate. We should therefore wr wr require that our value for d provide consistent results across resolutions. Given requirements we have stated, we can Z axis d d derive a formula for reliably computing d. These requirements are actually not very difficult to meet if we pick a measure of perspective foreshortening and breadth of the view that is not dependent on d

or wr. A convenient measure that many people use exaggeration of the perspective in this way, it makes sense that is the field of view. If you think of the lines formed by the viewer our value of d should be specified by an intuitive measure of the and the edges of the screen (which are shown as dotted lines in amount of perspective foreshortening we wish to have. Figures 1 and 2), the field of view is the measure of the angle In examining the same figure, the view is apparently between these lines. It is a constant measure of the breadth of the much narrower when the value of d is greater—thus, d also view. As the angle gets larger, the view becomes wider, and there affects the breadth of the view. The smaller values of d will is more perspective foreshortening. As the angles becomes small- make objects appear smaller, since they’re not expanding but er, the view is more narrow, and there is less foreshortening. the breadth of the view is. Looking back at our projection Through trigonometry, we can use the field of view to equation, this conclusion makes sense: d scales both x and y. derive the relationship between wr and d that we need. Figure 3 The smaller d is, the less scaling x and y will undergo, and thus, shows the field of view as θ and forms the triangle relating it to the smaller everything will appear. wr and d. The simple trigonometric relation is Figure 2 shows the affect of keeping the same d, but vary- wr ing the width in pixels, w , of the screen. Clearly, the larger the Ê qˆ r tanÁ ˜ = 2 width of the screen, the larger the view becomes. So, d cannot Ë 2¯ d . be considered in isolation—while d affects the breadth of the

38 GAME DEVELOPER • DECEMBER 1996/JANUARY 1997 http://www.gdmag.com For any given screen resolution, we will know wr, or the which is often used to compute the angle between two vectors width in pixels. We specify the field of view θ as a measure of (the equation is easily solved for θ). Did you ever wonder why the perspective foreshortening we want. So, the only unknown there are two common equations for the dot product? is d, and we can easily solve for it. One answer to that question comes from a geometric for- wr mulation based on the law of cosines. However, I’m not going 2 d = to prove the law of cosines here, but its derivation is straightfor- Ê qˆ tanÁ ˜ ward and appears in most books that cover trigonometry. From Ë 2¯ the triangle formed by the vectors u, v, and u-v, as shown in This calculation gives us exactly what we need: an equation Figure 4, the law of cosines gives us for d based on an intuitive measure of perspective foreshortening, 222 uv-=+-2 u v uvcos q and that produces consistent results across screen resolutions. (). With a more solid understanding of the value of d, and Does the |u|| v|cos(θ) part look familiar? It should—it’s one having already found the necessary multiplier to correct for of the forms for the dot product. If we solve for it, we get aspect ratio, we can rewrite our original perspective projection to 22 2 uv+-- uv incorporate these values. The final formulation is given by uvcos()q = Ê ˆ 2 . Á wprx˜ wr If we substitute in the equation for Euclidean distance for px¢ = + Á 2tan q ˜ p 2 the lengths, we get Equation A. After simplifying Equation A, Ë ()2 ¯ z we are left with the equality Ê ˆ wwp y h ¢ = Á rr˜ + r q =++ p y uvcos() uvxx uv y y uv zz. Á 2tan q rh˜ p 2 Ë ()2 pr¯ z . This progression clearly shows the equivalence of the two θ It is important to note that the values for wr, hr, rp, and forms of the dot product. But this method hides much of the are all constant for a given screen mode. Thus, the terms I’ve real relationship between the two equations. isolated in parentheses in the above equations can all be pre- Looking at it another way, the two forms of the dot product computed and stored as only two values: a multiplier for the x can be thought of as representing two different things: one a defi- projection and a multiplier for the y projection. Our new pro- nition and the other jection, while far more robust, is no more computationally an operation. Put Figure 3. Field of view for d expensive than the one with which we started. another way, we can w think of Equation 1 w Understanding the Dot Product as the definition of /2 Viewplane A 3D pipeline, like a real pipeline, has many individual “pipes,” the dot product. We d or stages, that its contents move through. If you look closely at can consider the other any 3D pipeline, you’d see that, stage after stage, a single opera- form of the dot prod- θ tion appears over and over again: the dot product. It’s used uct the operation we Z axis /2 everywhere—transforms, lighting, clipping, backface culling— need to perform to you name it, the dot product’s involved somewhere. Despite the meet the requirement dot product’s large repertoire of services, most people don’t pay set by the definition. it much attention. However, as we’re about to see, there’s a lot Instead of trying to mutate one form of the dot product into more to the dot product than meets the eye. the other by means of geometry, we can simply define what we I’m sure everyone has seen the following form of the dot want our dot product to do, where we want it to do this, and how product, as it is the method we all use for dot product we want it to do this. The operation we want will naturally come computations: out of these definitions. Equation 1 is obviously the “what”; it uv ◊++ =uv uv uv explains exactly what the dot product should do. xx y y zz. Now we need to define where we want the dot product to I would also wager that quite a few of you have seen the work. Equation 1 has no context for its demands; it does not dot product shown as specify how many components the vectors u and v must have, or uv ◊ = uvcos q what those vectors mean. Obviously, we want them to be three- () (Eq. 1), dimensional, Euclidean vectors, so the space we’re concerned Equation A. 2 2 2 2 222 222 2 2 uuuxyz++ + vvv xyz ++ -() uv xx - +-() uv yy+-() uv zz uvcos()q = 2

http://www.gdmag.com GAME DEVELOPER • DECEMBER 1996/JANUARY 1997 39 3D PIPELINE

Figure 4. The dot product with is the space Third, multiplication by a scalar associates. defined by the ◊= ◊ x, y, and z axes. ()ddab ()ab (Eq. 7) In mathe- Finally, we are ready. Keep in mind that the real beauty matics, the con- in the proof is not that it shows the two forms of the dot u cept of an axis product are equal, but rather that it embodies an elegant way u-v system is more of doing so. Think about the seven definitions we have just formalized. enumerated: These are the properties of our dot product and θ Each three-dim- our basis. We can think of these properties as requirements ensional coordi- we have laid out that must be fulfilled. Now we will see that nate must be we can use those requirements to generate the dot product, as v measured rela- some might say, “right out of thin air.” tive to a vector that defines how that coordinate is interpreted. To begin, we expand the two vectors of the dot product These vectors are called basis vectors, and, for three dimensions, they into their component form, as we defined in Equation 2. are assigned the letters i, j, and k. They are the three unit vectors uv ◊= uuu i + j + k ◊++ vvv i j k that coincide with the x, y, and z axes with which we are familiar. ()xyz() xyz A point a is measured by its x component along the vector Now, because of Equation 6, we can distribute the entire i, its y component along j, and its z component along k. We can expression for u over the component vectors of v. write this symbolically as uv ◊=◊+◊+ uvxx i i uv yx j i a =++aaaijk uvuvki ◊+◊+ ij xyz (Eq. 2). zxxy This equation says that the vector a is made up of a units x uvyyjjkj ◊+ u z ◊+ v y of i, a units of j, and a units of k. y z uvik ◊+◊+◊ uv jk u kk v The three-dimensional basis vectors we use for 3D graphics xz yz z z. have two important properties. First, they are mutually perpendic- Multiplication by a scalar is associative, as we stated in ular. Each goes in a completely different direction than either of Equation 7; so, we can group the scalars. the other two. This property is called orthogonality, and we call the uv ◊= uv ii ◊ +◊ uv ji + basis orthogonal. From our definition in Equation 1, we know that xx() yx() when two vectors are perpendicular, the dot product is equal to 0 uvzx()ki ◊ +◊ uv x y() ij + (the cosine of a right angle is 0, which makes the entire expression

0). The property of orthogonality can therefore be written as uvyy()jj ◊ +◊ uv zy() kj + ij ◊= jk ◊ = ki ◊= 0 uvik ◊ +◊ uv jk +◊ uv kk (Eq. 3). xz() yz() zz( ) since i, j, and k are mutually perpendicular and must have dot Given that the dot product of i, j, or k with one of the products equal to 0. other two basis vectors is equal to 0 (Equations 3 and 5), the The second important property is that the basis vectors i, j, majority of the terms drop, and we get and k are all unit vectors. Looking to the definition of the dot uv ◊= uv ii ◊ +◊ uv jj +◊ uv kk product in Equation 1, we can see that if the angle between two xx() y y() zz() vectors is 0 (meaning they point in the same direction), the cosine Finally, because the dot product of any basis vector with will be equal to 1, and their dot product is equal to the product of itself is equal to 1 (Equation 4), the dot products all drop and their lengths. Thus, the dot product of a vector with itself is the leave the familiar squared length of the vector. Using this property, we can write uv ◊= uv + uv + uv xx y y zz. ii ◊=◊= jj kk ◊ =1 (Eq. 4) So there you have it. Instead of using geometric theorems, since the squares of the lengths of each of the basis vectors are we simply stated the seven requirements we wanted to be true of all equal to 1. Because our basis vectors are all unit length, and our system, and we produced the operator we call the dot product. they are orthogonal, we say they are orthonormal. We now have defined what the dot product is and where it A Quick Look Ahead works. We still need to define how we want the dot product to We’ve come to the end of our 3D pipeline excursion for this work. First, it commutes. issue. If you’re like me, every time you re-examine the mathe- matics of 3D graphics, you find something new you didn’t see ab ◊=◊ ba (Eq. 5) before. Next issue, we’ll look more closely at a higher-level con- Second, it distributes. struct of the 3D pipeline, the transform matrix. ■ Casey Muratori is busy trying to think up something witty to abcab ◊+ =◊ +◊ac () (Eq. 6) say in his bio. Creative suggestions are welcome at [email protected].

40 GAME DEVELOPER • DECEMBER 1996/JANUARY 1997 http://www.gdmag.com D IRECTS OUND3D

Exploiting Surround Sound Using DirectSound3D

ou’re hiding in a dark tunnel outer ears have on sound waves arriving (above 1.5kHz). Applying IID to all fre- waiting to destroy an enemy. at the listener. Virtual 3D sounds are quencies is the most efficient approach, Suddenly you hear heavy created by modeling the head and outer because IID doesn’t seem to effect fre- breathing... coming from ears as digital filters. By applying these quencies below 1.5kHz. behind you. Sound like fanta- filters to a digitized sound, you can place Head-related transfer function sy? Think again. Thanks to a sound anywhere in 3D space. Some of (HRTF) is caused by sound reflecting new audio spatializing tech- the more important cues used to localize and diffracting off the complex and nologies, these kinds of audio a sound include interaural time differ- asymmetrical surfaces of the outer ear, Ycues can help you take your games to a ence, interaural intensity difference, and, to a lesser extent, the shoulder and new level of player immersion and excite- head-related transfer function, dimin- torso. Each ear modifies the sound dif- ment. These technologies enable you to ished intensity with distance, head ferently, producing a pair of left and create more realistic virtual environments movement, and vision. The last two, right impulse responses for determining by going beyond the basic stereo panning head movement and vision, are not tech- a specific spatial location. HRTF goes for left and right placement of sounds. nically audio cues, but they are very beyond the simple left or right position- Microsoft’s DirectX version 3.0 provides important in helping a listener locate a ing of IID and ITD by producing cues this functionality using a new API called sound in 3D space. to an actual three-dimensional location DirectSound3D. This article will cover Interaural time difference (ITD) is of the sound in relation to the listener’s some concepts behind positional 3D the time delay between a sound wave head. The data for HRTF is collected sound, how to use Microsoft’s Direct- arriving first at one ear, then the other. from natural or artificial ears and applied Sound3D API, and how to create a cool ITD is a primary cue for determining to the original sound sample using com- sample application to boot. the lateral position of sounds. For a plex mathematical formulas. The result- sound source directly in front of a listen- ing linear function is used to generate How 3D Sound Works er, the sound waves will reach the listen- finite impulse response (FIR) filters to Sounds can be heard in three dimen- er’s left and right ears at the same time create a spatial location for a sound sam- sions because of the effects the head and (Figure 1, position X). For a sound ple. Unfortunately, these computational- source located 45 degrees to the right of ly expensive calculations currently Figure 1. Interaural time a listener, the sound waves will reach the require powerful DSP chips to imple- difference (ITD) and interaural listener’s right ear before the left ear ment in real time. intensity difference (IID). (Figure 1, position Y). Left and right Diminished intensity with distance localization is the most pronounced refers to distant sounds having less vol- X Y effect of the opposing location of ears on ume than closer sounds. For a stationary a human head. sound source, unless the sound is a famil- Interaural intensity difference (IID) iar one, this doesn’t provide an effective is also a lateral localization cue. The ear distance cue. A sound that is approach- nearest the sound source receives more ing or moving away from the listener can sound energy than the farther ear. The be easily identified since it will have a sound source at position X (Figure 1 related increasing or decreasing intensity. again) produces no IID cues. The sound The listener can also use head source at position Y will product an IID movement to help place a sound by sam- cue at the left ear because the head acts pling the sound with the ears pointed in as an obstacle, or a “shadow,” causing different directions. Although it is a sig- attenuation above higher frequencies nificant factor in our ability to localize a

42 GAME DEVELOPER • DECEMBER 1996/JANUARY 1997 http://www.gdmag.com Greg Graham sound source, without special hardware 3D sound source buffer and the listener. to track a user’s head orientation, head- The sound source is represented by a 3D- motion data is not available in generat- enhanced DirectSound buffer, appropri- ing a localized sound. ately called a DirectSound3DBuffer. The Welcome to the world Vision is one of the most important IDirectSound3DBuffer is an interface on the cues in placing a sound. Vision helps us secondary buffer that controls the para- quickly locate the physical location of a meters of a particular sound source. The sound and confirm the direction that we listener represents the person who hears aurally perceive. the sound generated by sound buffer of 3D audio. Using objects in 3D space; it is depicted by an DirectSound3D IDirectSound3DListener. The IDirectSound- DirectSound3D is an extension to stan- 3DListener is an interface on the primary dard DirectSound functionality, so a buffer that controls the listener’s position quick recap is in order. Like most and apparent velocity in 3D space. It also audio cues that mimic DirectX components, DirectSound is controls the environmental parameters implemented as a COM (Component that affect the behavior of the Direct- Object Model) object and the APIs are Sound component, such as the amount of the interface to a DirectSound object. doppler shift. DirectSound3D was the way you DirectSound uses two main objects, designed to use the same positioning the DirectSound object and the Direct- information as Direct3D, D3DVECTOR (List- SoundBuffer object. The DirectSound ing 1). The same left-handed coordinate object creates access to a particular sound system is used by DirectSound and device (such as a sound card). It’s possi- Direct3D (the positive x-axis points to perceive sounds, ble to enumerate through all of the avail- the right, the positive y-axis points up able sound devices, checking the capabil- and the positive z-axis points away from ities of each, and create a DirectSound the viewer). object best suited for the purpose. The DirectSoundBuffer object repre- Listing 1. D3DVECTOR structure DirectSound3D sents the actual single output audio stream or sound. There are two types of typedef struct _D3DVECTOR { DirectSoundBuffer: primary and secondary. union { D3DVALUE x; The primary buffer contains what is being D3DVALUE dvX; can place an object played to the speakers. Secondary buffers }; union { store sound data ready to be played. D3DVALUE y; When a secondary buffer is played to the D3DVALUE dvY; }; primary buffer, DirectSound automatical- union { ly converts and mixes the sound data. D3DVALUE z; behind, above, (For more specific information, refer to D3DVALUE dvZ; }; “DirectSound Unplugged” by Jeff } D3DVECTOR, *LPD3DVECTOR; Roberts, in the June/July ’96 issue.) D3DVALUE DirectSound3D augments Direct- typedef float D3DVALUE, *LPD3DVALUE; Sound with two main components, the or below you.

http://www.gdmag.com GAME DEVELOPER • DECEMBER 1996/JANUARY 1997 43 D IRECTS OUND3D

Three-Trick Pony The sound is transformed, using the 3D Buffers, and dwMaxHw3DStreamingBuffers), This first incarnation of DirectSound3D environment settings, from a single and the other three describe the free, or uses three tricks to position a sound in mono sound into a stereo sound with unallocated, hardware 3D-positional space: It changes the arrival offset at the specific left and right channels. This capabilities of the device (dwFreeHw3DAll- listener’s ear, alters the volume, and uses stereo sound better localizes a sound Buffers, dwFreeHw3DStaticBuffers, and muffling. source with headphones than with two dwFreeHw3DStreamingBuffers). Because this • Arrival offset. Arrival offset is Direct- speakers. Because DirectSound treats the version of DirectSound3D is imple- Sound3D’s implementation of ITD, sound source as a monoaural sound to mented completely in software, all of the main element for displacing a create the 3D stereo signal, all of your these are zero for the first release. sound laterally (left or right). ITD is 3D sounds should be mono so Direct- To determine if a buffer is config- the most effective cue implemented Sound doesn’t need to convert them. ured for 3D sound, call the IDirectSound- by DirectSound3D. Buffer::GetCaps method and check DSB- • Volume. DirectSound3D manipulates DirectSound3D Capabilities CAPS.dwFlags for the DSBCAPS_CTRL3D flag. volume in two ways to localize a sound The IDirectSound::GetCaps method source in 3D. The first is a simple vol- returns the capabilities of the DirectSound IDirectSound3DListener ume offset at the listener’s ears used to object in the DSCAPS structure. Of the six Interface simulate IID. Although ITD and IID data members relevant to 3D sound, the Applications can use the methods of the are mainly lateral cues, to a smaller first three describe the hardware 3D- IDirectSound3DListener interface to degree they also help localize a sound position capabilities of the device retrieve and set parameters that describe source in the vertical plane (elevation). (dwMaxHw3DAllBuffers, dwMaxHw3DStatic- a listener’s position and velocity, orienta- DirectSound3D calculates the volume of a sound based on the distance DEV3D–HARDWARE-ASSISTED 3D AUDIO between the sound source and the lis- tener. The closer a sound is to the lis- irectSound3D supports 3D localization of audio streams. However, it’s software- only, and will likely remain so. Faced with the classic tradeoff of quality vs. CPU tener, the louder it sounds modeling utilization, Microsoft made the only choice which would be accepted by game the diminished intensity with distance Ddevelopers: to sacrifice quality for speed. mentioned previously. DirectSound The new generation of audio DSP hardware supports 3D localization as well as mixing of also provides a rolloff factor that you audio streams. A good example of this is VLSI’s new Songbird Pro chip. It’s capable of 3D can use to exaggerate this effect. audio and can believably place a sound behind or below the listener, especially through • Muffling. Muffling is the effect of a headphones. sound traveling in a roundabout way Unfortunately, DirectSound3D will not pass 3D positional information to the sound driver; before it reaches the ear; it’s known as DirectSound is capable of utilizing hardware-accelerated mixing, but not hardware-assist- the head shadow effect. Low frequen- ed 3D localization. The DEV3D specification (named for DiamondWare, Echo Speech, and cies can wrap around, and go through, VLSI Technology, the companies who developed it) is an extension to DirectSound that the listener’s head and still be heard enables hardware DSPs for 3D localization. The DEV3D home page, www.dw.com/dev3d, contains the actual specification document and reference code. with close to normal intensity. High frequencies can’t wrap or travel DEV3D uses regular IDirectSoundBuffer objects (as opposed to IDirectSound3DBuffer or IDirectSound3DListener objects). The concept is simple: Put a magic number into a through the listener’s head so they get buffer and everything after that point is understood to be DEV3D information that is to be blocked and arrive at the ears with less either used by the driver or passed to the hardware. intensity. Muffling is the primary The first step is to detect the presence of DEV3D. If the installed drivers don’t support it, method used to distinguish sounds the extra data in the buffers would play as noise. Allocate a DirectSoundBuffer of pre- coming from behind or in front of a cisely the length of the dev3d_INFO struct. Lock the entire buffer, copy the dev3d_QUERY listener. This front or back distinction string into the szMagicString field, unlock the buffer, and lock it again. If happens because the listener’s ears are szMagicString now holds dev3d_SIGNATURE, then DEV3D is supported. The remaining oriented forward, so a sound coming struct members tell you how many total and current voices the hardware is capable of from behind a listener will be muffled localizing at high, medium, and low quality. You may perform this query at any time. as compared to a sound coming from To actually localize a sound in three-dimensional space, allocate its DirectSoundBuffer a the front. Muffling also plays a role in little larger than you need—the constant dev3d_EXTRABUF is #defined to the right size. Lock the buffer and then copy into it the dev3d_LOCALIZE string, a priority DWORD (to help lateral sound placement, because a DEV3D decide which voices must be done at high quality and which others can be lower- sound originating from the listener’s quality or not localized at all, if necessary), a filled-in DS3DBUFFER struct, and finally a right will be slightly muffled at the filled-in DS3DLISTENER struct. listener’s left ear because of the mass When you perform the lock operation, the structures are initialized to their current values, of the listener’s head. so the 3D information is both readable and writeable. These three cues are applied to a -Keith Weiner sound source to place it in 3D space.

44 GAME DEVELOPER • DECEMBER 1996/JANUARY 1997 http://www.gdmag.com D IRECTS OUND3D

Listing 2. Create a Primary 3D Sound Buffer.IDirectSoundBuffer *CreatePrimarySound- ity between the listener and one or more 3D sound buffers. The amount of Buffer3D() doppler shift applied is scaled from zero { IDirectSoundBuffer *pDSBuffer = NULL; to ten, in whole numbers. These num- DSBUFFERDESC dsBDesc = {0}; bers represent a multiple of the doppler

memset( &dsBDesc, 0,sizeof(DSBUFFERDESC)); effects found in the real world. No dsBDesc.dwSize = sizeof(dsBDesc); doppler shift is applied to sound at zero, dsBDesc.dwFlags = DSBCAPS_CTRL3D | DSBCAPS_PRIMARYBUFFER; and ten times the real world amount of dsBDesc.dwBufferBytes = 0; // Zero required for primary buffer doppler shift is applied at ten. The if (g_pDirectSound->CreateSoundBuffer(&dsBDesc, &pDSBuffer, NULL) != DS_OK) IDirectSound3DListener::GetDopplerFactor pDSBuffer = NULL; method retrieves the doppler factor set return pDSBuffer; for a 3D listener, and the IDirect- } Sound3DListener::SetDopplerFactor method is used to set a new value. Velocity information is used only in cal- tion, and listening environment in 3D Sound3DListener::GetAllParameters or culating the effect of doppler shift. The space. The first step in using an IDirect- IDirectSound3DListener::SetAllPara- velocity settings have nothing to do with Sound3DListener object is to obtain an meters methods. the listener’s current or future position. IDirectSound3DListener interface pointer. Every change to a 3D listener para- Modifying the listener’s velocity settings An IDirectSound3DListener interface meter requires a recalculation of the 3D is a convienient way to increase or pointer is obtained from a primary 3D positional filter parameters. For maxi- decrease the doppler shift on all buffers sound buffer. Listing 2 shows how to mum efficiency, an application should heard by the listener. Velocity values, create a primary 3D sound buffer. The make parameter changes while using the used for global doppler shift effects, can QueryInterface method is used to deter- DS3D_DEFERRED flag in the dwApply para- be set or retrieved using the IDirect- mine if the desired interface is available meter of the applicable method. The Sound3DListener::SetVelocity and (to make sure this version of Direct- application then calls IDirectSound3D- IDirectSound3DListener::GetVelocity Sound supports 3D sound). Use the - Listener::CommitDeferredSettings when methods. When both position and IDirectSoundBuffer::QueryInterface all settings are complete. velocity settings are changing, it is a method on the resulting buffer to obtain There are three factors you can use good idea to use deferred mode to keep a pointer to an IDirectSound3DListener to simplify using DirectSound3D or to them synchronized. interface for that buffer. Note that calibrate with your virtual environment: The amount of attenuation for a the QueryInterface call will fail if the pri- the distance factor (different from mini- given sound is based on the listener’s mary buffer was not created with the mum and maximum distance settings), distance from the sound source and the DSBCAPS_CTRL3D flag. the doppler factor, and the rolloff factor. rolloff factor. The rolloff factor affects The DirectSound default distance how quickly the sound gets louder as it // lpDsbPrimary was created with unit is measured in meters. You can set approaches the listener. Like the DSBCAPS_CTRL3D. the distance factor to automatically con- doppler factor, the rolloff factor is a hr = lpDsbPrimary->QueryInterface vert all of your game’s units to meters. If multiple of real world sound. At zero, (IID_IDirectSound3DListener,&lpDs3d your base distance unit is yards, then set- there is no rolloff factor, and at ten, Listener); ting the distance factor to .91440018282 DirectSound applies ten times the real if( SUCCEEDED(hr) ) { (the number of meters in a yard) will world amount of attenuation. An appli- // Perform 3D operations. convert the units appropriately. You can cation can set and retrieve the current } manipulate this factor using the methods rolloff factor by using the IDirect- IDirectSound3DListener::SetDistanceFactor or The IDirectSound3DListener object DirectSound3DListener::GetDistanceFactor. Listing 3. DS3DLISTENER structure can be manipulated in a variety of ways. Doppler shift occurs when the fre- All of the modifiable listener’s parame- quency of sound waves increase as sound typedef struct { ters are contained in the DS3DListener source and listener approach each other DWORD dwSize; structure (Listing 3). You can set (or and decrease when they move apart. D3DVECTOR vPosition; D3DVECTOR vVelocity; get) these parameters one at a time This effect it typified by the high- D3DVECTOR vOrientFront; using the methods described later, or all pitched wail of an approaching siren D3DVECTOR vOrientTop; at once in a batch. To execute a batch seeming to drop in pitch after the siren D3DVALUE flDistanceFactor; D3DVALUE flRolloffFactor; call you set all of the listener’s parame- passes. In the 3D environment, Direct- D3DVALUE flDopplerFactor; ters, or read from a filled in DS3DListener Sound3D applies the doppler shift to a } DS3DLISTENER; structure, with calls to the IDirect- sound source based on the relative veloc-

46 GAME DEVELOPER • DECEMBER 1996/JANUARY 1997 http://www.gdmag.com D IRECTS OUND3D

Listing 4. Create a Secondary 3D Sound Buffer. a pointer to an IDirectSound3DBuffer interface for that buffer. Note that the BOOL Create3DSoundBuffer(DWORD dwBuf, DWORD dwBufSize, DWORD dwFreq, DWORD dwBitsPerSample, QueryInterface call will fail if the sec- DWORD dwBlkAlign) { ondary buffer was not created with the PCMWAVEFORMAT pcmwf; DSBCAPS_CTRL3D flag. DSBUFFERDESC dsBDesc;

// Set up wave format structure. // lpDsbSecondary was created with memset( &pcmwf, 0, sizeof(PCMWAVEFORMAT) ); DSBCAPS_CTRL3D. pcmwf.wf.wFormatTag = WAVE_FORMAT_PCM; pcmwf.wf.nChannels = 1; // mono format for efficiency hr = lpDsbSecondary->QueryInterface pcmwf.wf.nSamplesPerSec = dwFreq; ( I I D _ I D i r e c t S o u n d 3 D B u f f e r , pcmwf.wf.nBlockAlign = (WORD)dwBlkAlign; pcmwf.wf.nAvgBytesPerSec = pcmwf.wf.nSamplesPerSec * pcmwf.wf.nBlockAlign; &lpDs3dBuffer); pcmwf.wBitsPerSample = (WORD)dwBitsPerSample; if( SUCCEEDED(hr) ) { // Set 3D parameters of this sound. // Set up DSBUFFERDESC structure. memset(&dsBDesc, 0, sizeof(DSBUFFERDESC)); } dsBDesc.dwSize = sizeof(DSBUFFERDESC); dsBDesc.dwFlags = DSBCAPS_CTRL3D; dsBDesc.dwBufferBytes = dwBufSize; Like IDirectSound3DListener, batch dsBDesc.lpwfxFormat = (LPWAVEFORMATEX)&pcmwf; parameter manipulation is available using IDirectSound3DBuffer::GetAllParame- if (DS_OK != g_lpDS->CreateSoundBuffer(&dsBDesc, &g_lpSounds[dwBuf], NULL)) the return FALSE; ters and IDirectSound3DBuffer::Set- AllParameters methods. See Listing 5 for // Query for the 3D Sound Buffer interface. if (DS_OK != g_lpSounds[dwBuf]->QueryInterface(IID_IDirectSound3DBuffer, the DS3DBuffer structure. (void**) &g_lp3dSounds[dwBuf])) There is a point near a sound source return FALSE; beyond which the listener will no longer return TRUE; perceive the volume increasing as it draws } closer. This point is the minimum dis- tance for the sound source, corresponding Sound3DListener::SetRolloffFactor and er is facing and is defined by the relation- to the maximum logical limit for volume. IDirectSound3DListener::GetRolloffFactor ship between two vectors that share an Similarly, the maximum distance for a methods, respectively. origin. DirectSound calls these vectors sound source represents the farthest point The core of the DS3DListener infor- “top” and “front.” Both vectors originate at which the sound doesn’t get any qui- mation is the position of the listener. An at the center of the listener’s head, with eter. The minimum and maximum application can set and retrieve a listen- the top vector going straight up and the distance methods are IDirectSound- er’s position in 3D space by using the front vector proceeding at a right angle 3DBuffer::SetMaxDistance and IDirect- IDirectSound3DListener::SetPosition and through the listener’s face. Figure 2 illus- Sound3DBuffer::SetMinDistance. These IDirectSound3DListener::GetPosition trates this concept. An application sets methods are effective in normalizing dif- methods, respectively. the listener’s orientation by using the ferent sound levels. A good example is the The listener’s orientation plays a IDirectSound3DListener::SetOrientation difference between a fly and a helicopter. strong role in 3D effects processing. Ori- method, and retrieves it with the IDirect- You could give the fly a minimum dis- entation refers to the direction the listen- Sound3DListener::GetOrientation. By tance of one inch and the helicopter a default, the top vector is (0,1.0,0), and minimum distance of one mile. Thus, the Figure 2. Top and Front Direct- the front vector is (0,0,1.0). fly must be two inches away to be half as Sound3D orientation vectors. loud, but the helicopter has to fly two IDirectSound3DBuffer Top Interface Listing 5. DS3DBUFFER structure Games use the methods of the IDirectSound3DBuffer interface to retrieve typedef struct { DWORD dwSize; and set parameters that describe the D3DVECTOR vPosition; position, orientation, and environment D3DVECTOR vVelocity; of a sound buffer in 3D space. As for the DWORD dwInsideConeAngle; DWORD dwOutsideConeAngle; IDirectSound3DListener, the first step is to D3DVECTOR vConeOrientation; obtain an IDirectSound3DBuffer interface LONG lConeOutsideVolume; Front pointer. To do this, you must first create D3DVALUE flMinDistance; D3DVALUE flMaxDistance; a secondary 3D sound buffer (Listing 4). DWORD dwMode; Use the IDirectSoundBuffer::QueryInterface } DS3DBUFFER; method on the resulting buffer to obtain

48 GAME DEVELOPER • DECEMBER 1996/JANUARY 1997 http://www.gdmag.com miles away before it is half as loud. degrees, so the object projects sound at Putting It All Together The IDirectSound3DBuffer allows the same volume in all directions. A To put DirectSound3D through its paces, you to set one of three modes of opera- smaller value means that the object pro- I created an application that is available tion. Using the IDirectSound3D- jects sound at a lower volume outside of for download on the Game Developer web Buffer::SetMode method, you can turn the defined cone. The outside cone angle site. The steps to creating, using, and off 3D effects with DS3DMODE_DISABLE, must always be equal to or greater than releasing DirectSound3D are listed below return to normal 3D mode with the inside cone angle. in the sidebar, “Creating A Direct- DS3DMODE_NORMAL, or set a buffer to be in The outside cone volume repre- Sound3D Object.” My application initial- head-relative mode with DS3DMODE_HEAD- sents the additional volume attenuation izes DirectSound3D, loads a wave file, RELATIVE. Head-relative mode means (in hundredths of decibels) of the and configures the positional parameters that the position parameters of this sound when the listener is outside the of the sound buffer and the listener. The buffer are relative to the listener’s posi- buffer’s outer sound cone. The default sound source is placed 10 meters directly tion. This mode effectively uses the lis- outside volume is 0, meaning that the in front of the listener. The sound source tener’s position as the origin (0,0,0). For outer sound cone will have no percepti- then circles the listener, staying at the example, if the listener’s character dis- ble effect on attenuation unless this same elevation and at a 10 meter distance. charges a shotgun, the sound source of parameter is changed. An application I simplified the motions by just rotating the discharge is always going the be in sets and retrieves the outside cone the listener’s orientation. When the appli- the same location relative to the listener volume by using the IDirectSound- cation is terminated, DirectSound3D is regardless of the listener’s position. More 3DBuffer::SetConeOutsideVolume and uninitialized and released. creative uses of this mode are left as an D i r e c t S o u n d 3 D B u f f e r : : G e t C o n e - DirectSound3D makes it easy to exercise to the reader. OutsideVolume methods. Inside the add three-dimensional sounds to your Setting the position and velocity of outer sound cone, the normal buffer applications. The heart-pounding excite- the 3D sound buffer are done in the volume (returned by the IDirectSound- ment of your games can only increase same manner as for the listener. To set Buffer::GetVolume method) is used. with the dimension that DirectSound3D and get the position, use IDirect- Outside the outer sound cone, the out- adds. Your players will feel and hear a Sound3DBuffer::SetPosition and IDirect- side cone volume will be applied as greater level of interaction with your vir- Sound3DBuffer::GetPosition methods. To well, making the actual volume the sum tual worlds. ■ set and get the velocity parameters of the two. Outside both sound cones Greg Graham is a game developer (again, only for doppler shift) use the there is full attenuation and full muf- working in the Pacific Northwest. His cur- IDirectSound3DBuffer::SetVelocity and fling; inside both cones there is no rent project is creating a new virtual world IDirectSound3DBuffer::GetVelocity. effect; and between the two cones the full of possibilities. He can be reached via A 3D sound buffer has two sound effect is smoothly interpolated. e-mail at [email protected]. cones, an inside cone and an outside cone. These sound cones are used to CREATING A DIRECTSOUND3D OBJECT define volume and directional bound- 1. Create a DirectSound object by calling the DirectSoundCreate function. ries to a sound source. In addition to 2. Specify a cooperative level by calling the IDirectSound::SetCooperativeLevel sound attenuation, a low-pass filter is method. Most applications use the lowest level, DSSCL_NORMAL. applied to muffle the sounds outside 3. Call IDirectSound::CreateSoundBuffer with DSBCAPS_CTRL3D and DSBCAPS_PRIMARY- both of the sound cones for realism. A BUFFER set in the dwFlags member of the DSBUFFERDESC structure to create a primary game can set and retrieve the cone buffer (Listing 2). angles, volume attenuation, and posi- 4. Call IDirectSound::CreateSoundBuffer with DSBCAPS_CTRL3D set in the dwFlags tion and orientation of a buffer’s sound member of the DSBUFFERDESC structure to create a secondary buffer (Listing 4). cones using the following IDirect- 5. Obtain the interface pointers for IDirectSound3DListener and Sound3DBuffer methods: IDirectSound3DBuffer. • To set or retrieve the angles that define 6. Load the secondary buffers with data. Use the IDirectSoundBuffer::Lock method to these cones, an application uses IDi- obtain the pointer to the data area and the IDirectSoundBuffer::Unlock method to set the data to the device. rectSound3DBuffer::SetConeAngles and IDirectSound3DBuffer::GetConeAngles 7. Perform 3D operations. 8. Use the IDirectSoundBuffer::Play method to play the secondary buffers. methods, respectively. 9. Stop all buffers when your application has finished playing sounds by using the IDi- •To set or retrieve the orientation of rectSoundBuffer::Stop method. sound cones, an application can call 10. Release the secondary buffers. the IDirectSound3DBuffer::SetConeOri- 11. Release the DirectSound object. entation IDirectSound3DBuffer::Get- and NOTE: An application can create 3D and non-3D sound buffers from the same DirectSound ConeOrientation respectively. object. By default, cone angles are 360

http://www.gdmag.com GAME DEVELOPER • DECEMBER 1996/JANUARY 1997 49 TALISMAN

Talisman: Mystical Powers or Just More F.U.D.?

make my living writing high-per- How Things Work Now: Talisman Architecture formance graphics applications. Or, Traditional Graphics The goal of Talisman is to take a differ- more accurately, writing graphics Architecture ent approach to graphics architecture. applications that seem to be high The traditional way that improvements Instead of simply sending massive performance, but that actually use in graphics capabilities occur is that the amounts of data to the frame buffer, various tricks, techniques, and video cards end up with better and Talisman is designed to take advantage hacks to give the impression of faster hardware—a dedicated graphics of a number of features that are common high speed. This revelation is really processor, faster memory access, more to graphics. These features are based on Inothing new—graphics programs will on-board memory. This process of the fact that in a typical animated scene, always suck up any available bandwidth building bigger and better yet more-of- not many changes occur from one frame and be wanting for more. The fact is the-same hardware limits the improve- to the next; that if something is chang- that we can always find a use for more ments we can expect, since these ing, it’s typically limited to just a part of graphics capability. improvements are going to be a function the screen; and that some areas of the Perhaps there’s one solution on the of memory bandwidth. screen, such as a background, don’t need horizon. At the Siggraph convention Updating a typical 320×240 256- to be terribly accurate when they are held in New Orleans this past August, color screen at a refresh rate of 72Hz updated. Thus, Talisman’s goal is to Microsoft disclosed its new Talisman requires 5.5MB/sec bandwidth. If we achieve a high frame rate at the cost of technology initiative, the result of two want to produce workstation-quality quality, rather than the traditional years of research. Talisman is Microsoft’s graphics at a resolution of 1,024×768 approach of quality at the cost of speed. proposal for a new video board architec- with 24-bit color and a 16-bit Z-buffer If you think about it, however, this ture. What was disclosed both enthralled at the same 72Hz refresh rate, we need a is what we’re already doing. Were we and scared me. Talisman will radically staggering 283MB/sec bandwidth. using resolutions of 320×240 because we change the way that we design 2D and Assuming that you could find a game wanted small views? Texture maps were 3D graphics software. Why? Because that runs at a frame rate of 72Hz, you’d originally created to give the impression Microsoft is proposing a new architec- need an increase of over 50 times the of detail at a fraction of the cost—not ture for video boards that is designed to memory bandwidth, which points out because they give us the ability to dra- provide the following: 3D audio, MIDI the problem with this bigger-and-faster matically change an object’s image at run support, 720×486 MPEG-2 video, a 2D approach. While some Silicon Graphics time or because they turn out to be a and 3D graphics engine capable of 24-bit workstations are capable of this rate or cheap way of simulating lighting effects, color with a resolution of 1,344×1,024 better, you can’t find a similar capability but because it’s easier and cheaper to running at a 75Hz refresh rate, on-board on a PC system today. warp a bitmap onto a transformed poly- anisotropic , antialiasing, Waiting for memory prices to come gon than to transform all of the minute translucency, shadows, blur, and fog. down is only part of the solution. The details that the bitmap pictured. Given The real kicker is the targeted price real problem lies in the sheer mass of the choice, would you rather be able to of the board: between $200 and $500. information that must be transmitted. pick any color out of 16 million, or use Would you believe that proof-of-con- The current crop of cards all simply pass one of just 256? We’ve all turned to cept boards already exist? If you’re like more data at a faster rate, and while these simple quality hacks because me, you’ll be both terrified and ecstatic. memory prices have dramatically there’s no other way to achieve a usable Terrified because the world as you know decreased, the data transfer rate has not frame rate. In this case, usable is some- it is about to change radically, and ecsta- kept up. Thus, it’s currently impossible thing less than five frames per second. tic because all those effects you wanted to achieve a high frame rate coupled with Given a choice between working to achieve are going to become possible. high image quality at a commodity price. on the aesthetic and playability aspects

50 GAME DEVELOPER • DECEMBER 1996/JANUARY 1997 http://www.gdmag.com Ron Fosner of a game and trying to reduce the over- come out ahead. The high-end worksta- head associated with the graphics tion people were not too happy when they pipeline, most people would rather work heard this anouncement, but nothing’s on those aspects of the game that stopping them from using this architec- At last fall’s SIGGRAPH improve it, rather than merely simplify- ture, too. An SGI Reality Engine 2 can ing it to gain some rendering speed. crank at over 10 gigabytes per second. Talisman is designed to always render at Imagine what it could do at an equivalent the video frame rate. Thus, the differ- of a trillion bytes per second! ence between an inexpensive Talisman As I mentioned, Talisman is a col- convention, amid little system and an expensive one lies solely lection of techniques working together on the precision of its rendering rapidly to bring down the overall bandwidth changing scenes. requirements. These techniques come in How is this supposed to work? Talis- four major areas. man has a number of different levels; it’s 1. Image Layers fanfare, Microsoft not just one method, but a collection of 2. Chunking techniques that are combined to reduce 3. Image compression the bandwidth needed to update the dis- 4. Multi-pass rendering play. Taken as a whole, Microsoft reports Each of these techniques makes it proposed an initiative that it can reduce bandwidth requirements possible for the next one to further reduce by a factor of 60. (Yes, that’s 60 times, not the memory being transmitted over the 60%!) Thus, you could essentially take bus. Let’s examine each technique. your current program, increase the infor- mation needed to describe your image by Image Layers for a new video 60 times, and still get the same perfor- The first thing that may surprise you is mance. Or, in other words, you could that the Talisman architecture doesn’t change the resolution from 320×240 at 8- have a traditional frame buffer. Instead, bit color to 1,024×768 with 24-bit color it implements the concept of multiple and throw in a 16-bit Z-buffer and still image layers (Figure 1). These layers board architecture.

Figure 1. Image Layering. Fosner examines

it’s potential in game

development.

http://www.gdmag.com GAME DEVELOPER • DECEMBER 1996/JANUARY 1997 51 TALISMAN

Figure 2. “Chunking” an Image. ated with each chunk and where the geometry crosses chunk boundaries. When the scene changes, the geometry Select only those chunks is tracked, and its division into chunks is Chunk image that need to be sent dynamically modified. Send chunks to While this process may sound like image layer overhead, there are significant benefits. For example, only a 32×32-pixel depth buffer is required—rather than the entire frame buffer—allowing the depth buffer to be implemented directly on the graphics chip for high-speed memory access and automatically cleared between chunk processing. Antialiasing is also can be any size and shape, and generally you can provide a low-quality image for implemented directly on chunks, reduc- each noninterpenetrating object in a the background and let Talisman scale it ing the overall memory requirements scene is given its own image layer. up for you, applying built-in filtering to while allowing for much more sophisti- These layers are composited together to clarify the image if necessary. cated algorithms to be used. generate the video output signal. The The current plans are for Direct- hardware will track changes to these Draw and Direct3D Immediate Mode Image Compression layers and, if necessary, maintain the applications to have control over when The next step applies an image compres- frame rate, extrapolating layer changes image layers are updated. In fact, you sion technique to these small chunks based upon past changes until an updat- can treat a Talisman board as a ordinary (32×32 pixels=1K) to further reduce the ed layer is provided. I was taken aback double-buffer video board. Of course, amount of memory required to represent when I first heard about this tech- you could just as easily make it into a them. The method specified by Talis- nique—after all, this means that part of triple-buffer board, as well. At this level, man, called TREC (similar to JPEG), an image may suddenly “jump” when an you also have control over the extrapola- achieves compression ratios of 10:1 or unpredicted change occurs. However, tion that can occur in the image layers. better and allows the use of 32-bit true upon further reflection, I realized that The Talisman SDK provides some code color for all applications. Compression this is probably a better alternative— that an application developer can use to techniques are nothing new, we’ve just remember that the rest of the scene is estimate the acceptable perceptual error never thought about them as such. If still animating smoothly—than simply and determine the optimal transforma- you’ve had to take an artist’s 24-bit color dropping frames till everything can be tion to apply to an image. In some future images and generate an optimal 256- calculated and rendered. (unspecified) implementation of Direct3D color palette to display those images, Further, layers that don’t change Retained Mode (and other higher-level then you’ve been doing image compres- much, such as background scenes, don’t APIs), you won’t have to worry about sion. It’s a lot nicer when it’s all done in have to be redrawn every frame. The fre- when to update image layers; the trans- hardware. quency at which image layers are formations will be made automatically, changed depends upon the rendering and the image layer compositing will be Multi-pass Rendering engine. If you’re designing a space game managed for you. The last specification of the Talisman and the background is black, then you’d architecture is the support for multi-pass simply provide a black rectangle to the Chunking rendering (Figure 3). Multi-pass render- rearmost image layer and never update The next step in the Talisman architec- ing requires that a completed image it! What about a starfield? Since affine ture is called chunking (Figure 2). already exists before the next pass is transformations can be performed on Chunks are 32×32-pixel regions of each started. This requirement typically pre- each image layer, you’d simply provide a image layer. Since the user (or some vents multi-pass techniques from being large image that was the full 360° view API) has divided up the scene into used on all but off-line rendering appli- and translate or rotate it as needed image layers, the Talisman hardware fur- cations. By reducing the bandwidth to according to how the viewpoint changes. ther subdivides each image layer into specify an image, the Talisman architec- You’d never have to redraw the stars; square pixel regions, called chunks. Since ture allows images created by the render- you’d simply provide their locations and the information provided for each image ing process to be passed back into the then translate to the correct viewpoint. layer is a set of geometry (essentially a processor as data and used to create a The necessary transformations are all set of polygons that describe the object new image layer. Thus, techniques that done in hardware. And since you can specified in the image layer), the hard- were previously possible only with off- perform the full set of transformations, ware keeps track of the geometry associ- line image rendering are now possible

52 GAME DEVELOPER • DECEMBER 1996/JANUARY 1997 http://www.gdmag.com TALISMAN\

Figure 3. Multi-pass Rendering. performs any transformations on the images, and then sends the results to the compositing buffer. The final results are Original data Result after 'n' passes displayed in 24-bit color at 1,344×1,024 resolution running at 75Hz (note the slight aspect-ratio change, about a 1.5% reduction in the screen width to match Process the chunk size). The arrows indicate that image the transfer of information is frequently 'n' times bidirectional. An important aspect to using a Tal- isman-style board is understanding how the graphics API will talk to the board. Currently, we’re all used to placing our Return for Processing more completed objects in a 2D or 3D space and having processing the computer render them. Talisman needs more information than current video cards about the geometry of with real time image generation. For The important parts to note are the off- objects it is going to render. Using a example, shadows from multiple light the-shelf media chips to handle sound, future version of DirectDraw and sources or multiple reflections can now video, and communications, and the cus- Direct3D (it could be available as early be rendered in real-time. Multi-pass tom VLSI chips that make up the video as early 1997, when DirectX 4 is rendering is the most significant system. Geometries are passed into the shipped), you would have the option to advancement in the Talisman architec- media digital signal processor (DSP), control object geometry (such as, render ture. Microsoft has implementations that where transformations are processed, a particular image plane), or hand over support filtered shadows and anisotropic and then into the polygon object proces- these kinds of tasks to Talisman. What’s texture filtering, and an antialiasing sor, where shading, texturing, hidden important to understand is that Talis- algorithm that works simultaneously surface removal, antialiasing, and scan man would know the approximate Z- with translucency and depth buffering. conversion take place. The image layer order of the basic geometries you are Much of the research literature focuses compositor accesses chunk information, using and would use that data to opti- on various techniques that currently work only off-line. With a little imagi- nation, it’s not too hard to imagine video Figure 4. The Talisman Hardware Design boards in the near future supporting some pretty advanced features in real time. Think of the fun you could have PCI Bus with real-time ray tracing supported by the graphics hardware! Polygon Image Multimedia Support Media Object Layer DSP Processor Compositor The Talisman architecture recognizes that, while it has nothing to do with 3D graphics, a reasonably high level of built- in support for things like sound, MIDI, communication, various input devices, 2Meg 2Meg MPEG, and video conferencing is RDRAM RDRAM important. The fact that these features Audio Media Compositing are all supported by current off-the-shelf chip DAC Buffer chips indicates how encompassing the Talisman specification is.

2 Ch. Audio Video The Talisman & USB channel Hardware Design Modem (joystick) IEEE1394 Figure 4 shows the reference implemen- media channel tation that Microsoft is currently using.

54 GAME DEVELOPER • DECEMBER 1996/JANUARY 1997 http://www.gdmag.com mize its processing. Other APIs could TALISMAN GOALS also make use of this ability. • A single PCI board encompassing audio, video, and 2D and 3D graphics Intel’s Accelerated • A high-resolution display of 1,344×1,024 at 75Hz Graphics Port • 24-bit color at all resolutions About the same time that Talisman • 3D animation that is optimized at full refresh rates (75Hz) using a combination of architecture boards make their commer- image layer animation and 3D rendering and support for scene complexity of 20,000 cial appearance (probably sometime in to 30,000 rendered polygons or higher (which is comparable to 1.5 to 2 million poly- late 1997), you should also see some gons per second) boards that support the Accelerated • Polygon Object Processor pixel rendering rate of 40 Mpixels/second with anisotropic Graphics Port (AGP). The AGP is an texturing and antialiasing and an Image Layer Compositor pixel compositing rate of 320 Intel-driven effort to reduce the cost of Mpixels/sec advanced 3D features by making avail- • Very high-quality image generation incorporating anisotropic texture filtering, subpixel- able a fast, dedicated port so that the filtered antialiasing, translucent surfaces, shadows, blur, fog, and custom shading computer’s main memory is available to algorithms the graphics card. Currently, even PCI • A front-end geometry processor for off-loading transformations, clipping, lighting, and bus cards are limited in the bandwidth so on that they can process for video images. • Full resolution (720×486) MPEG-2 decode, as well as other video codecs, allowing video Microsoft has committed to support to be used as surface texturesand combined with graphics animations AGP memory directly in DirectX 5, • Base system has two-channel 16-bit audio inputs and outputs with DSP based MIDI syn- which will be available in the first half of thesis (wave table and other mechanisms supported), 3D spatialization, and digital 1997. What this means is that even low- audio mixing—other audio processing is also supported end Talisman cards that perhaps have “only” 4MB of memory could take advantage of the main system memory. The higher bandwidth provided by AGP directly from system memory. Clearly, fast graphics with excellent support for would work synergystically with a Talis- AGP by itself is going to make a big sound, input, video, and communica- man-architecture board to bring band- impact on games and 3D graphics appli- tions. DirectX is making headway in this width values approximately 120 times cations in the near future. area already, but no matter how much that of a non-Talisman board using sys- What does all this mean to the they tune their rendering code, it’s still tem memory for images. AGP by itself is average game designer? Well, there’s going to be limited by bandwidth. Talis- a traditional attempt to boost bandwidth going to be a quantum leap in playability man attacks the problem from the other by making memory access faster, while and realism. Wouldn’t it be nice if all end, bringing together some radical ideas Talisman is designed to compress the PCs were equipped with high-quality, to reduce bandwidth and wrapping them overall memory bandwidth requirements. true-color 3D hardware, 3D audio, together in the form of a hardware Combined together, they will tend to MIDI support, MPEG 2 video support, design. Keep your eye on Talisman—it blur the distinctions between the inex- and a generic network/modem and input could radically change 3D graphics on pensive and expensive video boards. API? That’s what Microsoft is trying to the personal computer. ■ The Talisman architecture was do with Talisman and DirectX. Even originally developed targeting PCI without Talisman, I’m quite fond of boards, so the appearance of the AGP is graphics standards that don’t require that a great feature for Talisman (and tradi- I write drivers for multiple video and For Further Info: tional boards); if an application requires sound boards—so I’m behind the Intel’s AGP extra memory (typically for textures), DirectX philosophy. Assuming that the http://www.teleport.com/~agfxport/ then AGP will provide faster access to implementation continues lurching system memory to get the memory need- towards its high-performance aspira- Microsoft’s Talisman ed by the application. I expect that all tions, I’m confident that most of the http://www.research.microsoft.com/ boards claiming to be good for games (or DirectX APIs will become fairly popular siggraph96/talisman/ good for 3D graphics, in general) will and perhaps even reach dominance. come with an AGP connector. The cur- What Microsoft’s Talisman propos- rent reference implementation of Talis- al tells me is that either that company is Ron Fosner is the founder of Data man has a bandwidth requirement of really looking to confuse the 3D graphics Visualization, a consulting group providing about 220MB/sec, and if you add an industry even more than it already has, companies with assistance in creating AGP to this implementation, you can or it is dedicating some high-powered OpenGL and DirectX applications. You can get all the memory required by Talisman efforts toward developing a platform for reach him at [email protected].

http://www.gdmag.com GAME DEVELOPER • DECEMBER 1996/JANUARY 1997 55 ARTIST‘S VIEW

Sweet Addictions

David Sieks s computer artists, we ab- more handy to have around. There’s a solutely need certain tools to perception that Painter is primarily an get the job done. The frus- illustration package. It’s true that The holidays are trating thing is, as game Painter’s main draw (ha, ha) is its “nat- graphics become ever more ural media tools”—the ability to make sophisticated and more inte- marks digitally that resemble traditional gral to the success of the art materials such as watercolors, oils, product, that list of necessary pastels, and many more. However, these almost here, and if toolsA seems to grow inexorably: fancy tools, which do lend themselves readily image editing, video editing, composit- to creating beautiful illustrations, also ing, 3D modeling and rendering, faster make Painter my favorite texture cre- processors, multiple processors, bigger ation tool. When it comes to texture you’re wondering monitors, 2D acceleration, 3D accelera- maps or bump maps for 3D models, I tion, particle effects, inverse kinematics, rarely turn anywhere else. motion capture…. Dip your toe into the Painter’s wide range of brush types roiling waters of computer graphics and react with the 2D “surface” on which suddenly you’re in up to your neck. You you paint, resulting in a correspondingly what to get the artist find the tools you’ve used so productive- wide range of different effects that can ly are no longer enough. be used to create seamless, natural tex- But that’s…okay. You’re not all tures. Painter comes with several wet; you’re swimming with a fast-mov- libraries of “papers” on which to paint ing current. The graphics tool you’d and lets you concoct and save your own in your life, never heard of or even conceived of yes- painting surfaces, too. The great variety terday becomes the life preserver that’s afforded by the standard brush options helping to keep you afloat today. can be enhanced by customizing brush With the holiday season upon us attributes; these personalized brushes once again, I thought I’d get into the can also be named and saved for repeat- consider these tools sharing mood and give you a peek at ed use. You can even swap papers from some of the newer goodies in my own one stroke to the next to mix and over- toybox, er, toolbox—a few choice lap different surface textures within a items that have kept me afloat lately. single image. from Fractal Somehow, I got by without them I find the Express Texture tool before, but now I find them as indis- extremely useful for turning an image pensable as these ol’ opposable thumbs into a high-contrast or grayscale bump of mine. map. Express Texture provides different approaches to converting the image, Design, 4DVision, and Painter Can based on the current paper grain or a Fractal Design Painter isn’t exactly a selected pattern, image luminance, or a new tool for me; it’s been a staple for predefined mask. Sliders give fine- quite some time. But the new features in grained control over how the image is version 4, available now for Macintosh converted, and a preview window lets Spacetec IMC. and Windows, make this old friend even you view the result before you commit.

56 GAME DEVELOPER • DECEMBER 1996/JANUARY 1997 http://www.gdmag.com This capability allows you tus. Many times I’ve wanted to reach to draw with precision, through the screen and put the details repositioning anchor exactly where I want them on an object. points as needed and With 4D Paint, a new 3D texturing adjusting curves with bezi- package from 4DVision, I’m able to do er handles. Your shapes just that (well, not the reaching through can then be converted to the screen part). floating selections and Until recently, 3D texturing tools repositioned within the were available only for high-end plat- image, pasted into other forms. Now, 4DVision has brought this images, or turned into enviable power to the more accessible ammo for the Image PC workstation. 4D Paint is designed to Hose. This feature is great work as a plug-in for 3D Studio MAX— for creating decals for 3D where it takes geometry and mapping Seamless bump and texture maps can be created in minutes objects, logos, and other information directly from your scene—or with the natural media tools and surfaces in Fractal Design slick graphics where you as a standalone application that can Painter 4. want to get the line quality import .3DS files. Even when operating and shape just right. as a plug-in, 4D Paint uses its own In addition to painting your own Painter 4 also has new capabilities toolset and interface, which is clean and textures, Painter lets you create different for creating Web graphics. Images can be easy to navigate. randomized effects with blobs, marbling, saved in GIF format at color resolutions Basically, 4D Paint allows you to and seamless fractal patterns. As with from 256 down to 4. Palettes can be paint directly on your geometry with a everything in Painter, these “random” automatically dithered or quantized or variety of brushes, rotate the model as effects can be closely managed with vari- can be defined by the user. Images can be needed, pan, zoom, and adjust lighting so ous slider controls and settings. Painter saved as interlaced GIFs, so they appear you can see what you’re doing while you also supports Photoshop-compatible more quickly when a Web page is loaded. work. And it doesn’t just let you slap plug-ins, which gives you even more You can also define hyperlinks to be some color on: You can also selectively effects with which to work. associated with your image to create a paint bump, shininess, self-illumination, One Painter feature I return to fre- clickable image map. and opacity values, as well as use bitmaps quently is the Image Hose, which sprays Small but significant changes to the as painting elements. In addition to the canvas with images—24-bit bitmaps interface in version 4 make using rotating objects to view them, you can with an 8-bit alpha mask. An Image Hose Painter’s tools easier. The documentation toggle standard orthographic views in “nozzle” can consist of several images that is also much more helpful than in past which to work. are sprayed together; a great feature for releases. Painter 4 is a favorite tool made A range of brushes and paints are when you want to avoid too uniform an even better, and it still comes in a cool ready for use, and you can easily create appearance in a texture. For example, sev- paint can instead of a box. To go with it, your own varieties, as well. New brushes eral variations of a leaf bitmap can be I recommend a pres- sprayed together to create foliage, or an sure sensitive tablet assortment of scars, dents, and grime can and a good-size be sprayed onto a starship hull pattern to monitor, so you can give the look of random wear and tear. keep a variety of If you’ve got a scanned image or menus open without digitized photo you’d like to use as a tex- cluttering up your ture map, Painter provides helpful tools screen. for turning these images into seamless patterns. Existing seams can be moved to Paint Some the center of the view where they are eas- Bump ier to evaluate. Feathered selections, As good as Fractal cloner brushes that lay down elements of Design Painter is at the image with each stroke, or any creating textures, Painter media that seem appropriate can sometimes making then be employed to obscure the seams. just the right 2D One new feature is that Painter now map for a 3D object Selectively paint color, bump, self-illumination, shininess, opacity, or can import (in Adobe Illustrator 5 for- is like trying to bitmaps directly onto 3D objects with 4D Paint from 4DVision. mat) and create vector-based “shapes.” giftwrap a large cac-

http://www.gdmag.com GAME DEVELOPER • DECEMBER 1996/JANUARY 1997 57 ARTIST’S VIEW

can be defined with settings for shape, Bitmaps can also be pasted onto size, angle, and feathering; or you can your object from the clipboard, then create and define a small bitmap shape dragged around and repositioned. to use as a custom brush head. New Though they can be flipped horizontally brushes and paints can be saved, and you or vertically, they cannot be freely rotat- can even include a description of your ed within 4D Paint, as you might be creation and its use in an attached note used to doing in 2D paint programs such section. as Fractal Design Painter. Bitmaps past- One very cool paint attribute is the ed from the clipboard in this manner user-definable Area of Effect, which lets also cannot be resized, though those you create drybrush or wash effects that used with Bitmap Paint or Texture Paint interact with bump maps on your model. can. The solution, if you want the free- A drybrush look or highlight only paints dom of dragging the bitmap around the on areas with a sufficient bump value: model to place it, is to rotate and scale it Get two-fisted action in 3D Studio MAX Raised areas receive paint, while depres- as desired in an outside paint program with the SpceController and Space- sions do not. A wash works in the oppo- before pasting it into 4D Paint. Ware AniMotion from Spacetec IMC site fashion by letting color pool in the In addition to freeform brushes, low-lying areas without covering the there are tools to create straight lines or high spots. The effect is much like polygons, a fill tool, text, and an eraser Big Blue Ball working on Fractal Design Painter’s tool. The eraser is especially handy: It The SpaceController from Spacetec paper textures. With these paint settings uses the current brush attributes and can IMC is a motion-control device that, at and the right bump map, you can create selectively erase color, bump, opacity, present, is compatible only with 3D Stu- extremely tactile effects. shininess, or self-illumination values. dio MAX. At first sight, it looks like it One limitation of the first version Thus, you can go into an area and erase might be some sort of game-controller of 4D Paint is that it is not adept at bumps, for example, without removing device, and when first described, it importing tiling textures; that bump map color. sounds about as necessary as a cap to you have set to 10 U/V reps in MAX is 4D Paint works with multiple lay- wear on top of your hat. I mean, MAX likely to come into 4D Paint showing ers, which can be kept distinct from one already has a motion-control device: It’s only a single iteration of the pattern. another. Neat effects can be achieved by called a mouse. 4DVision is working on an update to fix erasing areas from one layer to let a But once you wrap your hand this. You can, however, use bitmaps as a lower layer show through. The order of around that big blue ball, you’ll find the paint within the program, where it is layers can be shifted, so a layer can be SpaceController brings you a giant step possible to scale and tile them. moved up or down in the stack, and closer to being able to work smoothly in One method, called Bitmap Paint, layer can be named, which makes keep- the 3D environment on the other side of is very similar to the Image Hose in ing track of them much easier. your screen. It’s used in conjunction with Fractal Design Painter. Images are You can also delete an entire layer, the mouse, not instead of it, and while it sprayed onto the surface in random or giving you the freedom to experiment doesn’t supercede any of the mouse’s sequential order, as you prefer. The without fear of ruining your work. You functionality—the mouse still works as Bitmap Paint can combine multiple files can create a new layer above your exist- normal—the SpaceController does pro- to serve as color, bump, self-illumina- ing work on which to try a new effect: If vide a more efficient way to perform tion, opacity, shininess, and alpha values. it doesn’t work, simply delete the new object transforms, allowing you to move You can also define the dab spacing for layer; if it does work, the layers can be and rotate objects in all axes fluidly and the brush you use with Bitmap Paint to kept separate or collapsed into one. freely without having to switch tools. If precisely control placement of the paint I’ve found 4D Paint provides a much working with 4D Paint is like being able elements. In this manner, a bitmap can more natural way to add surface details to to reach through the screen to paint be placed so as to tile seamlessly as you my models, almost like holding an object directly on a model, using the Space- paint it onto your model. in my hand to paint it with a real brush. Controller with your mouse is like being Texture Paint is another method of In a lot of ways, though, 4D Paint works able to reach through the screen with painting with bitmaps. In this case, you even better than manipulating a physical both hands to freely manipulate actors, specify a source image that is then sam- model because it gives it’s users the free- lights, and cameras in your scene. pled to provide the paint for your current dom to paint with bitmaps, juggle layers, You use the SpaceController by brush. Rather than applying the entire and so on. If you do much texture map- resting the palm of your hand on the texture to your model, you paint it in ping, once you’ve had a chance to paint in molded base and gently pushing, pulling, selectively with your brush, stroke by 3D, you’ll wonder how you got along and twisting the ball with your fingertips stroke. without it. (it wiggles slightly under the pressure,

58 GAME DEVELOPER • DECEMBER 1996/JANUARY 1997 http://www.gdmag.com but doesn’t actually turn like a trackball). The SpaceController is also sup- work with, but often it’s the new tools Your finger pressure causes the selected ported in 4D Paint. This is a very nice that open up new possibilities or suggest object onscreen to translate and rotate way to work—rotating and zooming the new approaches, that allow us to meet simultaneously in any axis as directed, view with the SpaceController in one deadlines that would otherwise have without your even having to pick move hand while painting with the mouse in crushed us, or that help us keep our work or rotate tools. Contrast this freedom the other. At the time of this writing, fresh and our audience looking forward with using the mouse alone, where each 4D Paint only looks for the device on to what-in-the-world-we’ll-come-up- tool must be picked and each transform COM1, which necessarily limits the with-next. ■ effected separately. The SpaceController configuration of your machine. Still, this represents an apparently small but, in limtiation shouls be remedied with practice, significant improvement to how future updates from 4DVision. David Sieks is a contributing editor to you work in 3D space. It’s kind of like The SpaceController also provides Game Developer. You can contact him via power steering for 3D Studio MAX. a much quicker method of animating e-mail at [email protected]. The SpaceController’s SpaceWare smooth object movement, as translation AniMotion software operates as a MAX and rotation are handled simultaneously plug-in. Onscreen controls in MAX’s in real time according to your input SpaceController Utilities command panel allow you to through the device. This makes fly- SpaceController fine-tune the device’s functions. These throughs and fly-bys a snap: Keyframes Spacetec IMC Corp. various settings can change certain char- are recorded automatically at intervals set The Boott Mills, 100 Foot of John Street acteristics of the SpaceController to bet- by you, and all object movement is creat- Lowell, MA 01852-1126 ter suit it to a particular task. The Single ed at once as you literally steer the object Tel: (508) 970-0330 Axis Filter constraint, for example, limits through the scene. Again, contrast this Web: http://www.spacetec.com/ movement to the dominant force exerted with using the mouse alone, where Price: $495 on the ball: The selected object will movement and rotation tools must be System Requirements: 3D Studio MAX, 2MB move or rotate only along a single axis at swapped keyframe by keyframe through- free hard disk space for installation, one a time, though by switching the quality out the animation. The SpaceWare Ani- available serial (COM) port for device or direction of pressure on the controller, Motion software also makes it simple to you can immediately change which axis use the SpaceController even while is in effect and whether the object is to recording animations in reverse, which is be rotated or moved. Using this filter can the easy way to show objects flying or be a good way to work with the Space- falling into perfect alignment. Painter 4 Controller until you become used to how The SpaceController is an elegant Painter 4 your finger pressure translates into an tool: clear in purpose and simple to use. Fractal Design Corp. onscreen response; the filter makes I’m not going to kid you: You don’t need 5550 Scotts Valley Drive object transforms more deliberate with- this thing any more than you need a Scotts Valley, CA 95067 out limiting freedom of movement. sound system in your car. But I wouldn’t Tel: (408) 430-4200 The command panel also can be used think of driving across the country with- Web: http://www.fractal.com/ to restrict the type of transform and the out a tapedeck or a CD player to keep Price: $549 axes of movement. For example, you can me sane, and I’ll be equally glad to have System Requirements: PC - 486 with 8MB RAM or Pentium with 12MB RAM, Windows perform a translation without allowing the the big blue ball in hand next time I 3.1 or Windows 95; also available for Mac object to rotate at all, or rotate the object tackle a modeling or animation task of freely while moving only along the z axis. cross-country proportions. The device’s sensitivity and responsiveness Again, at present the SpaceCon- are set with the command panel as well. troller is only compatible with 3D Studio Being able to work with both hands MAX. If that’s not your 3D package, but 4D Paint makes sub-object editing more interac- you’re interested in using the SpaceCon- tive. With the SpaceController, you can troller to improve your workflow dynam- 4D Paint 4DVision rotate an object in place while picking ics, let Spacetec IMC know about it. 4800 Happy Canyon, Ste. 250 and manipulating vertices with the Computer game animators are like Denver, CO 80237 mouse. This is handy for complex mod- sharks: not just because we’ve got dull Tel: (303) 759-1024 or (800) 252-1024 eling tasks where an object’s geometry gray skin and soulless eyes—that’s just Web: http://www.4dvision.com/ must be tweaked a bit at a time in many from too many long hours in front of our Price: $995 places, such as when creating organic monitors—but because, like sharks, System Requirements: 3D Studio MAX, Win- shapes. The task of modeling flows more we’ve got to keep moving or we drown. dows NT 3.51 or later, 16–24-bit color at naturally due to the added control. Old, familiar tools are comfortable to 800×600, 32MB RAM, CD-ROM for installation

http://www.gdmag.com GAME DEVELOPER • DECEMBER 1996/JANUARY 1997 59