[ Print Article! ]

NVIDIA's Cg technology
June 13, 2002 Brandon Bell

Summary: Today NVIDIA has unveiled a new programming language solely for graphics: Cg. Find out more about Cg and its possible ramifications for the graphics world in our preview of this technology.


IntroductionPage:: ( 1 / 3 )

Accelerating the convergence of film and real-time rendering

Up until now, game developers have had to use complex assembly language to create the lifelike graphics gamers experience in today’s latest games. The programming skills required to truly bring these games to life are only possessed by a select group of programmers and requires an extensive amount of time and patience to be done properly. In today’s fast-paced world, game developers are often placed under intense time constraints, while others lack the resources to bring in top-notch talent. With economic pressure continuing to hamper game developers while the complexity of modern graphics also continues to increase, life in the game development field has never been tougher. In an attempt to alleviate some of the pressure on 3D content developers, NVIDIA has been working behind closed doors on its Cg graphics programming language.

Cg (“C” for graphics) is a high-level graphics programming language NVIDIA has developed in cooperation with Microsoft for game developers and other 3D content developers to ease the process of bringing 3D objects to life on your computer screen. Besides the language itself, NVIDIA has developed a toolkit that consists of the Cg compiler, Cg browser, Cg standard library, and a variety of pre-written Cg shaders that can be used in game development, digital content creation, and computer-aided design applications.

The language

In today’s programming environment, programmers are forced to code directly to the hardware itself. As we discussed earlier, this is done in low-level assembly code. Cg replaces the abstract assembly code with more familiar syntax that resembles a programming language all programmers are familiar with: C. As a result, a graphics effect that once took dozens (or even hundreds) of lines of code has been simplified to only a handful of lines.

[image]

<% print_image("01"); %><% print_image("02"); %>

The illustrations above highlight the difference between assembly and Cg for content creation developers. As you can see Cg has simplified the process of bringing objects to life substantially. If you were a programmer, which language would you prefer to code in?





SIDEBAR: “Cg will do for GPUs what C and C++ did for CPUs”

-Jen Hsun Huang, CEO NVIDIA Corporation


The rest of CgPage:: ( 2 / 3 )

[image]

<% print_image("03"); %><% print_image("04"); %>

The compiler

If the language itself is the nuts and bolts of the Cg programming environment, the Cg compiler is the heart and soul that makes it all happen. Once the program is written, the compiler can output code for DirectX or OpenGL. Since Cg is designed specifically for vertex and pixel shader programs, DirectX versions 8 and 9 are supported as well as OpenGL 1.4. The compiler itself is cross platform; in particular programs written for Windows, Linux, Macintosh, and Xbox are supported. And if all that isn’t enough, the compiler can create code for all GPUs that support DirectX 8 (or above) and/or OpenGL 1.4, making it very universal. In keeping with Linux tradition, NVIDIA has open-sourced certain components of the compiler, allowing content developers to add their own customizations as well.

[image]

<% print_image("05"); %><% print_image("06"); %>

Like NVIDIA’s unified driver architecture, the Cg compiler employs a unified compiler architecture that is forward and backward compatible with today’s current and tomorrow’s next generation of graphics cores. As a result, once the program is written, the compiler will automatically optimize the program for multiple generations of graphics chips with no intervention from the programmer – the days of optimizing for one particular graphics core (future or present) are gone.

[image]
<% print_image("07"); %><% print_image("08"); %>

The final components of the Cg toolkit are the Cg browser (a graphics interface for creating and modifying objects), the Cg standard library (a set of built-in functions dedicated to help the programmer with common computations), and a collection of pre-written Cg shaders that can be used for development as well as training.



SIDEBAR: The Cg toolkit is currently in beta; the gold release is scheduled for later this year.


SummaryPage:: ( 3 / 3 )

Our thoughts

On the surface, NVIDIA’s Cg programming environment appears to be a good thing for all content developers who are looking to push the limits of today’s hardware without requiring a corresponding increase in development time. Many journalists and consumers have noticed the increasing disparity between today’s latest hardware and games (or other software applications) that are designed to take advantage of that hardware with growing frustration. Cg could be the key ingredient that gets the software industry the shot of adrenaline it currently needs.

On the other hand, Cg could bring us one step closer to an NVIDIA-dominated world. What happens if developers choose not to dedicate enough time to ensure that non-NVIDIA cards work well with their Cg-compiled code, or aren’t optimized for the best performance? Fortunately, Cg is 100% compatible with Microsoft’s recently announced high level shading language for DirectX 9 (as well as OpenGL) and its open-sourced roots will hopefully keep scenarios such as this to a minimum, but it doesn’t take a conspiracy theorist to see that this possibility could become a reality in the near future. Only time will tell how this aspect of the story develops.

As of right now, over 100 game developers have pledged their support of Cg. Prominent names include Blizzard, Epic MegaGames, Lithtech, Sony Online Entertainment, and Valve. Software. Applications such as 3D Studio Max, Lightwave, and Maya have also hopped onboard. With this kind of support, Cg appears to be off to a good start.

Now that Microsoft and NVIDIA are providing the tools to make content creation easier for game developers, hopefully the pixel and vertex shaders that launched with so much promise a year ago will truly live up to the hype surrounding them. The future of graphics hardware is certainly going in that direction, it’s about time that the software caught up.



SIDEBAR: What do you think of Cg, is it a good thing for game development or not? Voice your thoughts in the comments!


© Copyright 2003 FS Media, Inc.
[ Print Article! | Close Window ]