Hi, I've read here : http://unity3d.com/support/documentation/Manual/Shaders.html that Unity's shader can be written in HLSL or CG. However the rest of the reference doesn't mention HLSL anymore and everywhere I look I read that CG has to be used. It seems like the conversion from HLSL to CG is just a minor problem still I would like to use HLSL directly. The link above indicates that something like that is possible. I'm searching for something like Code (csharp): HLSLProgram //... ENDHLSL Is that possible ? If possible, what problems will arise due to use of HLSL ?
I wonder if it's a typo. I don't think I've seen HLSL here, but GLSL is supported and undocumented. That page used to say "GLSL".
Well, if there's no way of using hlsl in shaderlab, how much work is it to convert hlsl to cg ? I've heard they're pretty similar in syntax.
I've found an interesting thread. http://forum.beyond3d.com/archive/index.php/t-7529.html It says that the cg compiler can compile HLSL. However the thread is not actual, so I'm wondering: Is HLSL still compatible with CG ?
HLSL and CG are the same except for a few functions that were introduced in CG later. HLSL was developed by microsoft and Nvidia together to be able to use high level languages to write instructions for the vertex processor as well as the shader processor in your GPU.
Are there functions in HLSL that CG doesn't have ? If only CG has been extended I guess there should be no problems with just pasting HLSL between CGPROGRAM and ENDCG
HLSL and CG are based on the same concept and "c" like language. Cg and HLSL were developed in parallel as a partnership between nVidia and Microsoft. Their syntax and semantics " originally" were identical. but as Microsoft decided to develop HLSL on it's own, there is lot of little diferences that makes CG and HLSL to be "incompatible". some basic function like mul(); doesn't work the same way. the parameter order are not the same: Code (csharp): [B]HLSL[/B]: mul (matrix, vector); [B]CG[/B]: mul(vector, matrix); plus each language have some specific functions, formats and types... so you can't Copy/Paste HLSL into CG like that. it's need some correction. i think you must have some HLSL tags for unity to compile correctly....
mul() has three different overloads in Cg and HLSL, for matrix-vector, vector-matrix and matrix-matrix multiplications. The order in which you need to multiply vectors and matrices depends on the data in the matrix. I'm not sure if Unity transposes the built-in matrices for HLSL or not. If it does, then you would need to swap your matrix multiplications. If it doesn't, then you can leave the Cg as-is.
The multiplication order only depends on whether your matrices are column major or row major. There's no "one true way" of doing, but it's true that most Cg shader examples choose different order compared to most HLSL examples. So the choice does not depend on a language per se, as more of "what convention is used". The Cg and HLSL languages (for D3D9 level stuff) are identical for all practical purposes. They started diverging a bit with Direct3D10 and later stuff. In Unity's Xbox 360 build, we compile exactly the same regular shaders with Xbox360's HLSL. So yes, the language is the same for practical reasons. The conventions might differ of course.
That answers the question I posed: Unity does not transpose matrix data when compiling HLSL shaders, which means you should use mul(M, v) when transforming a vector with a matrix.