Archived

This topic is now archived and is closed to further replies.

Nairou

Shaders: Cg and HLSL

Recommended Posts

I have recently started reading up about shaders, what they are and how to use them in my engine, and I have heard a lot about both Microsoft''s HLSL and nVidia''s Cg. I''m curious what the differences are between these? Why would someone choose one over the other? Does the engine design have to accomodate anything for the two, or do they both get compiled externally into the normal shader assembly code shown in the DirectX documentation? Is the difference really just a matter of preference for the designers? I''m still getting this all sorted out in my head, so any clarification would be appreciated.

Share this post


Link to post
Share on other sites
I have just recently got into shaders myself. HLSL and Cg use the exact same programming syntax so if you know one, you know the other. They each just use a different interface for talking to the GPU.

Why would someone choose one over the other-
Which ever floats your boat really. I bought a book on Cg and I use microsofts HLSL interface.

Does the engine design have to accomodate anything for the two, or do they both get compiled externally into the normal shader assembly code shown in the DirectX documentation-
Look on nVidias and ATIs developer sections for information on how to write shaders using HLSL or Cg. There are two ways to load a shader into your program. One is to precompile it, and the other is to compile it at runtime. All the resources I''ve read say it''s best to compile a shader at runtime because efficiency changes can automatically be made depending on the hardware of a computer.

Is the difference really just a matter of preference for the designers- In my opinion yes. Though my understanding is that to use the CineFX features with Cg you''d need to use the Cg interface and not the HLSL interface (at least this is my understanding). Of course the CineFX feature set would only run on nVidia cards anyways.

I''m by no means a expert on shaders, but I hope the aforementioned helps at least get you vectored in the right direction =)

Good luck!

Share this post


Link to post
Share on other sites