@ -42,4 +42,40 @@ out vec4 outFragColor;
# define isnan(val) !(val<0.0||val>0.0||val==0.0)
# define isnan(val) !(val<0.0||val>0.0||val==0.0)
#endif
#endif
#if __VERSION__ == 110
mat3 mat3(mat4 m) {
return mat3(m[0].xyz, m[1].xyz, m[2].xyz);
}
#endif
#if __VERSION__ <= 140
float determinant(mat2 m) {
return m[0][0] * m[1][1] - m[1][0] * m[0][1];
}
float determinant(mat3 m) {
return + 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]);
}
#endif
#if __VERSION__ <= 130
mat2 inverse(mat2 m) {
return mat2(m[1][1], -m[0][1], -m[1][0], m[0][0]) / determinant(m);
}
mat3 inverse(mat3 m) {
return mat3(
+ (m[1][1] * m[2][2] - m[2][1] * m[1][2]),
- (m[1][0] * m[2][2] - m[2][0] * m[1][2]),
+ (m[1][0] * m[2][1] - m[2][0] * m[1][1]),
- (m[0][1] * m[2][2] - m[2][1] * m[0][2]),
+ (m[0][0] * m[2][2] - m[2][0] * m[0][2]),
- (m[0][0] * m[2][1] - m[2][0] * m[0][1]),
+ (m[0][1] * m[1][2] - m[1][1] * m[0][2]),
- (m[0][0] * m[1][2] - m[1][0] * m[0][2]),
+ (m[0][0] * m[1][1] - m[1][0] * m[0][1])) / determinant(m);
}
#endif