# Cg

> shading language

**Wikidata**: [Q1024657](https://www.wikidata.org/wiki/Q1024657)  
**Wikipedia**: [English](https://en.wikipedia.org/wiki/Cg_(programming_language))  
**Source**: https://4ort.xyz/entity/cg

## Summary
Cg is a specialized programming language designed to write shaders that control how 3-D surfaces appear and how vertices are processed on a GPU, featuring vector/matrix primitives, texture-sampling built-ins, and GPU-specific qualifiers that enable efficient execution on massively parallel graphics hardware.

## Key Facts
- Classified as a subclass of programming language in Wikidata (sitelink count: 161)
- First major standardized shading language, OpenGL Shading Language (GLSL), released in 2004
- OpenGL ES Shading Language introduced in 2009 for mobile and embedded GPUs
- High-Level Shader Language (HLSL) has the highest sitelink count (17) among Microsoft-centric sources
- Open Shading Language created by Sony Pictures Imageworks optimized for offline film rendering
- Alternative names include Japanese (シェーダ言語), Korean (Shade語言), and Chinese (着色语言)
- Wikidata item sitelink count: 5; Wikipedia articles exist in multiple languages
- Freebase ID /m/022l10
- Microsoft Academic ID (discontinued) 18670160
- Encyclopedia of China (3rd ed.) ID 154912
- Cg has sitelink count: 15
- Wikipedia title: Cg (programming language)
- Macports port: cg-toolkit
- Wikidata description: shading language
- Google Knowledge Graph ID: /g/11bc57sfg6

## FAQs
### Q: What is Cg used for?
A: Cg is used to write shaders that control how 3-D surfaces appear and how vertices are processed on a GPU, enabling real-time rendering pipelines.

### Q: What makes Cg different from other shading languages?
A: Cg extends a base programming language with vector/matrix primitives, texture-sampling built-ins, and GPU-specific qualifiers, letting a single source file run efficiently on massively parallel graphics hardware.

### Q: Is Cg tied to a specific graphics API?
A: Yes, Cg is native to DirectX and was designed to work with Microsoft's graphics ecosystem.

### Q: Can Cg run on other APIs?
A: Not directly; source must be transpiled or rewritten because each language uses different entry-point semantics, coordinate conventions, and built-in function names.

## Why It Matters
Shading languages turned fixed-function graphics pipelines into programmable ones, enabling the leap from flat-shaded triangles to cinematic lighting, normal mapping, and real-time ray tracing. By exposing the GPU's parallel execution model through C-like syntax, they let artists and engineers encode visual rules—how metallic a surface looks, how light scatters under skin, or how water ripples—without changing the underlying engine code. This programmability powers everything from mobile game visuals to high-end film post-production, and underpins the modern GPU compute revolution that now accelerates machine-learning and scientific simulation.

## Notable For
- First widespread adoption via GLSL (2004) standardized by the Khronos Group, unifying vendor-specific assembler shaders
- Dominance in PC gaming and DirectX ecosystem with HLSL's high sitelink count (17)
- Only major shading language purpose-built for offline, film-quality ray tracing rather than real-time rasterization
- Newest entry, aiming to bring safe, portable GPU code to web browsers with a single source language
- Multiple national-script aliases show the topic's global relevance in computer-graphics education

## Body
### Definition and Purpose
A shading language is a domain-specific programming language whose grammar and built-in functions are optimized for writing vertex, geometry, and fragment shaders. Shaders are short programs executed by the GPU to determine vertex positions, pixel colors, and intermediate geometric attributes. The language adds vector/matrix data types, texture-sampling intrinsics, and qualifiers that map variables to GPU registers, enabling massively parallel execution.

### Historical Milestones
- 2001 – NVIDIA introduces Cg (C for Graphics) as a high-level shading language
- 2004 – Cg becomes the first major standardized shading language alongside OpenGL 2.0, replacing vendor-specific assembler
- 2009 – OpenGL ES Shading Language ships, tailoring GLSL for constrained mobile GPUs
- Microsoft's High-Level Shader Language (HLSL) evolves in parallel, tied to DirectX 9 and onward
- 2008 – Sony Pictures Imageworks releases Open Shading Language (OSL) for offline rendering
- 2014 – Apple introduces Metal Shading Language, unifying graphics and compute on iOS/macOS
- 2019 – Khronos begins work on WebGPU Shading Language, targeting secure cross-platform web deployment

### Language Family Tree
All major shading languages borrow C-style syntax but diverge in semantics:
- Cg uses "in/out" qualifiers and layout locations for Vulkan compatibility
- HLSL adopts semantics like "SV_Position" for Direct3D linkage
- Metal uses "[[attribute]]" syntax and supports pointer-based argument buffers
- OSL adds closures and automatic differentiation for ray-tracing integrators

### Current Ecosystem
Modern engines (Unity, Unreal, Godot) abstract differences via shader graphs or cross-compilers such as SPIR-V, but developers still hand-write performance-critical kernels in the native shading language of the target API.

### Technical Specifications
- Cg has sitelink count: 15
- Website: https://developer.nvidia.com/cg-toolkit
- Freebase ID: /m/022l10
- Macports port: cg-toolkit
- Wikidata description: shading language
- Google Knowledge Graph ID: /g/11bc57sfg6

### Community and Adoption
Cg has been adopted by various game engines and graphics applications, though it's less commonly used today compared to newer shading languages like GLSL and HLSL. It remains part of NVIDIA's ecosystem and is still referenced in academic and technical literature.

## References

1. Freebase Data Dumps. 2013