We describe, here, the already converted productions between HLSL and GLSL.

Direct Token Mapping

#elseif #elif float2x2 mat2x2
float2 vec2 float2x3 mat2x3
float3 vec3 float2x4 mat2x4
float4 vec4 float3x2 mat3x2
bool2 bvec2 float3x3 mat3x3
bool3 bvec3 float3x4 mat3x4
bool4 bvec4 float4x2 mat4x2
int2 ivec2 float4x3 mat4x3
int3 ivec3 float4x4 mat4x4
int4 ivec4 tex2D texture2D
half2 ivec2
half3 ivec3
half4 ivec4

Others Mappings

  • #include: The pre-processing tag #include imports another file into the line where the tag is declared. Since GLSL does not have this feature, we need to import and parse that file.
  • GLSL * operator between matrices, is the standard linear algebra matrix multiplication, while in HLSL is a component wise multiplication.
  • Looks like HLSL cross params are backwards to what you had expect cross(T,N) equates to NxT, not TxN.
  • GLSL doesn't support varying and uniform variables declared inside the parameters of a main function. They must be outside, like global vars.
  • GLSL doesn't support two or more main functions in a file.
  • Every GLSL file must have a main function with no arguments.
  • GLSL does not support an 'f' after a float number (e.g. 1.0f).

Column Major or Row Major?

HLSL and GLSL matrices are both column major, but elements are accessed in this way:


float4x4 = // [row][column]
 [0][0], [0][1], [0][2], [0][3]
 [1][0], [1][1], [1][2], [1][3]
 [2][0], [2][1], [2][2], [2][3]
 [3][0], [3][1], [3][2], [3][3]

float2x2 (
    0, 0, // row 1
    2, 2  // row 2) 

int1x1    iMatrix;   // integer matrix with 1 row,  1 column
int4x1    iMatrix;   // integer matrix with 4 rows, 1 column
int1x4    iMatrix;   // integer matrix with 1 row, 4 columns
double3x3 dMatrix;   // double matrix with 3 rows, 3 columns

matrix[0] returns the first row.


float4x4 = // [column][row]
 [0][0], [0][1], [0][2], [0][3]
 [1][0], [1][1], [1][2], [1][3]
 [2][0], [2][1], [2][2], [2][3]
 [3][0], [3][1], [3][2], [3][3]

 mat2(float, float,  // first column
     float, float); // second column  

GLSL matrix[0] is the first column.

Semantic Params

There are no Semantic Params in GLSL. The variables that have semantical behavior must be replaced by declared variables. For example:

float4 oColor : Color

must be changed to


Intrinsic Functions that are not supported by GLSL

asuint round
clip saturate
cosh sincos
determinant tanh
frexp tex1Dbias
GetRenderTargetSampleCount tex1Dgrad
GetRenderTargetSamplePosition tex2Dbias
isfinite tex2Dgrad
isinf tex3Dbias
isnan tex3Dgrad
ldexp texCUBEbias
lerp texCUBEgrad
lit transpose
log10 trunc

HLSL Attributes Reference (Xbox 360)

This attributes are for shaders developed for Xbox360, thus, GLSL does not support them.

branch maxtempreg
call noExpressionOptimizations
flatten predicateBlock
ifAll reduceTempRegUsage
ifAny removeUnusedInputs
isolate sampreg
loop unroll
maxexports unused

Last edited Jul 9, 2008 at 12:32 PM by bellaver, version 61


No comments yet.