Search Unity

  1. All Pro and Enterprise subscribers: find helpful & inspiring creative, tech, and business know-how in the new Unity Success Hub. Sign in to stay up to date.
    Dismiss Notice
  2. Dismiss Notice

Getting started with Cg

Discussion in 'Shaders' started by CamnJB, May 6, 2021.

  1. CamnJB


    May 6, 2021
    I'm starting to look into learning shader programming. I mostly use unreal at the moment but I'm experimenting a bit with unity. I have the book The Cg Tutorial but not sure how I'm supposed to practice the examples? The toolkit doesn't seem to work (I just get a blank windows terminal open up) and FX Composer doesn't seem to be the answer. I read that unity is compatible with Cg so I'm going to try and get the examples to run in unity? I know Cg is a bit outdated now but from what I've read the information is transferable to HLSL. Would I just be best off to ignore the book and look into HLSL?
  2. AcidArrow


    May 20, 2010
    To practice CG create an unlit shader in while using built it, make a material that uses that shader, put that material on a mesh on the screen and practice away.

    CG and HLSL are fairly similar, yes.
  3. mgear


    Aug 3, 2010
  4. bgolus


    Dec 7, 2012
    Unity does not use Cg anymore. Cg was abandoned by Nvidia nearly a decade ago, and Unity removed the last remaining use of Cg from their codebase many years ago. Lots of stuff in Unity remains using the term "cg", but it's all HLSL now.

    However all that said, Cg and Direct3D 9 style HLSL (which most of Unity's shaders and most documentation examples are written in) are nearly identical and share the same syntax and most of the same intrinsic functions. Things like the Cg Toolkit and FX Composer should be considered dead as they were both written close to 15 years ago and have not been maintained at all since then. And their usefulness for writing Unity shaders was always questionable as they had significantly different requirements than what Unity's shaders do, and Unity comes with a lot of helper functions unique to Unity that can make parts of writing shaders easier. Or at least a little shorter.

    The tutorial links @mgear posted, along with others you can find that are Unity specific are going to be far more useful for you today. Another good one that goes into a lot more depth is Catlike Coding's tutorials. There's also Freya Holmer's more recent videos.