GLSL - OpenGL - WebGL

CG is not an old version of HLSL, it’s a shader language by Nvidia that’s almost identical to DX9 era HLSL but has compilers that could output DX9 HLSL or OpenGL 3.0 GLSL shaders.

Current ShaderLab is no longer Cg, and is essentially straight HLSL inside the CGPROGRAM blocks, with some minor “magic” mixed in (mostly in the form of defines in cginc files) for cross platform compiling, and their own fork of hlsl2glsl, an open source project that started as AMD’s version of the same problem Nvidia was trying to solve with Cg.

Obviously things like CGPROGRAM, the .cginc file extension, and using “fragment” shaders instead if “pixel” shaders are a hold over from being Cg, but the actual shader code is all HLSL to the point of there being a few commands that Cg has that HLSL doesn’t which will not compile anymore.

ShaderToy is great for getting an idea of what can be done within a fragment shader, but because it doesn’t offer any way to render meshes or use vertex shaders you’re missing a large set of tools you would actual want to use for real time work. The vast majority of really impressive ShaderToys can’t run anywhere close to 60fps at full screen for example. It’s still a great utility for playing with ideas and brushing up on your math skills though.

As for GLSL / HLSL, there are of course minor differences that don’t overlap, but you usually have to get pretty far in before you hit those. Most of the time you can take any basic chunk of GLSL and translate it into HLSL by just searching for any use of “vec” and replacing it with “float”.

2 Likes