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.


closed as off-topic by Josh Feb 17 '16 at 19:02

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about "how to get started," "what to learn next," or "which technology to use" are discussion-oriented questions which involve answers that are either based on opinion, or which are all equally valid. Those kinds of questions are outside the scope of this site. Visit our help center for more information." – Josh
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 3
    \$\begingroup\$ 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? \$\endgroup\$ – Tetrad Aug 31 '11 at 22:11
  • 1
    \$\begingroup\$ Cg is widely used because it supports both DirectX and OpenGL. \$\endgroup\$ – Raphael R. Aug 31 '11 at 22:13

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).

  • \$\begingroup\$ 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 \$\endgroup\$ – Steven Lu Sep 1 '11 at 1:09
  • 1
    \$\begingroup\$ +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. \$\endgroup\$ – Nicol Bolas Sep 1 '11 at 3:37
  • \$\begingroup\$ This answer probably needs to be updated to reflect recent driver changes. \$\endgroup\$ – Maximus Minimus Aug 31 '12 at 8:23

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.
  • \$\begingroup\$ It should be noted that "Cg" does not support OpenGL. NVIDIA's Cg compiler supports compilation to GLSL, and GLSL is supported on OpenGL. \$\endgroup\$ – Nicol Bolas Sep 1 '11 at 3:40
  • 2
    \$\begingroup\$ I don't know if the "completely" is really justified. \$\endgroup\$ – Christian Rau Sep 1 '11 at 14:28

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