Skip to content

Commit

Permalink
Merge pull request xbmc#24739 from thexai/fix-pixel-shaders
Browse files Browse the repository at this point in the history
[Windows] Fix inaccurate 10-bit SDR / HDR color using Pixel Shaders
  • Loading branch information
fuzzard authored Mar 1, 2024
2 parents d1f2c53 + 19c6aae commit 36c6d14
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion system/shaders/output_d3d.fx
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ float4 OUTPUT_PS(VS_OUTPUT In) : SV_TARGET
{
float4 color = g_Texture.Sample(KernelSampler, In.TextureUV);
[flatten] if (m_params.x)
color = saturate(0.0625 + color * 219.0 / 255.0);
color = saturate((64.0 / 1023.0) + color * (940.0 - 64.0) / 1023.0);

color *= m_params.y * 2.0;
color += m_params.z - 0.5;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -515,15 +515,15 @@ const CGlMatrix& CConvertMatrix::GenMat()
{
if (m_srcBits >= 12)
{
CScale scale(4080.0f / (3760 - 256), 4080.0f / (3840 - 256), 4080.0f / (3840 - 256));
CTranslate trans(- 256.0f / 4080, - 256.0f / 4080, - 256.0f / 4080);
CScale scale(4095.0f / (3760 - 256), 4095.0f / (3840 - 256), 4095.0f / (3840 - 256));
CTranslate trans(-256.0f / 4095.0f, -256.0f / 4095.0f, -256.0f / 4095.0f);
mat *= scale;
mat *= trans;
}
else if (m_srcBits == 10)
{
CScale scale(1020.0f / (940 - 64), 1020.0f / (960 - 64), 1020.0f / (960 - 64));
CTranslate trans(- 64.0f / 1020, - 64.0f / 1020, - 64.0f / 1020);
CScale scale(1023.0f / (940 - 64), 1023.0f / (960 - 64), 1023.0f / (960 - 64));
CTranslate trans(-64.0f / 1023.0f, -64.0f / 1023.0f, -64.0f / 1023.0f);
mat *= scale;
mat *= trans;
}
Expand Down Expand Up @@ -559,8 +559,8 @@ Matrix4 CConvertMatrix::GetYuvMat()
ret *= black;
if (m_limitedDst)
{
float valScale = (235 - 16) / 255.0f;
float valTrans = 16.0f / 255;
float valScale = (940.0f - 64.0f) / 1023.0f;
float valTrans = 64.0f / 1023.0f;
CScale scale(valScale, valScale, valScale);
CTranslate trans(valTrans, valTrans, valTrans);
ret *= trans;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,19 @@ Matrix4 bt709Mat_8bit(bt709_8bit);

std::array<std::array<float, 4>, 4> bt709_10bit =
{{
{1.1643834114, 1.1643834114, 1.1643834114, 0.0000000000},
{0.0000000000, -0.2132485956, 2.1124014854, 0.0000000000},
{1.7927408218, -0.5329092145, 0.0000000000, 0.0000000000},
{1.1678080559, 1.1678080559, 1.1678080559, 0.0000000000},
{0.0000000000, -0.2138758004, 2.1186144352, 0.0000000000},
{1.7980136871, -0.5344766378, 0.0000000000, 0.0000000000},
{-0.9729449749, 0.3014826477, -1.1334021091, 1.0000000000},
}};

Matrix4 bt709Mat_10bit(bt709_10bit);

std::array<std::array<float, 4>, 4> bt709_10bit_texture =
{{
{74.5922470093, 74.5922470093, 74.5922470093, 0.0000000000},
{0.0000000000, -13.6610431671, 135.3237915039, 0.0000000000},
{114.8458175659, -34.1390075684, 0.0000000000, 0.0000000000},
{74.8116378784, 74.8116378784, 74.8116378784, 0.0000000000},
{0.0000000000, -13.7012224197, 135.7218017578, 0.0000000000},
{115.1836090088, -34.2394218445, 0.0000000000, 0.0000000000},
{-0.9729449749, 0.3014826477, -1.1334021091, 1.0000000000},
}};

Expand Down

0 comments on commit 36c6d14

Please sign in to comment.