summaryrefslogtreecommitdiff
path: root/src/shaders/common/mathlib.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/shaders/common/mathlib.h')
-rw-r--r--src/shaders/common/mathlib.h63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/shaders/common/mathlib.h b/src/shaders/common/mathlib.h
new file mode 100644
index 0000000..fcc54ea
--- /dev/null
+++ b/src/shaders/common/mathlib.h
@@ -0,0 +1,63 @@
+#ifndef SSR_SHADER_MATH_H
+#define SSR_SHADER_MATH_H
+
+#include "../../math/structs.h"
+
+/************************************************************************/
+/* constants */
+/************************************************************************/
+
+#define SSR_PI 3.14159265359f
+#define SSR_TWO_PI 6.28318530718f
+#define SSR_FOUR_PI 12.56637061436f
+#define SSR_INV_PI 0.31830988618f
+#define SSR_INV_TWO_PI 0.15915494309f
+#define SSR_INV_FOUR_PI 0.07957747155f
+#define SSR_HALF_PI 1.57079632679f
+#define SSR_INV_HALF_PI 0.636619772367f
+
+/************************************************************************/
+/* Vec3 */
+/************************************************************************/
+Vec2 vec2(float x, float y);
+Vec2 vec2_minus(Vec2 v1, Vec2 v2);
+Vec2 vec2_plus(Vec2 v1, Vec2 v2);
+float vec2_dot(Vec2 v1, Vec2 v2);
+
+/************************************************************************/
+/* Vec3 */
+/************************************************************************/
+Vec3 vec3(float x, float y, float z);
+Vec3 vec3_minus(Vec3 v1, Vec3 v2);
+Vec3 vec3_plus(Vec3 v1, Vec3 v2);
+float vec3_dot(Vec3 v1, Vec3 v2);
+Vec3 vec3_cross(Vec3 v1, Vec3 v2);
+Vec3 vec3_lerp(Vec3 v1, Vec3 v2, float t);
+Vec3 vec3_slerp(Vec3 v1, Vec3 v2, float t);
+Vec3 vec3_scale(Vec3 v, float scale);
+Vec3 vec3_normalize(Vec3 v);
+
+/************************************************************************/
+/* Vec4 */
+/************************************************************************/
+Vec4 vec4(float x, float y, float z, float w);
+Vec4 vec4_minus(Vec4 v1, Vec4 v2);
+Vec4 vec4_plus(Vec4 v1, Vec4 v2);
+Vec4 vec4_scale(Vec4 v, float scale);
+Vec4 vec4_saturate(Vec4 v);
+Vec4 vec4_normalize(Vec4 v);
+
+/************************************************************************/
+/* Matrix */
+/************************************************************************/
+Mat3 mat3(Vec3 colum1, Vec3 colum2, Vec3 colum3); // colum major
+Vec3 mat3_mulvec3(Mat3 m, Vec3 v);
+Mat3 mat3_mulmat3(Mat3 m, Mat3 m2);
+
+Mat4 mat4(Vec4 colum1, Vec4 colum2, Vec4 colum3, Vec4 colum4);
+Vec3 mat4_mulvec3(Mat4 m, Vec3 v);
+Vec4 mat4_mulvec4(Mat4 m, Vec4 v);
+Mat4 mat4_mulmat4(Mat4 m, Mat4 m2);
+
+
+#endif \ No newline at end of file