Efficient construction of submatrices?

I’ve run across some code in what I think was nVidia’s GLSL implementation that won’t run on the ATI or 3Dlabs cards we have here (surprise!? :smiley: ). What it is doing is constructing a 3x3 submatrix from a 4x4 matrix using something along the lines of:

uniform mat4 foo

void main() {
  mat3 bar = mat3(foo);
}

I’m not entirely sure this is a legal thing to do. The 1.051 spec only talks about using collections of floats for the matrix constructor or from vec types, but nothing involving matrix types. Am I correct in this read of the spec?

If so, what is an efficient way of constructing a sub matrix out of a larger matrix? Alternatively, efficiently dealing with making the same 4x4 matrix do both point and vector transformations without creating a submatrix. Perhaps creating a new vec4 with the w component set to zero? eg

mat4 foo;
vec4 new_normal = vec4(old_normal.xyz, 0);
new_normal = foo * new_normal;

The .59 spec says
“However, construction of a matrix from other matrices is currently reserved for future use.”

The inconvenient equivalent code according to the spec’s 5.6 Matrix Components paragraph should be

uniform mat4 foo
void main()
{
mat3 bar = mat3(vec3(foo[0]), vec3(foo[1]), vec3(foo[2]));
}

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.