2 * Copyright © 2012 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
26 // Forward declaration because builtins don't know about other builtins.
27 float dot(vec4, vec4);
29 float determinant(mat2 m)
31 return m[0][0] * m[1][1] - m[1][0] * m[0][1];
34 float determinant(mat3 m)
36 return (+ m[0][0] * (m[1][1] * m[2][2] - m[1][2] * m[2][1])
37 - m[0][1] * (m[1][0] * m[2][2] - m[1][2] * m[2][0])
38 + m[0][2] * (m[1][0] * m[2][1] - m[1][1] * m[2][0]));
41 float determinant(mat4 m)
43 float SubFactor00 = m[2][2] * m[3][3] - m[3][2] * m[2][3];
44 float SubFactor01 = m[2][1] * m[3][3] - m[3][1] * m[2][3];
45 float SubFactor02 = m[2][1] * m[3][2] - m[3][1] * m[2][2];
46 float SubFactor03 = m[2][0] * m[3][3] - m[3][0] * m[2][3];
47 float SubFactor04 = m[2][0] * m[3][2] - m[3][0] * m[2][2];
48 float SubFactor05 = m[2][0] * m[3][1] - m[3][0] * m[2][1];
49 float SubFactor06 = m[1][2] * m[3][3] - m[3][2] * m[1][3];
50 float SubFactor07 = m[1][1] * m[3][3] - m[3][1] * m[1][3];
51 float SubFactor08 = m[1][1] * m[3][2] - m[3][1] * m[1][2];
52 float SubFactor09 = m[1][0] * m[3][3] - m[3][0] * m[1][3];
53 float SubFactor10 = m[1][0] * m[3][2] - m[3][0] * m[1][2];
54 float SubFactor11 = m[1][1] * m[3][3] - m[3][1] * m[1][3];
55 float SubFactor12 = m[1][0] * m[3][1] - m[3][0] * m[1][1];
56 float SubFactor13 = m[1][2] * m[2][3] - m[2][2] * m[1][3];
57 float SubFactor14 = m[1][1] * m[2][3] - m[2][1] * m[1][3];
58 float SubFactor15 = m[1][1] * m[2][2] - m[2][1] * m[1][2];
59 float SubFactor16 = m[1][0] * m[2][3] - m[2][0] * m[1][3];
60 float SubFactor17 = m[1][0] * m[2][2] - m[2][0] * m[1][2];
61 float SubFactor18 = m[1][0] * m[2][1] - m[2][0] * m[1][1];
65 adj_0[0] = + (m[1][1] * SubFactor00 - m[1][2] * SubFactor01 + m[1][3] * SubFactor02);
66 adj_0[1] = - (m[1][0] * SubFactor00 - m[1][2] * SubFactor03 + m[1][3] * SubFactor04);
67 adj_0[2] = + (m[1][0] * SubFactor01 - m[1][1] * SubFactor03 + m[1][3] * SubFactor05);
68 adj_0[3] = - (m[1][0] * SubFactor02 - m[1][1] * SubFactor04 + m[1][2] * SubFactor05);
70 return dot(m[0], adj_0);