7
7
#define LUT_SPACE_ENCODE (x) LinearToLogC (x)
8
8
#define LUT_SPACE_DECODE (x) LogCToLinear (x)
9
9
10
- // Set to 1 to use more precise but more expensive log/linear conversions. I haven't found a proper
11
- // use case for the high precision version yet so I'm leaving this to 0.
12
- #define USE_PRECISE_LOGC 0
10
+ #ifndef USE_PRECISE_LOGC
11
+ // Set to 1 to use more precise but more expensive log/linear conversions. I haven't found a proper
12
+ // use case for the high precision version yet so I'm leaving this to 0.
13
+ #define USE_PRECISE_LOGC 0
14
+ #endif
13
15
14
- // Set to 1 to use the full reference ACES tonemapper. This should only be used for research
15
- // purposes as it's quite heavy and generally overkill.
16
- #define TONEMAPPING_USE_FULL_ACES 0
16
+ #ifndef TONEMAPPING_USE_FULL_ACES
17
+ // Set to 1 to use the full reference ACES tonemapper. This should only be used for research
18
+ // purposes as it's quite heavy and generally overkill.
19
+ #define TONEMAPPING_USE_FULL_ACES 0
20
+ #endif
17
21
18
- // PQ ST.2048 max value
19
- // 1.0 = 100nits, 100.0 = 10knits
20
- #define DEFAULT_MAX_PQ 100.0
22
+ #ifndef DEFAULT_MAX_PQ
23
+ // PQ ST.2048 max value
24
+ // 1.0 = 100nits, 100.0 = 10knits
25
+ #define DEFAULT_MAX_PQ 100.0
26
+ #endif
27
+
28
+ #ifndef USE_FAST_SRGB
29
+ #ifdef SHADER_API_MOBILE
30
+ #define USE_FAST_SRGB 1
31
+ #else
32
+ #define USE_FAST_SRGB 0
33
+ #endif
34
+ #endif
21
35
22
36
//
23
37
// Alexa LogC converters (El 1000)
@@ -132,21 +146,30 @@ float3 PQToLinear(float3 x)
132
146
133
147
//
134
148
// sRGB transfer functions
149
+ // Fast path ref: http://chilliant.blogspot.com.au/2012/08/srgb-approximations-for-hlsl.html?m=1
135
150
//
136
151
half SRGBToLinear (half c)
137
152
{
153
+ #if USE_FAST_SRGB
154
+ return c * (c * (c * 0.305306011 + 0.682171111 ) + 0.012522878 );
155
+ #else
138
156
half linearRGBLo = c / 12.92 ;
139
157
half linearRGBHi = PositivePow ((c + 0.055 ) / 1.055 , 2.4 );
140
158
half linearRGB = (c <= 0.04045 ) ? linearRGBLo : linearRGBHi;
141
159
return linearRGB;
160
+ #endif
142
161
}
143
162
144
163
half3 SRGBToLinear (half3 c)
145
164
{
165
+ #if USE_FAST_SRGB
166
+ return c * (c * (c * 0.305306011 + 0.682171111 ) + 0.012522878 );
167
+ #else
146
168
half3 linearRGBLo = c / 12.92 ;
147
169
half3 linearRGBHi = PositivePow ((c + 0.055 ) / 1.055 , half3 (2.4 , 2.4 , 2.4 ));
148
170
half3 linearRGB = (c <= 0.04045 ) ? linearRGBLo : linearRGBHi;
149
171
return linearRGB;
172
+ #endif
150
173
}
151
174
152
175
half4 SRGBToLinear (half4 c)
@@ -156,18 +179,26 @@ half4 SRGBToLinear(half4 c)
156
179
157
180
half LinearToSRGB (half c)
158
181
{
182
+ #if USE_FAST_SRGB
183
+ return max (1.055 * PositivePow (c, 0.416666667 ) - 0.055 , 0.0 );
184
+ #else
159
185
half sRGBLo = c * 12.92 ;
160
186
half sRGBHi = (PositivePow (c, 1.0 / 2.4 ) * 1.055 ) - 0.055 ;
161
187
half sRGB = (c <= 0.0031308 ) ? sRGBLo : sRGBHi;
162
188
return sRGB;
189
+ #endif
163
190
}
164
191
165
192
half3 LinearToSRGB (half3 c)
166
193
{
194
+ #if USE_FAST_SRGB
195
+ return max (1.055 * PositivePow (c, 0.416666667 ) - 0.055 , 0.0 );
196
+ #else
167
197
half3 sRGBLo = c * 12.92 ;
168
198
half3 sRGBHi = (PositivePow (c, half3 (1.0 / 2.4 , 1.0 / 2.4 , 1.0 / 2.4 )) * 1.055 ) - 0.055 ;
169
199
half3 sRGB = (c <= 0.0031308 ) ? sRGBLo : sRGBHi;
170
200
return sRGB;
201
+ #endif
171
202
}
172
203
173
204
half4 LinearToSRGB (half4 c)
0 commit comments