“Hardware shaders”, “interactive rendering”, “real-time cinematic effects”… These terms and things they denote are permeating into the 3D graphics field. It all began when NVIDIA and ATI developed and rolled out the new generation of graphics processors with revolutionary 3D features This process has recently been developing very actively due to the more advanced hardware GPU models coming, as well as due to special software worked out particularly for them.
The Cg language (C for Graphics) invented by NVIDIA is a special-purpose C-like language for programming the so-called hardware shaders. Shaders allow fantastic and spectacular visual effects in real time and using only the graphics card’s hardware. Regrettably, Cg is too narrowly specialized and won't suite an amateur in programming. For example, it won't go for a designer who works with graphics, including interactive one, too.
So, we were waiting for another, more accessible and mass-oriented tool for work with shaders. And it did come out – CgFX is a Cg dialect, compatible with DirectX shader specifications and requiring the user-defined parameters from a shader that change its visual representation. The programmability of shaders allows the designer to process them with traditional graphics tools.
The standards imposed by the developers of system software (operation systems) are changing, too. Today we already talk about the ninth version of DirectX and, accordingly, more flexible and powerful shaders. They now resemble fully-fledged programs with conditional branches, loops and so on. Modern shaders are proficient in implementing complex and sophisticated effects in real time, while interactive technologies themselves are becoming the hot talk of designers, artists, movie directors. It is also quite natural that after the arrival of CgFX the modern 3D graphics packages offered plug-ins to support it. Today there are plug-ins available for Softimage XSI, Maya and 3d studio max.
In this article I will try to show you what CgFX is by the example of 3d studio max.
CgFX and 3d studio max
So, CgFX for max is first of all a tool for visual hardware shader development within the environment and with the 3d studio max tools. NVIDIA guarantees you full WYSIWYG: you will see in the interactive application or game exactly what you see in the 3d studio viewport. The shader code may include any command from the Cg language as well as insertions in Assembler or in any other low-level language.
Overall, the CgFX plug-in uses 3d studio max environment to open shader files, execute them, modify them and display the result in the viewport in real time. Shader files are compatible with the FX format developed for DirectX, with all ensuing consequences.
Every shader program can and even must have user-defined parameters. Thus, two objects produced by the same shader but with different parameters can have quite distinct looks (the shader code itself remains unchanged, of course).
These parameters are exactly where the designer enters the game. Every shader has its own list of parameters depending on the purpose each particular shader was created for. Basic parameters are textures and color. Just imagine: you have a shader library for rendering human skin, hair, eyes. It is ready for immediate use, photo-like, adjustable and interactive! ...R elax, of course, there is sure no such library so far.
Besides the things I have mentioned above, the shader can have several techniques. The technique is a method (code portion) that implements this or that shader function. As the shader is executed by the GPU of your graphics card, there arises the compatibility issue between the code and the capabilities of the graphics card it runs on. Incorporation of several techniques into a shader makes it “heavier” (longer), but allows it to run on both: GeForce 2 and GeForce FX, for example. The plug-in can also open the shader file in the project window so that you could manually edit its code.
Now, I have covered the basic things you should know about shaders and Cg, let's go over to more concrete matters.