David Kirk is NVIDIA’s chief scientist, and his personal enthusiasm for Cg is easy to see. “What we’re doing here”, he says, “is allowing people to develop graphics at a higher level than was possible before, without getting their fingers dirty with the difficult, low-level assembly language.” Graphics development, he claims, has become much more complex simply due to the speed at which GPUs (Graphics Processing Units) are evolving. Standard PC CPUs follow Moore’s Law, which states that performance doubles roughly every 18 months; however, according to Kirk, GPU speed is currently doubly every six months, and with this increase in speed comes a related increase in complexity and power which has made modern GPUs very difficult to develop for.
“Right now, if you’re a really hotshot programmer you can do some cool stuff with the shaders on current GPUs”, according to Kirk, “but most programmers really struggle to get things up and running... What we’ve created in Cg is a technology that allows game developers to get more out of the time they’re spending on their graphics, and opens up these powerful tools to everyone, not just programming wizards… An experienced C coder can pick up Cg and be writing shaders in about an hour.” An impressive claim, although of course, the actual 3D graphics knowledge required to actually make the shaders do anything useful may take somewhat longer to learn.
Universal translator
When Kirk says “everyone” in this context, he really does mean everyone, too; he talks about the forthcoming Cg support for industry-standard 3D animation packages Softimage 3D, Lightwave, 3DS Max and Maya, which will allow artists to tweak shader effects in Cg within the editor itself. A third party is also working with NVIDIA on creating a tool to translate shaders from RenderMan – the film industry standard shaders package, used on a variety of movies – into real-time shaders in Cg, and Kirk expects that many movie production studios will use the real-time rendering capabilities of modern hardware, combined with Cg, to prototype their effects and rendering and streamline their production line. “We’re bringing the advantages of real-time rendering into the film production process, just as we’re bringing film quality graphics into the games industry”, boasts Kirk.
By way of example of the type of graphics quality he’s talking about, I’m shown a piece of Cg code for rendering realistic skin onto a face. The end results are certainly impressive – the skin does look appropriately lit and textured, and the entire scene is surprisingly life-like – but perhaps what is most impressive is the fact that the whole process is performed by a mere 20 to 30 lines of Cg code. “In assembly language, this would be thousands of lines of code”, Kirk tells me. The compiler NVIDIA has written for Cg outputs shader assembly at runtime, dynamically creating code for OpenGL or DirectX, depending on which is required, and Kirk is adamant that it creates shaders just as tightly optimised as the most lovingly hand-tweaked code. “Once you start to have huge assembly programs, computers are simply better at optimising them than humans are – we’re looking ahead here to when shaders are gigantic, complex programs which would be impossible to optimise by hand.”