Introduction
A .cg file holds a program in Cg, “C for graphics”, the shading language
that NVIDIA developed in collaboration with Microsoft. It is the same language as
HLSL under a different name. NVIDIA now lists the Cg
Toolkit as a legacy product at the end of its life. The last release is Cg 3.1, and
NVIDIA points to GLSL or HLSL as the replacement.
A .cgfx file is a CgFX effect: a text file that groups programs with the
state needed to draw with them. It is the same format as the .fx effect
files of Microsoft’s DirectX 9. The Cg runtime loads a .cgfx or
.fx file with cgCreateEffectFromFile, and a .cg
or .hlsl file with cgCreateProgramFromFile.
Structure
A Cg file is plain text with C-like syntax. Inputs and outputs of a program carry
semantics, written after a colon, such as POSITION and COLOR,
which tie them to the stages of the graphics pipeline. A parameter marked
uniform is set from the application. A CgFX file adds
technique blocks that contain pass blocks, and a pass sets
render state and names the programs to use.
void main(float4 position : POSITION,
float4 color : COLOR,
out float4 oPosition : POSITION,
out float4 oColor : COLOR,
uniform float4x4 modelViewProj)
{
oPosition = mul(modelViewProj, position);
oColor = color;
}
Not described
Known, not yet covered
- Reference: this overview is the only page. The language has no reference pages: the types, semantics and profiles, the standard library functions, the CgFX syntax for techniques, passes, state assignments and annotations, and the
cgccompiler options. The Cg 3.1 documentation describes them. - Reference: the CgFX state assignments for each graphics interface and the assembly forms a profile can compile to are not described.
- Viewer: there is no viewer for these formats yet, and nothing is compiled or checked.
Links
Software
- Cg Toolkit – NVIDIA’s legacy compiler
cgcand runtime (Windows, macOS, Linux)
Reference
- Cg 3.1 documentation – NVIDIA’s reference pages
- The Cg Tutorial: introduction – what Cg is and how it relates to HLSL
- The Cg Tutorial: CgFX overview – the effect file format
- cgc – the command-line compiler