From a0439c8d387579a1727ad00c2e105e7602aedbb6 Mon Sep 17 00:00:00 2001 From: chai Date: Sun, 12 Jul 2020 13:31:28 +0800 Subject: +mathlib --- src/shaders/common/core.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/shaders/common/core.c (limited to 'src/shaders/common/core.c') diff --git a/src/shaders/common/core.c b/src/shaders/common/core.c new file mode 100644 index 0000000..703458c --- /dev/null +++ b/src/shaders/common/core.c @@ -0,0 +1,30 @@ +#include "core.h" + +Vec4 _proj_params; +Vec2 _time; +Vec4 _screen_params; + +Vec3 unpacknormal(Color32 c32) { + Vec3 normal = { + c32.r * 2 - 1, + c32.g * 2 - 1, + c32.b * 2 - 1, + }; + return normal; +} + +Mat4 mat4(Vec4* c1, Vec4* c2, Vec4* c3, Vec4* c4); + +Vec2 texsize(Texture* texture) { + Vec2 size = {texture->width, texture->height}; + return size; +} + +float linear01depth(float depth) { + float n = _proj_params.x, f = _proj_params.y; + return n / ((n-f)*depth + f); +} + +float lineareyedepth(float depth) { + return _proj_params.y * linear01depth(depth); +} \ No newline at end of file -- cgit v1.1-26-g67d0