Created
October 20, 2020 16:13
-
-
Save nikq/e80f188dcc6402153d9b2e3099468d11 to your computer and use it in GitHub Desktop.
HLG checkup shader for MPC-BE
This file contains hidden or 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
// $MinimumShaderProfile: ps_2_0 | |
sampler s0 : register(s0); | |
// float ST2084_to_Y(float pixel) // pixel should be 0-1 | |
// { | |
// const float pq_m1 = 0.1593017578125f; // ( 2610.0 / 4096.0 ) / 4.0; | |
// const float pq_m2 = 78.84375f; // ( 2523.0 / 4096.0 ) * 128.0; | |
// const float pq_c1 = 0.8359375f; // 3424.0 / 4096.0 or pq_c3 - pq_c2 + 1.0; | |
// const float pq_c2 = 18.8515625f; // ( 2413.0 / 4096.0 ) * 32.0; | |
// const float pq_c3 = 18.6875f; // ( 2392.0 / 4096.0 ) * 32.0; | |
// const float pq_C = 100.0f; | |
// // Note that this does NOT handle any of the signal range | |
// // considerations from 2084 - this assumes full range (0 - 1) | |
// float Np = pow(pixel, 1.0f / pq_m2); | |
// float L = Np - pq_c1; | |
// if (L < 0.0) | |
// L = 0.0; | |
// L = L / (pq_c2 - pq_c3 * Np); | |
// L = pow(L, 1.0f / pq_m1); | |
// return L * pq_C; // returns 0-100, 1=100cd/m^2 | |
// } | |
// float3 ST2084_to_Y(float3 rgb) { | |
// return float3(ST2084_to_Y(rgb.x), ST2084_to_Y(rgb.y), ST2084_to_Y(rgb.z)); | |
// } | |
float Y_to_sRGB(float C) // returns signal, 0-1, input 0-1 | |
{ | |
return (C < 0.f) | |
? 0.f | |
: ((C > 1.f) ? 1.f | |
: ((C < 0.0031308f) | |
? C * 12.92f | |
: (1.055f * pow(C, 1.0f / 2.4f) - 0.055f))); | |
} | |
float3 Y_to_sRGB_3(float3 rgb) { | |
return float3(Y_to_sRGB(rgb.x), Y_to_sRGB(rgb.y), Y_to_sRGB(rgb.z)); | |
} | |
float HLG_to_Y(float C) { | |
const float a = 0.17883277f; | |
const float b = 0.28466892f; | |
const float c = 0.55991073f; | |
return (C < 0.f) ? 0.f : ((C <= 0.5f) ? (4.f * C * C) : exp((C - c) / a) + b); | |
} | |
float3 HLG_to_Y_3(float3 rgb) { | |
return float3(HLG_to_Y(rgb.x), HLG_to_Y(rgb.y), HLG_to_Y(rgb.z)); | |
} | |
float3 reinhard(float3 rgb){ | |
return rgb / (rgb+1); | |
} | |
float4 main(float2 tex : TEXCOORD0) : COLOR { | |
float gain=1.f; | |
float4 c0 = tex2D(s0, tex); | |
float3 l = reinhard(HLG_to_Y_3(c0.xyz)*gain); | |
float4 c = float4(Y_to_sRGB_3(l),1.); | |
return c; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment