forked from scp-fs2open/fs2open.github.com
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathz-compress.sdr
More file actions
89 lines (83 loc) · 2.3 KB
/
Copy pathz-compress.sdr
File metadata and controls
89 lines (83 loc) · 2.3 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
float compress_depth_value(float linear) {
float linear_mult;
float exponent_mult;
float offset;
linear = max(-linear, 0.0);
if(linear < 10.0) {
//Special handling for very close values. For smooth shadows at very close distances, equidistant steps get too inaccurate.
//Scaling this down linearly will push more accuracy to closer distances. Due to the scaling, this does not lose accuracy
//at any point over the worse of uncompressed / z-compress, but it does trade the gained accuracy from compression at 10m
//distance for accuracy lost due to compression below 0.5m (roughly)
return linear * 0.01;
}
else if (linear < 100.0) {
linear_mult = 0.05550473078;
exponent_mult = 0.08493173544;
offset = 0.0;
}
else if (linear < 1570.0) {
linear_mult = 11.53589613947;
exponent_mult = 0.00793869919;
offset = 0.0;
}
else if (linear < 3000.0) {
linear_mult = -0.10000000000;
exponent_mult = 0.00928910863;
offset = 3000.0;
}
else if (linear < 10000.0) {
linear_mult = -0.10000000000;
exponent_mult = 0.00094912231;
offset = 3000.0;
}
else if (linear < 100000.0) {
linear_mult = -6.98947320727;
exponent_mult = 0.00007382062;
offset = 3000.0;
}
else {
linear_mult = -1000.0;
exponent_mult = log2(1000.0 / 65000.0) / (100000.0 - GLOBAL_FAR_Z);
offset = 100000.0;
}
return linear_mult * pow(2.0, (linear - offset) * exponent_mult);
}
float uncompress_depth_value(float compressed) {
float linear_mult;
float exponent_mult;
float offset;
if(compressed < -1000.0) {
linear_mult = -1000.0;
exponent_mult = log2(1000.0 / 65000.0) / (100000.0 - GLOBAL_FAR_Z);
offset = 100000.0;
}
else if (compressed < -10.0) {
linear_mult = -6.98947320727;
exponent_mult = 0.00007382062;
offset = 3000.0;
}
else if (compressed < -0.1) {
linear_mult = -0.10000000000;
exponent_mult = 0.00094912231;
offset = 3000.0;
}
else if (compressed < 0.0) {
linear_mult = -0.10000000000;
exponent_mult = 0.00928910863;
offset = 3000.0;
}
else if (compressed < 0.1) {
return compressed * -100.0;
}
else if (compressed < 20.0) {
linear_mult = 0.05550473078;
exponent_mult = 0.08493173544;
offset = 0.0;
}
else {
linear_mult = 11.53589613947;
exponent_mult = 0.00793869919;
offset = 0.0;
}
return -(log2(compressed / linear_mult) / exponent_mult + offset);
}