Causes Grumpiness
I started learning the GPU shader programming language Cg yesterday. In fact, I reviewed a lot of things, including Microsoft’s HLSL and the OpenGL shader-language GLSL. But, since I can only learn so much, I decided to stick with Cg for now.
Contrary to the title (which indicates how learning a new language can make me feel at first), Cg means “C for Graphics.” It was spec’d by nVidia, and it is a pretty nice little language. It seems to have caught on quite a bit in the development arena, which is nice - although typical, it is really lame to have to learn one language for Microsoft development, and another for everything else… Cg looks like it is the common denominator at this point, which is comforting!
The nVidia developer site is nice enough to include a Cg Toolkit, which includes Cg libraries for DirectX (on Windows) and OpenGL, a Cg compiler, and lots of helpful documentation to make it much easier to grasp the language. Good examples too; simple and to the point. And it isn’t a Windows-only package; there is also support for Linux and MacOSX.
One interesting difference from CPU programming languages is that GPUs support vector-math and matrix-math really efficiently. So, for example, a dot-product or cross-product is really fast to calculate, as are most operations that involve vectors. But this is also a new experience for people unfamiliar with GPU programming - learning to write your code in terms of whole vectors, instead of processing vector-components individually. It’s an important lesson to learn early, because it can yield very fast, or very slow, shader-programs!
It’s funny - as I get into this teaching job at Caltech, instead of writing up notes to remember things, I make Powerpoint slides instead. That’s nice - I already have a pretty decent introduction to the language all hashed out. And, I have a few interesting homework problems spec’d out too, to give students the flavor of GPU programming. Next I’m going to play with the simple Cg program included in the Cg Toolkit - shading a torus! I’m looking forward to it. I think I’m right on that cusp where it will stop being annoying and start being fun!