View Single Post
Old 23rd May 2019, 17:16   #56321  |  Link
Alexkral
Registered User
 
Join Date: Oct 2018
Posts: 319
@Daicon

Save this as *.hlsl and load it in MPC-HC. It just convert the gamut to Rec.709 or DCI-P3. You can edit it as a text file, change the gamut option from the second line to DCI-P3 if you get oversaturation.

Code:
sampler s0 : register(s0);

static int GAMUT = 0;		//Rec.709 = 0, DCI-P3 = 1

static float m1 = 2610.0 / 4096.0 / 4;
static float m2 = 2523.0 / 4096.0 * 128;
static float c1 = 3424.0 / 4096.0;
static float c2 = 2413.0 / 4096.0 * 32;
static float c3 = 2392.0 / 4096.0 * 32;

static float3x3 Rec709 =
{
    1.660491, -0.5876411, -0.0728499,
    -0.1245505, 1.1328999, -0.0083494,
    -0.0181508, -0.1005789, 1.1187297
};

static float3x3 DCIP3 =
{
    1.3435783, -0.2821797, -0.0613986,
    -0.0652975, 1.0757879, -0.0104905,
    0.0028218, -0.0195985, 1.0167767
};

float3 PQ_EOTF(float3 Ep)
{
    float3 p = pow(Ep, 1 / m2);
    return pow(max(p - c1, 0) / (c2 - c3 * p), 1 / m1);
}

float3 PQ_OETF(float3 Fd)
{
    float3 p = pow(Fd, m1);
    return pow((c1 + c2 * p) / (1 + c3 * p), m2);
}

float4 main(float2 tex : TEXCOORD0) : COLOR
{
    float3x3 mat;
    float3 color = tex2D(s0, tex).rgb;
    color = PQ_EOTF(color);
    mat = GAMUT == 0 ? Rec709 : DCIP3;
    color = saturate(mul(mat, color));
    color = PQ_OETF(color);
    return float4(color, 1);
}
Alexkral is offline   Reply With Quote