summaryrefslogtreecommitdiff
path: root/src/shaders/common/core.c
blob: ffaa64998d8d42784d5143752a4e046ba935b599 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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);
}