Top 1K Features Creators Events Podcasts Books Extensions Interviews Blog Explorer CSV

Cg

< >

Cg, aka C for Graphics, is a shading language created in 2003.

#585on PLDB 21Years Old
Wikipedia

Cg (short for C for Graphics) is a high-level shading language developed by Nvidia in close collaboration with Microsoft for programming vertex and pixel shaders. Cg is based on the C programming language and although they share the same syntax, some features of C were modified and new data types were added to make Cg more suitable for programming graphics processing units. This language is only suitable for GPU programming and is not a general programming language. Read more on Wikipedia...


Example from Wikipedia:
// input vertex struct VertIn { float4 pos : POSITION; float4 color : COLOR0; }; // output vertex struct VertOut { float4 pos : POSITION; float4 color : COLOR0; }; // vertex shader main entry VertOut main(VertIn IN, uniform float4x4 modelViewProj) { VertOut OUT; OUT.pos = mul(modelViewProj, IN.pos); // calculate output coords OUT.color = IN.color; // copy input color to output OUT.color.z = 1.0f; // blue component of color = 1.0f return OUT; }

Language features

Feature Supported Example Token
Comments ✓ // A comment
Line Comments ✓ // A comment //
Semantic Indentation X

- Build the next great programming language · Add · About · Search · Keywords · Livestreams · Labs · Resources · Acknowledgements

Built with Scroll v144.0.0