Sign in to follow this  
head_hunter

Which shading language?

Recommended Posts

Hello everyone. I am at the point where I need to learn a shading language. I as far as I know, the major options are Cg, GLSL and HLSL. Could you give me list of pros and cons for each and a final recommendation? If I am not mistaken, the above languages are the high-level equivalents of the assembly-like instructions which were used earlier to program the GPU. Is there any reason to learn this older assembly language and not the high-level ones? Thanks.

Share this post


Link to post
Share on other sites
Quote:
Original post by head_hunter
I am at the point where I need to learn a shading language. I as far as I know, the major options are Cg, GLSL and HLSL. Could you give me list of pros and cons for each and a final recommendation?

The main difference is in how much documentation and sambles and such you can find for each. I learned HLSL, but I had a hell of a time finding articles and tutorials about it. Cg seemed much better in that respect. And I think (but haven't checked) that GLSL is the worst of the bunch there. Haven't really seen any samples or documentation or anything for that. (But it probably exists somewhere)
On the other hand, at least HLSL and Cg are so similar it's crazy. I assume GLSL is too, but at least the two former are practically identical. When I learned HLSL, I actually used a few Cg articles to explain things the HLSL documentation skipped.

Quote:

If I am not mistaken, the above languages are the high-level equivalents of the assembly-like instructions which were used earlier to program the GPU. Is there any reason to learn this older assembly language and not the high-level ones?

Same as always. It never hurts to know what's going on under the hood. But no, you don't need it.

Share this post


Link to post
Share on other sites
There's several nice GLSL examples at lighthouse3d. And the orange book holds all the documentation you'll probably need.

HLSL is DirectX only
GLSL is OpenGL only
CG can work on both. But I don't know how well it's going to do in the future. (I don't think ATI has a CG compiler, so it compiles to Shader ASM, and I don't know if ASM is going to updated with new features, hopefully someone else can fill that knowledge in)

All of the languages are pretty similar, so after learning one, learning another shouldn't be too bad.

Share this post


Link to post
Share on other sites
GLSL is OpenGL only.
HLSL is DX only.
Cg works on both OGL and DX HOWEVER in the case of OpenGL it is limited in usefullness somewhat. The reason for this is that Cg has to compile down to code for one of the shading extensions. On NV hardware this isnt a huge problem as they produce their own fragment and vertex program extensions to get the best out of their hardware.

ATI on the other hand only support the ARB vertex and fragment program extensions and GLSL extensions. afaik Cg doesnt allow you to compile Cg code to GLSL and use that extension so you are stuck with going for VP/FP. However these extensions are as good as dead. They never made it to core OpenGL and all the focus now from the ARB is on GLSL, as such the functionality is locked at its current level (around PS2.0 iirc) and will never be extended, so any new functionality, such as anything in SM3.0, will never be avaible via it and by extension not to Cg either on ATI hardware (unless Cg is adjusted to output to GLSL).

Also, Cg can only target ATI's newer cards (9500 and up) the previous generation isnt support (9200 and down) as no one has produced the code to let it target ATI's pre-vp/fp shader system (it would be down to ATI todo and its not like they are going to support a competitors product now is it and NV arent going todo it for the same reason).

Share this post


Link to post
Share on other sites
My recommendation would be HLSL is you're using DirectX or GLSL is you're using OpenGL - Cg has issues with ATI hardware as previous posters have mentioned. While HLSL and GLSL are different, they are similar enough that you'll be ok if you learn either.

Share this post


Link to post
Share on other sites
i'd also recommend going with HLSL. it has the advantage that if you write a shader that isn't working as you expected, then you can debug it in visual studio. set breakpoints, look at the value of the variables as you step through the code, etc. very handy.

learning the shader assembly is a good idea. HLSL compiler isn't perfect and can produce very inefficient code sometimes. if you have an understanding of the shader assembly you'll be able to write HLSL that compiles efficiently.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this