<s>
Cg	B-Language
(	O
short	O
for	O
C	B-Language
for	I-Language
Graphics	I-Language
)	O
and	O
High-Level	B-Language
Shader	I-Language
Language	I-Language
(	O
HLSL	B-Language
)	O
are	O
two	O
names	O
given	O
to	O
a	O
high-level	B-Language
shading	I-Language
language	I-Language
developed	O
by	O
Nvidia	O
and	O
Microsoft	O
for	O
programming	B-General_Concept
shaders	O
.	O
</s>
<s>
Cg/HLSL	O
is	O
based	O
on	O
the	O
C	B-Language
programming	I-Language
language	I-Language
and	O
although	O
they	O
share	O
the	O
same	O
core	O
syntax	O
,	O
some	O
features	O
of	O
C	B-Language
were	O
modified	O
and	O
new	O
data	O
types	O
were	O
added	O
to	O
make	O
Cg/HLSL	O
more	O
suitable	O
for	O
programming	B-General_Concept
graphics	B-Architecture
processing	I-Architecture
units	I-Architecture
.	O
</s>
<s>
Two	O
main	O
branches	O
of	O
the	O
Cg/HLSL	O
language	O
exist	O
:	O
the	O
Nvidia	B-Language
Cg	I-Language
compiler	O
(	O
cgc	O
)	O
which	O
outputs	O
DirectX	B-Application
or	O
OpenGL	B-Application
and	O
the	O
Microsoft	O
HLSL	B-Language
which	O
outputs	O
DirectX	B-Application
shaders	O
in	O
bytecode	O
format	O
.	O
</s>
<s>
Nvidia	O
's	O
cgc	O
was	O
deprecated	B-General_Concept
in	O
2012	O
,	O
with	O
no	O
additional	O
development	O
or	O
support	O
available	O
.	O
</s>
<s>
HLSL	B-Language
shaders	O
can	O
enable	O
many	O
special	O
effects	O
in	O
both	O
2D	O
and	O
3D	O
computer	O
graphics	O
.	O
</s>
<s>
The	O
Cg/HLSL	O
language	O
originally	O
only	O
included	O
support	O
for	O
vertex	O
shaders	O
and	O
pixel	O
shaders	O
,	O
but	O
other	O
types	O
of	O
shaders	O
were	O
introduced	O
gradually	O
as	O
well	O
:	O
</s>
<s>
DirectX	B-Application
10	I-Application
(	O
Shader	B-Language
Model	I-Language
4	I-Language
)	O
and	O
Cg	B-Language
2.0	O
introduced	O
geometry	O
shaders	O
.	O
</s>
<s>
DirectX	B-Application
11	O
(	O
Shader	B-Language
Model	I-Language
5	O
)	O
introduced	O
compute	B-Operating_System
shaders	I-Operating_System
(	O
GPGPU	B-Architecture
)	O
and	O
tessellation	O
shaders	O
(	O
hull	O
and	O
domain	O
)	O
.	O
</s>
<s>
The	O
latter	O
is	O
present	O
in	O
Cg	B-Language
3.1	O
.	O
</s>
<s>
DirectX	B-Application
12	O
(	O
Shader	B-Language
Model	I-Language
6.3	O
)	O
introduced	O
ray	B-Algorithm
tracing	I-Algorithm
shaders	O
(	O
ray	O
generation	O
,	O
intersection	O
,	O
bit	O
/closest	O
hit	O
/	O
miss	O
)	O
.	O
</s>
<s>
Due	O
to	O
technical	O
advances	O
in	O
graphics	O
hardware	O
,	O
some	O
areas	O
of	O
3D	O
graphics	O
programming	B-General_Concept
have	O
become	O
quite	O
complex	O
.	O
</s>
<s>
In	O
the	O
beginning	O
,	O
vertex	O
and	O
pixel	O
shaders	O
were	O
programmed	O
at	O
a	O
very	O
low	O
level	O
with	O
only	O
the	O
assembly	O
language	O
of	O
the	O
graphics	B-Architecture
processing	I-Architecture
unit	I-Architecture
.	O
</s>
<s>
A	O
portable	O
,	O
higher	O
level	O
language	O
for	O
programming	B-General_Concept
the	O
GPU	B-Architecture
was	O
needed	O
,	O
so	O
Cg	B-Language
was	O
created	O
to	O
overcome	O
these	O
problems	O
and	O
make	O
shader	O
development	O
easier	O
.	O
</s>
<s>
Some	O
of	O
the	O
benefits	O
of	O
using	O
Cg	B-Language
over	O
assembly	O
are	O
:	O
</s>
<s>
Cg	B-Language
code	O
is	O
portable	O
to	O
a	O
wide	O
range	O
of	O
hardware	O
and	O
platforms	O
,	O
unlike	O
assembly	O
code	O
,	O
which	O
usually	O
depends	O
on	O
hardware	O
and	O
the	O
platforms	O
it	O
's	O
written	O
for	O
.	O
</s>
<s>
The	O
Cg	B-Language
compiler	O
can	O
optimize	O
code	O
and	O
do	O
lower	O
level	O
tasks	O
automatically	O
,	O
which	O
are	O
hard	O
to	O
do	O
and	O
error	O
prone	O
in	O
assembly	O
.	O
</s>
<s>
Cg	B-Language
has	O
six	O
basic	O
data	O
types	O
.	O
</s>
<s>
Some	O
of	O
them	O
are	O
the	O
same	O
as	O
in	O
C	B-Language
,	O
while	O
others	O
are	O
especially	O
added	O
for	O
GPU	B-Architecture
programming	B-General_Concept
.	O
</s>
<s>
Cg	B-Language
also	O
features	O
vector	O
and	O
matrix	O
data	O
types	O
that	O
are	O
based	O
on	O
the	O
basic	O
data	O
types	O
,	O
such	O
as	O
float3	O
and	O
float4x4	O
.	O
</s>
<s>
Such	O
data	O
types	O
are	O
quite	O
common	O
when	O
dealing	O
with	O
3D	O
graphics	O
programming	B-General_Concept
.	O
</s>
<s>
Cg	B-Language
also	O
has	O
struct	O
and	O
array	O
data	O
types	O
,	O
which	O
work	O
in	O
a	O
similar	O
way	O
to	O
their	O
C	B-Language
equivalents	O
.	O
</s>
<s>
Cg	B-Language
supports	O
a	O
wide	O
range	O
of	O
operators	O
,	O
including	O
the	O
common	O
arithmetic	O
operators	O
from	O
C	B-Language
,	O
the	O
equivalent	O
arithmetic	O
operators	O
for	O
vector	O
and	O
matrix	O
data	O
types	O
,	O
and	O
the	O
common	O
logical	O
operators	O
.	O
</s>
<s>
Cg	B-Language
shares	O
the	O
basic	O
control	O
structures	O
with	O
C	B-Language
,	O
like	O
if/else	O
,	O
while	O
,	O
and	O
for	O
.	O
</s>
<s>
Cg	B-Language
implements	O
many	O
C	B-Language
preprocessor	I-Language
directives	O
and	O
its	O
macro	O
expansion	O
system	O
.	O
</s>
<s>
Cg	B-Language
programs	O
are	O
built	O
for	O
different	O
shader	O
profiles	O
that	O
stand	O
for	O
GPUs	B-Architecture
with	O
different	O
capabilities	O
.	O
</s>
<s>
As	O
the	O
number	O
of	O
profile	O
and	O
shader	O
types	O
cropped	O
up	O
,	O
Microsoft	O
has	O
switched	O
to	O
use	O
the	O
term	O
"	O
Shader	B-Language
Model	I-Language
"	O
to	O
group	O
a	O
set	O
of	O
profiles	O
found	O
in	O
a	O
generation	O
of	O
GPUs	B-Architecture
.	O
</s>
<s>
Cg	B-Language
supports	O
some	O
of	O
the	O
newer	O
profiles	O
up	O
to	O
Shader	B-Language
Model	I-Language
5.0	O
as	O
well	O
as	O
translation	O
to	O
glsl	B-Language
or	O
hlsl	B-Language
.	O
</s>
<s>
PS	B-Operating_System
1.0	O
—	O
Unreleased	O
3dfx	O
Rampage	O
,	O
DirectX	B-Application
8	I-Application
.	O
</s>
<s>
PS	B-Operating_System
1.1	O
—	O
GeForce	O
3	O
,	O
DirectX	B-Application
8	I-Application
.	O
</s>
<s>
PS	B-Operating_System
1.2	O
—	O
3Dlabs	O
Wildcat	O
VP	O
,	O
DirectX	B-Application
8.0a	I-Application
.	O
</s>
<s>
PS	B-Operating_System
1.3	O
—	O
GeForce	O
4	O
Ti	O
,	O
DirectX	B-Application
8.0a	I-Application
.	O
</s>
<s>
PS	B-Operating_System
1.4	O
—	O
Radeon	B-Device
8500-9250	I-Device
,	O
Matrox	B-Device
Parhelia	I-Device
,	O
DirectX	B-Application
8.1	I-Application
.	O
</s>
<s>
Shader	B-Language
Model	I-Language
2.0	I-Language
—	O
Radeon	B-Device
9500-9800/X300	I-Device
-X600	I-Device
,	O
DirectX	B-Application
9	I-Application
.	O
</s>
<s>
Shader	O
Model	O
2.0a	O
—	O
GeForce	O
FX/PCX	O
-optimized	O
model	O
,	O
DirectX	B-Application
9.0a	I-Application
.	O
</s>
<s>
Shader	B-Language
Model	I-Language
2.0b	O
—	O
Radeon	O
X700-X850	O
shader	B-Language
model	I-Language
,	O
DirectX	B-Application
9.0b	I-Application
.	O
</s>
<s>
Shader	B-Language
Model	I-Language
3.0	I-Language
—	O
Radeon	B-Device
X1000	I-Device
and	O
GeForce	O
6	O
,	O
DirectX	B-Application
9.0c	I-Application
.	O
</s>
<s>
Shader	B-Language
Model	I-Language
4.0	I-Language
—	O
Radeon	O
HD	O
2000	O
and	O
GeForce	O
8	O
,	O
DirectX	B-Application
10	I-Application
.	O
</s>
<s>
Shader	O
Model	O
4.1	O
—	O
Radeon	O
HD	O
3000	O
and	O
GeForce	O
200	O
,	O
DirectX	B-Application
10.1	I-Application
.	O
</s>
<s>
Shader	B-Language
Model	I-Language
5.0	O
—	O
Radeon	O
HD	O
5000	O
and	O
GeForce	O
400	O
,	O
DirectX	B-Application
11	O
.	O
</s>
<s>
Shader	B-Language
Model	I-Language
5.1	O
—	O
GCN	O
1+	O
,	O
Fermi+	O
,	O
DirectX	B-Application
12	O
(	O
11_0+	O
)	O
with	O
WDDM	O
2.0	O
.	O
</s>
<s>
Shader	B-Language
Model	I-Language
6.0	O
—	O
GCN	O
1+	O
,	O
Kepler+	O
,	O
DirectX	B-Application
12	O
(	O
11_0+	O
)	O
with	O
WDDM	O
2.1	O
.	O
</s>
<s>
Shader	B-Language
Model	I-Language
6.1	O
—	O
GCN	O
1+	O
,	O
Kepler+	O
,	O
DirectX	B-Application
12	O
(	O
11_0+	O
)	O
with	O
WDDM	O
2.3	O
.	O
</s>
<s>
Shader	B-Language
Model	I-Language
6.2	O
—	O
GCN	O
1+	O
,	O
Kepler+	O
,	O
DirectX	B-Application
12	O
(	O
11_0+	O
)	O
with	O
WDDM	O
2.4	O
.	O
</s>
<s>
Shader	B-Language
Model	I-Language
6.3	O
—	O
GCN	O
1+	O
,	O
Kepler+	O
,	O
DirectX	B-Application
12	O
(	O
11_0+	O
)	O
with	O
WDDM	O
2.5	O
.	O
</s>
<s>
Shader	B-Language
Model	I-Language
6.4	O
—	O
GCN	O
1+	O
,	O
Kepler+	O
,	O
Skylake+	O
,	O
DirectX	B-Application
12	O
(	O
11_0+	O
)	O
with	O
WDDM	O
2.6	O
.	O
</s>
<s>
Shader	B-Language
Model	I-Language
6.5	O
—	O
GCN	O
1+	O
,	O
Kepler+	O
,	O
Skylake+	O
,	O
DirectX	B-Application
12	O
(	O
11_0+	O
)	O
with	O
WDDM	O
2.7	O
.	O
</s>
<s>
As	O
in	O
C	B-Language
,	O
Cg/HLSL	O
features	O
a	O
set	O
of	O
functions	O
for	O
common	O
tasks	O
in	O
GPU	B-Architecture
programming	B-General_Concept
.	O
</s>
<s>
Some	O
of	O
the	O
functions	O
have	O
equivalents	O
in	O
C	B-Language
,	O
like	O
the	O
mathematical	O
functions	O
abs	O
and	O
sin	O
,	O
while	O
others	O
are	O
specialized	O
in	O
GPU	B-Architecture
programming	B-General_Concept
tasks	O
,	O
like	O
the	O
texture	O
mapping	O
functions	O
tex1D	O
and	O
tex2D	O
.	O
</s>
<s>
Cg	B-Language
programs	O
are	O
merely	O
vertex	O
and	O
pixel	O
shaders	O
,	O
and	O
they	O
need	O
supporting	O
programs	O
that	O
handle	O
the	O
rest	O
of	O
the	O
rendering	O
process	O
.	O
</s>
<s>
Cg	B-Language
can	O
be	O
used	O
with	O
two	O
graphics	O
APIs	B-General_Concept
:	O
OpenGL	B-Application
or	O
DirectX	B-Application
.	O
</s>
<s>
Each	O
has	O
its	O
own	O
set	O
of	O
Cg	B-Language
functions	O
to	O
communicate	O
with	O
the	O
Cg	B-Language
program	O
,	O
like	O
setting	O
the	O
current	O
Cg	B-Language
shader	O
,	O
passing	O
parameters	O
,	O
and	O
such	O
tasks	O
.	O
</s>
<s>
In	O
addition	O
to	O
being	O
able	O
to	O
compile	O
Cg	B-Language
source	O
to	O
assembly	O
code	O
,	O
the	O
Cg	B-Language
runtime	O
also	O
has	O
the	O
ability	O
to	O
compile	O
shaders	O
during	O
execution	O
of	O
the	O
supporting	O
program	O
.	O
</s>
<s>
The	O
Cg	B-Language
dialect	O
has	O
only	O
ever	O
had	O
one	O
compiler	O
,	O
in	O
the	O
form	O
of	O
Nvidia	O
's	O
Cg	B-Language
toolkit	O
.	O
</s>
<s>
Microsoft	O
has	O
released	O
two	O
compilers	O
for	O
HLSL	B-Language
.	O
</s>
<s>
It	O
was	O
deprecated	B-General_Concept
in	O
favor	O
of	O
the	O
open-source	O
LLVM-based	O
DXC	O
(	O
DirectXShaderCompiler	O
)	O
with	O
support	O
for	O
newer	O
HLSL	B-Language
features	O
.	O
</s>
<s>
DXC	O
can	O
also	O
emit	O
SPIR-V	B-Application
bytecode	O
.	O
</s>
<s>
The	B-Library
Khronos	I-Library
Group	I-Library
has	O
also	O
written	O
a	O
LLVM-based	O
HLSL	B-Language
compiler	O
,	O
in	O
the	O
form	O
of	O
a	O
frontend	O
for	O
glslang	B-Language
,	O
their	O
GLSL-to-SPIR_V	O
compiler	O
.	O
</s>
<s>
Support	O
for	O
SPIR-V	B-Application
means	O
that	O
the	O
shaders	O
can	O
be	O
cross-platform	O
,	O
no	O
longer	O
limiting	O
them	O
to	O
a	O
DirectX	B-Application
stack	O
.	O
</s>
<s>
This	O
task	O
was	O
previously	O
performed	O
by	O
source-level	O
converters	O
like	O
HLSL2GLSL	B-Application
,	O
but	O
the	O
resulting	O
code	O
is	O
often	O
bloated	O
.	O
</s>
<s>
The	O
PlayStation	O
Shading	B-Language
Language	I-Language
is	O
based	O
on	O
Cg/HLSL	O
.	O
</s>
<s>
The	O
ReshadeFX	O
shading	B-Language
language	I-Language
is	O
also	O
based	O
on	O
Cg/HLSL	O
.	O
</s>
<s>
Shaders	O
written	O
in	O
ReshadeFX	O
are	O
compiled	O
to	O
OpenGL	B-Application
,	O
DX	O
,	O
or	O
Vulkan	O
and	O
injected	O
into	O
games	O
to	O
act	O
as	O
post-processing	O
filters	O
.	O
</s>
<s>
R.U.S.E.	B-Application
</s>
