Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have written some GLSL and Cg shaders a couple years back. I am starting another graphics engine project and I want to choose my technologies carefully so that my code will be accessible years down the road.

It seems to me that GLSL and Cg and HLSL are just slightly different syntaxes. Are there any other alternatives to these shader languages? It used to be I only cared about my code compiling correctly on ATI and nVidia hardware (their drivers, to be accurate) but these days I'd like it to function well on Intel's integrated solutions as well. From what I know since all vendors support OpenGL, GLSL should work, and HLSL is its counterpart for DirectX, so there shouldn't be problems there either. What about Cg?

Another question I have is whether these languages are still relevant for using newer techniques. I think they are, but maybe what I don't know is that nobody uses Cg anymore because it's gone out of style, or whatever. When I get around to learning and implementing these techniques myself, I'll surely find out all about the ins and outs, but I'd like to get a feeling for which languages and toolkits are being used NOW by those who are on the cutting edge, so I don't end up building my framework on software that will become obsolete.

share|improve this question
I question the reasoning behind this question. Why aren't you just writing shaders that the platform you want to ship your game on supports? –  Tetrad Aug 31 '11 at 22:11
Cg is widely used because it supports both DirectX and OpenGL. –  Raphael R. Aug 31 '11 at 22:13
add comment

2 Answers

up vote 5 down vote accepted

Thinking about your target platform is the right approach, and modern Intels actually have a quite good (for Intel) GLSL compiler. If you need to run on downlevel Intels you'll have to re-evaluate (I actually went back to ARB ASM recently for that very reason).

Beware of NVIDIA - their GLSL compiler will even accept some HLSL syntax/keywords, and if you only ever develop or test on NVIDIA you stand a real danger of producing something that will only ever work on NVIDIA.

I like HLSL a lot. One of the key differences is that whereas with GLSL the driver vendor must provide the compiler, with HLSL the compiler is provided by Microsoft as part of your DirectX install. That way you get to be certain that all of your users are on a standard baseline so far as the compiler is concerned, and can rule out one possible source of bugs or variations. The Effects framework makes things much easier for managing shaders in your program, although Microsoft are downplaying this a little in D3D11 (it's provided as source only which you must compile yourself and I'm not certain of the redistribution legalities).

share|improve this answer
This is interesting. Shouldn't there be a way to compile Cg to target ARB assembly? This link also is relevant to this discussion: opengl.org/wiki/Selecting_a_Shading_Language –  Steven Lu Sep 1 '11 at 1:09
+1: for mentioning the danger of NVIDIA-only OpenGL development. And Steven: Thanks for pointing me to that page. There is some outdated info on GLSL that needs culling. –  Nicol Bolas Sep 1 '11 at 3:37
This answer probably needs to be updated to reflect recent driver changes. –  Jimmy Shelter Aug 31 '12 at 8:23
add comment

GLSL and CG/HLSL are completely different, not just slightly. CG and HLSL were developed in parallel, and CG was nvidia's effort to create a standard shader language. The ARB rejected it in favour of GLSL.

CG is used because it supports OpenGL and DirectX.

All three shader languages are under active development:

  • The current GLSL 4.20 specification came out this August.
  • I can't find any dates for the current HLSL, but the current revision supports Shader Model 5, which came out with DirectX 11, which came out in October 2009.
  • The current CG toolkit was released in February 2011, the first version from 3.0 in July 2011.
share|improve this answer
It should be noted that "Cg" does not support OpenGL. NVIDIA's Cg compiler supports compilation to GLSL, and GLSL is supported on OpenGL. –  Nicol Bolas Sep 1 '11 at 3:40
I don't know if the "completely" is really justified. –  Christian Rau Sep 1 '11 at 14:28
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.