Till KTH:s startsida Till KTH:s startsida

Cg Programming

This page contains general information and tips for programming in Cg.

The Cg toolkit comes with a bunch of documentation. The User's Manual in particular is a surprisingly good source of information. If you don't have access to a computer with the Cg toolkit installed, you can download the User's Manual here.

  • Page 34 in the User's Manual (p. 52 in the actual PDF) has a table of math functions and how they work.
  • Keep in mind that operators, such as '*', only work on specific data types. e.g: For matrix/vector multiplication you need to use the math function mul(M, N).
  • When translating math formulae to code, think about what the formula does. Some notation may be ambiguous, or visually similar to something else. Some mix-ups may produce valid, although incorrect results. If your program works, but looks incorrect, then this is a likely reason.