HLSL vs Cg: Any significant difference?

Started by
14 comments, last by NLDEV 19 years, 5 months ago
Originally when I had first started getting into shader languages I was really looking forward to using Cg, but then it looked like it was never getting updated. On top of that nVidia started releasing FX Composer (um.. ok?). It really didn't make sense to me. I'll be honest, this really feels like a situation where not only is there no right solution, but no good solution either.
Advertisement
Quote:Original post by Anonymous Poster
Correct me if I am wrong here, but for those who want to go for API independence, neither HLSL or GLSL is an appropriate choice, correct? Afterall, no one wants to write two different versions of the same shader for their game.
That's a fair point. Though from what I understand, HLSL and GLSL are pretty similar - such that porting shaders from one to the other shouldn't be difficult. If you wanted to avoid porting altogether then Cg could well be a better bet.

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

API independence is overrated. If you want to support non-Windows workstation/PC platforms (x86 Linux, Macs, maybe some other Unix flavours on x86, PowerPC, maybe even Itanium) then go with OpenGL and GLSL. If you are happy with just Windows support (and maybe easier porting to Microsoft console platforms) then go with Direct3D and HLSL. If you want to support other console platforms then there are no higher level shader languages or open APIs so the whole point is moot.

OpenGL is the closest thing to a cross platform graphics API there is. There's little point for most people in building an API independet renderer on top of it. Far better just to pick your API and get on with making your game.

Game Programming Blog: www.mattnewport.com/blog

Quote:Original post by superpig
Quote:Original post by gjaegy
superpig: I thought CG development still go on. They released a beta version some weeks ago...
Really? They're certainly not making a big deal of it any more - they're more pushing their HLSL-based tools, like FX Composer.


Cg and HLSL are pretty much the same language, except that nVidia's Cg has some extra facilities to support OpenGL. In fact, Cg and HLSL were both co-developed by Microsoft and nVidia. So while you might hear less about Cg and more about HLSL as time progresses, Cg lives on in DirectX with a different name.

FX Composer is both an HLSL and a Cg tool, because the shaders you write with FX Composer can still target OpenGL using the Cg Toolkit SDK. But for the most part, it's 99.9% compatible with HLSL... right down to the use of techniques and effects.

One problem that the Cg Toolkit SDK doesn't support that DirectX does is vertex and pixel fragment linking. This allows you to construct shaders from multiple fragments that implement different aspects of a complete shader. It's exposed through the CG/HLSL keywords "vertexfragment" and "pixelfragment". In DirectX, you link fragments together using ID3DXFragmentLinker or Microsoft.DirectX.Direct3D.FragmentLinker.

I've complained to nVidia about this, so hopefully they will get around to supporting it in their tools. They're currently accepting input from the development community on which direction people would like to see nVidia's development tools go.

While semantically, there are many similiarities between HLSL/Cg and GLSL, syntactically they are different languages. And afaik, GLSL does not support fragment linking in any form.

The GLSL or OpenGL Shading Language was pioneerd by 3DLabs in their OpenGL 2.0 proposal, which was mostly scrapped, as they originally proposed to make OpenGL an object-oriented C++ API. But as you may know, this isn't the case with the OpenGL 2.0 specification today. Yet, GLSL was accepted by the OpenGL ARB over Cg, which nVidia pushed hard.

ATI and Discreet are working on some tools for abstracting the underying shader architecture. ATI's Ashli technology can transform an HLSL, GLSL, or a RenderMan shader into an either a compiled HLSL or GLSL shader. Discreet has integrated Ashli into 3DS Max 7 and has add a transformation pipeline for converting 3DS Max materials into compiled HLSL or GLSL shaders.

However, after looking at it, I still thought that these technologies were rather immature, as they generated subpar code and there were no good user interfaces to control the transformation process. I expect it will improve over time though.

I'm not sure what Alias or SoftImage have in mind for their DCC toolsets.
Now I'm a bit confused. Other than platform, whats the difference between HLSL and GLSL? I just assumed GLSL was OpenGL's way of using HLSL shaders.
Quote:Original post by Nairou
Now I'm a bit confused. Other than platform, whats the difference between HLSL and GLSL? I just assumed GLSL was OpenGL's way of using HLSL shaders.


GLSL is OpenGL's shading language (which is different than HLSL), which has recently been made part of the OpenGL core.

This topic is closed to new replies.

Advertisement