-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimd_routines.ispc
140 lines (124 loc) · 4.23 KB
/
simd_routines.ispc
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// Copyright Silicon Studio K.K. 2023
// author: Vivien Oddou
// BSD License
// John Hable/Jim Hejl filmic tone map
static const float U2_A = 0.22; // "Shoulder strength"
static const float U2_B = 0.3; // "Linear strength"
static const float U2_C = 0.1; // "Linear angle"
static const float U2_D = 0.2; // "Toe strength"
static const float U2_E = 0.01; // "Toe numerator"
static const float U2_F = 0.22; // "Toe denominator"
static const float U2_W = 11.2; // "Linear White Point Value"
inline float Uncharted2Tonemap(float x)
{
static const float ExposureBias = 2;
x *= ExposureBias;
return ((x * (U2_A * x + U2_C * U2_B) + U2_D * U2_E) / (x * (U2_A * x + U2_B) + U2_D * U2_F)) - U2_E / U2_F;
}
inline float LinearToGamma(float linearClr)
{
return pow(linearClr, 1/2.2);
}
static const float whiteScale = 1.0f / (((2 * U2_W * (U2_A * 2 * U2_W + U2_C * U2_B) + U2_D * U2_E) / (2 * U2_W * (U2_A * 2 * U2_W + U2_B) + U2_D * U2_F)) - U2_E / U2_F);
inline float ToneComponent(float comp)
{
float postTone = Uncharted2Tonemap(comp);
return postTone * whiteScale;
}
inline float ToneComponentAndToGamma(float comp)
{
comp = ToneComponent(comp);
return LinearToGamma(comp);
}
export void ToSignedRgbAllF32Pixels(uniform float vin[], uniform int8 vout[], uniform int count, uniform float exposure)
{
foreach (index = 0 ... count)
{
float v = vin[index] * exposure;
vout[index] = min(255.f, 255 * v) - 128;
}
}
export void ToSignedRgbAllF16Pixels(uniform uint16 vin[], uniform int8 vout[], uniform int count, uniform float exposure)
{
foreach (index = 0 ... count)
{
float v = half_to_float(vin[index]) * exposure;
vout[index] = min(255.f, 255 * v) - 128;
}
}
export void GammaAllF32Pixels(uniform float vin[], uniform int8 vout[], uniform int count, uniform float exposure)
{
foreach (index = 0 ... count)
{
float v = vin[index] * exposure;
vout[index] = min(255.f, 255 * LinearToGamma(v)) - 128;
}
}
export void GammaAllF16Pixels(uniform uint16 vin[], uniform int8 vout[], uniform int count, uniform float exposure)
{
foreach (index = 0 ... count)
{
float v = half_to_float(vin[index]) * exposure;
vout[index] = min(255.f, 255 * LinearToGamma(v)) - 128;
}
}
// expose and downtone to SDR
export void ToneAllF32Pixels(uniform float vin[], uniform int8 vout[], uniform int count, uniform float exposure)
{
foreach (index = 0 ... count)
{
float v = vin[index] * exposure;
vout[index] = min(255.f, 255 * ToneComponent(v)) - 128;
}
}
export void ToneAllF16Pixels(uniform uint16 vin[], uniform int8 vout[], uniform int count, uniform float exposure)
{
foreach (index = 0 ... count)
{
float v = half_to_float(vin[index]) * exposure;
vout[index] = min(255.f, 255 * ToneComponent(v)) - 128;
}
}
// expose, downtone, and gamma-ify
export void ToneAllF32PixelsAndToGamma(uniform float vin[], uniform int8 vout[], uniform int count, uniform float exposure)
{
foreach (index = 0 ... count)
{
float v = vin[index] * exposure;
vout[index] = min(255.f, 255 * ToneComponentAndToGamma(v)) - 128;
}
}
export void ToneAllF16PixelsAndToGamma(uniform uint16 vin[], uniform int8 vout[], uniform int count, uniform float exposure)
{
foreach (index = 0 ... count)
{
float v = half_to_float(vin[index]) * exposure;
vout[index] = min(255.f, 255 * ToneComponentAndToGamma(v)) - 128;
}
}
export void GetMinMaxF32(uniform float vin[], uniform int count, uniform float& minOut, uniform float& maxOut)
{
varying float varMin = 1e34f;
varying float varMax = -1e34f;
foreach (index = 0 ... count)
{
float v = vin[index];
if (v < varMin) varMin = v;
if (v > varMax) varMax = v;
}
minOut = reduce_min(varMin);
maxOut = reduce_max(varMax);
}
export void GetMinMaxF16(uniform uint16 vin[], uniform int count, uniform float& minOut, uniform float& maxOut)
{
varying float varMin = 1e34f;
varying float varMax = -1e34f;
foreach (index = 0 ... count)
{
float v = half_to_float(vin[index]);
if (v < varMin) varMin = v;
if (v > varMax) varMax = v;
}
minOut = reduce_min(varMin);
maxOut = reduce_max(varMax);
}