Last active
July 6, 2018 20:30
-
-
Save Pyromuffin/82d16fd9eafb6a8e262299e6e90669ea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Texture2D<float4> originalTex : register(t1); | |
RWTexture2D<float4> outHdrTex : register(u0); | |
float3 ApplyREC2084Curve(float3 L, float maxLuminance) | |
{ | |
float m1 = 2610.0 / 4096.0 / 4; | |
float m2 = 2523.0 / 4096.0 * 128; | |
float c1 = 3424.0 / 4096.0; | |
float c2 = 2413.0 / 4096.0 * 32; | |
float c3 = 2392.0 / 4096.0 * 32; | |
// L = FD / 10000, so if FD == 10000, then L = 1. | |
// so to scale max luminance, we want to multiply by maxLuminance / 10000 | |
float maxLuminanceScale = maxLuminance / 10000.0f; | |
L *= maxLuminanceScale; | |
float3 Lp = pow(L, m1); | |
return pow((c1 + c2 * Lp) / (1 + c3 * Lp), m2); | |
} | |
float3 REC709toREC2020(float3 RGB709) | |
{ | |
static const float3x3 ConvMat = | |
{ | |
0.627402, 0.329292, 0.043306, | |
0.069095, 0.919544, 0.011360, | |
0.016394, 0.088028, 0.895578 | |
}; | |
return mul(ConvMat, RGB709); | |
} | |
float3 RemoveSRGBCurve(float3 x) | |
{ | |
// Approximately pow(x, 2.2) | |
return x < 0.04045 ? x / 12.92 : pow((x + 0.055) / 1.055, 2.4); | |
} | |
[numthreads(8, 8, 1)] | |
void CopyHDR(uint2 dtid : SV_DispatchThreadID) | |
{ | |
float4 originalColor = originalTex[dtid]; | |
float4 col; | |
col = originalColor; | |
col.rgb = RemoveSRGBCurve(col.rgb); | |
col.rgb = REC709toREC2020(col.rgb); | |
col.rgb = ApplyREC2084Curve(col.rgb, 180); | |
outHdrTex[dtid] = col; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment