-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPD-Tonemap.h
66 lines (56 loc) · 1.67 KB
/
PD-Tonemap.h
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
// Copyright 2022-present Contributors to the photographic-dctl project.
// SPDX-License-Identifier: BSD-3-Clause
// https://github.com/mikaelsundell/photographic-dctls
// clang-format on
// tonemap curve
struct TonemapCurve
{
float low;
float lowsoft;
float high;
float highsoft;
float shoulder;
float toe;
};
__DEVICE__ struct TonemapCurve tonemap_curve() {
struct TonemapCurve tm;
tm.low = 0.300;
tm.lowsoft = 0.200;
tm.high = 0.350;
tm.highsoft = 0.200;
tm.shoulder = 0.5;
tm.toe = 0.4;
return tm;
}
__DEVICE__ float tonemap_pow(float x, float c, float p) {
return pow(x, c) / pow(p, c - 1.0);
}
__DEVICE__ float tonemap_scurve(float x, float p, float c) {
if (x < p) {
return tonemap_pow(x, c, p);
}
else {
return 1.0 - tonemap_pow(1.0 - x, c, 1.0 - p);
}
}
// ootf forward
__DEVICE__ float3 tonemap_ootf_dcip3_rec709(float3 log) {
log = lin_rec709gamma24(dcip3gamma26_lin(log));
return pow_f3(log, 2.2 / 2.6); // purely experiemental dcip3 to rec709
}
__DEVICE__ float3 tonemap_ootf_sRGB_rec709(float3 log) {
log = lin_rec709gamma24(sRGBgamma22_lin(log));
return pow_f3(log, 2.2 / 2.4); // purely experiemental sRGB to rec709
}
// ootf inverse
__DEVICE__ float3 tonemap_ootf_rec709_dcip3(float3 log) {
log = lin_dcip3gamma26(rec709gamma24_lin(log));
return pow_f3(log, 2.6 / 2.2); // purely experiemental rec709 to dcip3
}
// tonecompress reinhard
__DEVICE__ float3 tonecompress_reinhard(float3 lin, float exp) {
return lin / (1.0 + lin * exp);
}
__DEVICE__ float3 tonecompress_inverse_reinhard(float3 compressed, float exp) {
return compressed / (1.0 - compressed * exp);
}