Why does Unity use HLSL instead of GLSL?
I am beginner in shader programming. I got my introduction (few minutes ago) to shader programming via Unity. I didn't know what HLSL was. So, I Googled and found this post: Difference b/w HLSL & GLSL I can't understand one thing. Unity was initially developed for OSX & introduced at WWDC. Also DirectX is windows only API & HLSL is the shader programming language for DirectX. However, Unity3D for OSX is written in OpenGL. OpenGL uses a standard shader programming language called "GLSL". So, I'm confused how Unity3D uses HLSL on OSX & why Unity didn't pick GLSL instead of HLSL. NOTE: I might be wrong somewhere. So please correct if something is wrong as I told I'm a beginner
As far as I know, Unity uses Cg (which is deprecated by NVIDIA since 2012, I have no idea why they still use it) as its shader language (which is really similar to HLSL) instead of HLSL or GLSL as stated here:
In Unity, shader programs are written in a variant of HLSL language (also called Cg but for most practical uses the two are the same).
Later on, Unity will convert the Cg shader into HLSL, GLSL or Metal based on what it needs (probably the target platform).
Then again, you can write GLSL directly as stated here and a note there:
However, use of raw GLSL is only recommended for testing, or when you know you are only targeting Mac OS X, OpenGL ES mobile devices, or Linux. In all normal cases, Unity will cross-compile Cg/HLSL into optimized GLSL when needed.
Additionally, I found a really good answer for the deprecated Cg here (read there, there are some good answers):
As NVIDIA is not supporting CG anymore, latest unity versions actually compile shaders using HLSL compiler and transform the resulting bytecode to GLSL.
Which also stated before and I missed it:
OpenGL Core, OpenGL ES 3 and Metal use Microsoft’s HLSL followed by bytecode translation into GLSL or Metal, using HLSLcc.
- Database Administration Tutorials
- Programming Tutorials & IT News
- Linux & DevOps World
- Entertainment & General News
- Games & eSport