diff options
Diffstat (limited to 'src/glsl/builtins/glsl/inverse.glsl')
-rw-r--r-- | src/glsl/builtins/glsl/inverse.glsl | 112 |
1 files changed, 56 insertions, 56 deletions
diff --git a/src/glsl/builtins/glsl/inverse.glsl b/src/glsl/builtins/glsl/inverse.glsl index 3578d988833..ffb84f90794 100644 --- a/src/glsl/builtins/glsl/inverse.glsl +++ b/src/glsl/builtins/glsl/inverse.glsl @@ -24,82 +24,82 @@ mat2 inverse(mat2 m) { mat2 adj; - adj[0].x = m[1].y; - adj[0].y = -m[0].y; - adj[1].x = -m[1].x; - adj[1].y = m[0].x; - float det = m[0].x * m[1].y - m[1].x * m[0].y; + adj[0][0] = m[1][1]; + adj[0][1] = -m[0][1]; + adj[1][0] = -m[1][0]; + adj[1][1] = m[0][0]; + float det = m[0][0] * m[1][1] - m[1][0] * m[0][1]; return adj / det; } mat3 inverse(mat3 m) { mat3 adj; - adj[0].x = + (m[1].y * m[2].z - m[2].y * m[1].z); - adj[1].x = - (m[1].x * m[2].z - m[2].x * m[1].z); - adj[2].x = + (m[1].x * m[2].y - m[2].x * m[1].y); - adj[0].y = - (m[0].y * m[2].z - m[2].y * m[0].z); - adj[1].y = + (m[0].x * m[2].z - m[2].x * m[0].z); - adj[2].y = - (m[0].x * m[2].y - m[2].x * m[0].y); - adj[0].z = + (m[0].y * m[1].z - m[1].y * m[0].z); - adj[1].z = - (m[0].x * m[1].z - m[1].x * m[0].z); - adj[2].z = + (m[0].x * m[1].y - m[1].x * m[0].y); + adj[0][0] = + (m[1][1] * m[2][2] - m[2][1] * m[1][2]); + adj[1][0] = - (m[1][0] * m[2][2] - m[2][0] * m[1][2]); + adj[2][0] = + (m[1][0] * m[2][1] - m[2][0] * m[1][1]); + adj[0][1] = - (m[0][1] * m[2][2] - m[2][1] * m[0][2]); + adj[1][1] = + (m[0][0] * m[2][2] - m[2][0] * m[0][2]); + adj[2][1] = - (m[0][0] * m[2][1] - m[2][0] * m[0][1]); + adj[0][2] = + (m[0][1] * m[1][2] - m[1][1] * m[0][2]); + adj[1][2] = - (m[0][0] * m[1][2] - m[1][0] * m[0][2]); + adj[2][2] = + (m[0][0] * m[1][1] - m[1][0] * m[0][1]); - float det = (+ m[0].x * (m[1].y * m[2].z - m[1].z * m[2].y) - - m[0].y * (m[1].x * m[2].z - m[1].z * m[2].x) - + m[0].z * (m[1].x * m[2].y - m[1].y * m[2].x)); + float det = (+ m[0][0] * (m[1][1] * m[2][2] - m[1][2] * m[2][1]) + - m[0][1] * (m[1][0] * m[2][2] - m[1][2] * m[2][0]) + + m[0][2] * (m[1][0] * m[2][1] - m[1][1] * m[2][0])); return adj / det; } mat4 inverse(mat4 m) { - float SubFactor00 = m[2].z * m[3].w - m[3].z * m[2].w; - float SubFactor01 = m[2].y * m[3].w - m[3].y * m[2].w; - float SubFactor02 = m[2].y * m[3].z - m[3].y * m[2].z; - float SubFactor03 = m[2].x * m[3].w - m[3].x * m[2].w; - float SubFactor04 = m[2].x * m[3].z - m[3].x * m[2].z; - float SubFactor05 = m[2].x * m[3].y - m[3].x * m[2].y; - float SubFactor06 = m[1].z * m[3].w - m[3].z * m[1].w; - float SubFactor07 = m[1].y * m[3].w - m[3].y * m[1].w; - float SubFactor08 = m[1].y * m[3].z - m[3].y * m[1].z; - float SubFactor09 = m[1].x * m[3].w - m[3].x * m[1].w; - float SubFactor10 = m[1].x * m[3].z - m[3].x * m[1].z; - float SubFactor11 = m[1].y * m[3].w - m[3].y * m[1].w; - float SubFactor12 = m[1].x * m[3].y - m[3].x * m[1].y; - float SubFactor13 = m[1].z * m[2].w - m[2].z * m[1].w; - float SubFactor14 = m[1].y * m[2].w - m[2].y * m[1].w; - float SubFactor15 = m[1].y * m[2].z - m[2].y * m[1].z; - float SubFactor16 = m[1].x * m[2].w - m[2].x * m[1].w; - float SubFactor17 = m[1].x * m[2].z - m[2].x * m[1].z; - float SubFactor18 = m[1].x * m[2].y - m[2].x * m[1].y; + float SubFactor00 = m[2][2] * m[3][3] - m[3][2] * m[2][3]; + float SubFactor01 = m[2][1] * m[3][3] - m[3][1] * m[2][3]; + float SubFactor02 = m[2][1] * m[3][2] - m[3][1] * m[2][2]; + float SubFactor03 = m[2][0] * m[3][3] - m[3][0] * m[2][3]; + float SubFactor04 = m[2][0] * m[3][2] - m[3][0] * m[2][2]; + float SubFactor05 = m[2][0] * m[3][1] - m[3][0] * m[2][1]; + float SubFactor06 = m[1][2] * m[3][3] - m[3][2] * m[1][3]; + float SubFactor07 = m[1][1] * m[3][3] - m[3][1] * m[1][3]; + float SubFactor08 = m[1][1] * m[3][2] - m[3][1] * m[1][2]; + float SubFactor09 = m[1][0] * m[3][3] - m[3][0] * m[1][3]; + float SubFactor10 = m[1][0] * m[3][2] - m[3][0] * m[1][2]; + float SubFactor11 = m[1][1] * m[3][3] - m[3][1] * m[1][3]; + float SubFactor12 = m[1][0] * m[3][1] - m[3][0] * m[1][1]; + float SubFactor13 = m[1][2] * m[2][3] - m[2][2] * m[1][3]; + float SubFactor14 = m[1][1] * m[2][3] - m[2][1] * m[1][3]; + float SubFactor15 = m[1][1] * m[2][2] - m[2][1] * m[1][2]; + float SubFactor16 = m[1][0] * m[2][3] - m[2][0] * m[1][3]; + float SubFactor17 = m[1][0] * m[2][2] - m[2][0] * m[1][2]; + float SubFactor18 = m[1][0] * m[2][1] - m[2][0] * m[1][1]; mat4 adj; - adj[0].x = + (m[1].y * SubFactor00 - m[1].z * SubFactor01 + m[1].w * SubFactor02); - adj[1].x = - (m[1].x * SubFactor00 - m[1].z * SubFactor03 + m[1].w * SubFactor04); - adj[2].x = + (m[1].x * SubFactor01 - m[1].y * SubFactor03 + m[1].w * SubFactor05); - adj[3].x = - (m[1].x * SubFactor02 - m[1].y * SubFactor04 + m[1].z * SubFactor05); + adj[0][0] = + (m[1][1] * SubFactor00 - m[1][2] * SubFactor01 + m[1][3] * SubFactor02); + adj[1][0] = - (m[1][0] * SubFactor00 - m[1][2] * SubFactor03 + m[1][3] * SubFactor04); + adj[2][0] = + (m[1][0] * SubFactor01 - m[1][1] * SubFactor03 + m[1][3] * SubFactor05); + adj[3][0] = - (m[1][0] * SubFactor02 - m[1][1] * SubFactor04 + m[1][2] * SubFactor05); - adj[0].y = - (m[0].y * SubFactor00 - m[0].z * SubFactor01 + m[0].w * SubFactor02); - adj[1].y = + (m[0].x * SubFactor00 - m[0].z * SubFactor03 + m[0].w * SubFactor04); - adj[2].y = - (m[0].x * SubFactor01 - m[0].y * SubFactor03 + m[0].w * SubFactor05); - adj[3].y = + (m[0].x * SubFactor02 - m[0].y * SubFactor04 + m[0].z * SubFactor05); + adj[0][1] = - (m[0][1] * SubFactor00 - m[0][2] * SubFactor01 + m[0][3] * SubFactor02); + adj[1][1] = + (m[0][0] * SubFactor00 - m[0][2] * SubFactor03 + m[0][3] * SubFactor04); + adj[2][1] = - (m[0][0] * SubFactor01 - m[0][1] * SubFactor03 + m[0][3] * SubFactor05); + adj[3][1] = + (m[0][0] * SubFactor02 - m[0][1] * SubFactor04 + m[0][2] * SubFactor05); - adj[0].z = + (m[0].y * SubFactor06 - m[0].z * SubFactor07 + m[0].w * SubFactor08); - adj[1].z = - (m[0].x * SubFactor06 - m[0].z * SubFactor09 + m[0].w * SubFactor10); - adj[2].z = + (m[0].x * SubFactor11 - m[0].y * SubFactor09 + m[0].w * SubFactor12); - adj[3].z = - (m[0].x * SubFactor08 - m[0].y * SubFactor10 + m[0].z * SubFactor12); + adj[0][2] = + (m[0][1] * SubFactor06 - m[0][2] * SubFactor07 + m[0][3] * SubFactor08); + adj[1][2] = - (m[0][0] * SubFactor06 - m[0][2] * SubFactor09 + m[0][3] * SubFactor10); + adj[2][2] = + (m[0][0] * SubFactor11 - m[0][1] * SubFactor09 + m[0][3] * SubFactor12); + adj[3][2] = - (m[0][0] * SubFactor08 - m[0][1] * SubFactor10 + m[0][2] * SubFactor12); - adj[0].w = - (m[0].y * SubFactor13 - m[0].z * SubFactor14 + m[0].w * SubFactor15); - adj[1].w = + (m[0].x * SubFactor13 - m[0].z * SubFactor16 + m[0].w * SubFactor17); - adj[2].w = - (m[0].x * SubFactor14 - m[0].y * SubFactor16 + m[0].w * SubFactor18); - adj[3].w = + (m[0].x * SubFactor15 - m[0].y * SubFactor17 + m[0].z * SubFactor18); + adj[0][3] = - (m[0][1] * SubFactor13 - m[0][2] * SubFactor14 + m[0][3] * SubFactor15); + adj[1][3] = + (m[0][0] * SubFactor13 - m[0][2] * SubFactor16 + m[0][3] * SubFactor17); + adj[2][3] = - (m[0][0] * SubFactor14 - m[0][1] * SubFactor16 + m[0][3] * SubFactor18); + adj[3][3] = + (m[0][0] * SubFactor15 - m[0][1] * SubFactor17 + m[0][2] * SubFactor18); - float det = (+ m[0].x * adj[0].x - + m[0].y * adj[1].x - + m[0].z * adj[2].x - + m[0].w * adj[3].x); + float det = (+ m[0][0] * adj[0][0] + + m[0][1] * adj[1][0] + + m[0][2] * adj[2][0] + + m[0][3] * adj[3][0]); return adj / det; } |