float3 linear_srgb(float3 x) { return lerp(1.055 * pow(x, 1. / 2.4) - 0.055, 12.92 * x, step(x, 0.0031308)); } static const float3x3 AP1_2_XYZ_MAT = { 0.6624541811, 0.1340042065, 0.1561876870, 0.2722287168, 0.6740817658, 0.0536895174, -0.0055746495, 0.0040607335, 1.0103391003 }; static const float3x3 XYZ_2_AP1_MAT = { 1.6410233797, -0.3248032942, -0.2364246952, -0.6636628587, 1.6153315917, 0.0167563477, 0.0117218943, -0.0082844420, 0.9883948585 }; static const float3x3 D60_2_D65_CAT = { 0.98722400, -0.00611327, 0.0159533, -0.00759836, 1.00186000, 0.0053302, 0.00307257, -0.00509595, 1.0816800 }; static const float3x3 XYZ_2_REC2020_MAT = { 1.7166511880, -0.3556707838, -0.2533662814, -0.6666843518, 1.6164812366, 0.0157685458, 0.0176398574, -0.0427706133, 0.9421031212 }; static const float SATURATION = 1.2; static const float EXPOSURE = 1.2; // ACES curve fit by Stephen Hill float3 ToneMap(float3 color) { //return color; //return linear_srgb(color); float3 v = max(0, mul(float3x3(0.59719, 0.35458, 0.04823, 0.07600, 0.90834, 0.01566, 0.02840, 0.13383, 0.83777), color * EXPOSURE)); float3 a = v * (v + 0.0245786f) - 0.000090537f; float3 b = v * (0.983729f * v + 0.4329510f) + 0.238081f; color = a / b; color = lerp(dot(color, float3(0.272229, 0.674082, 0.0536895)), color, SATURATION); color = mul(AP1_2_XYZ_MAT, color); color = mul(D60_2_D65_CAT, color); color = mul(XYZ_2_REC2020_MAT, color); //return (color); return linear_srgb(max(0, color)); }