-
Notifications
You must be signed in to change notification settings - Fork 18
/
metric.glsl
37 lines (36 loc) · 902 Bytes
/
metric.glsl
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
31
32
33
34
35
36
37
float distanceMetric(vec2 pos, uint metric)
{
switch (metric)
{
case 0u:
// squared euclidean
return dot(pos, pos);
case 1u:
// manhattam
return dot(abs(pos), vec2(1.0));
case 2u:
// chebyshev
return max(abs(pos.x), abs(pos.y));
default:
// triangular
return max(abs(pos.x) * 0.866025 + pos.y * 0.5, -pos.y);
}
}
vec4 distanceMetric(vec4 px, vec4 py, uint metric)
{
switch (metric)
{
case 0u:
// squared euclidean
return px * px + py * py;
case 1u:
// manhattam
return abs(px) + abs(py);
case 2u:
// chebyshev
return max(abs(px), abs(py));
default:
// triangular
return max(abs(px) * 0.866025 + py * 0.5, -py);
}
}