summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/bgfx/examples/common/shaderlib.sh
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/bgfx/examples/common/shaderlib.sh')
-rw-r--r--3rdparty/bgfx/examples/common/shaderlib.sh20
1 files changed, 19 insertions, 1 deletions
diff --git a/3rdparty/bgfx/examples/common/shaderlib.sh b/3rdparty/bgfx/examples/common/shaderlib.sh
index 2bcd43d7df2..f0aee192493 100644
--- a/3rdparty/bgfx/examples/common/shaderlib.sh
+++ b/3rdparty/bgfx/examples/common/shaderlib.sh
@@ -1,5 +1,5 @@
/*
- * Copyright 2011-2018 Branimir Karadzic. All rights reserved.
+ * Copyright 2011-2019 Branimir Karadzic. All rights reserved.
* License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
*/
@@ -392,4 +392,22 @@ vec2 texture2DBc5(sampler2D _sampler, vec2 _uv)
#endif
}
+mat3 cofactor( mat4 _m )
+{
+ // Reference:
+ // Cofactor of matrix. Use to transform normals. The code assumes the last column of _m is [0,0,0,1].
+ // https://www.shadertoy.com/view/3s33zj
+ // https://github.com/graphitemaster/normals_revisited
+ return mat3(
+ _m[1][1]*_m[2][2]-_m[1][2]*_m[2][1],
+ _m[1][2]*_m[2][0]-_m[1][0]*_m[2][2],
+ _m[1][0]*_m[2][1]-_m[1][1]*_m[2][0],
+ _m[0][2]*_m[2][1]-_m[0][1]*_m[2][2],
+ _m[0][0]*_m[2][2]-_m[0][2]*_m[2][0],
+ _m[0][1]*_m[2][0]-_m[0][0]*_m[2][1],
+ _m[0][1]*_m[1][2]-_m[0][2]*_m[1][1],
+ _m[0][2]*_m[1][0]-_m[0][0]*_m[1][2],
+ _m[0][0]*_m[1][1]-_m[0][1]*_m[1][0] );
+}
+
#endif // __SHADERLIB_SH__