Skip to content

Commit

Permalink
Fix ICtCp chroma scaling in HDR tonemaps
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaldaien committed Jul 21, 2024
1 parent 04be0fc commit 303ee96
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 10 deletions.
21 changes: 12 additions & 9 deletions resources/shaders/imgui_pix_shader.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,19 @@ float4 main (PS_INPUT input) : SV_Target

if (Y_out + Y_in > 0.0)
{
float I0 = ICtCp.x;
float I_scale = 0.0f;

ICtCp.x *=
max ((Y_out / Y_in), 0.0f);

if (ICtCp.x != 0.0f && I0 != 0.0f)
{
I_scale =
min (I0 / ICtCp.x, ICtCp.x / I0);
}

ICtCp.yz *= I_scale;
}

else
Expand Down Expand Up @@ -363,12 +374,4 @@ float4 main (PS_INPUT input) : SV_Target
SanitizeFP (out_col);
};

#endif








#endif
32 changes: 31 additions & 1 deletion src/utility/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1212,8 +1212,23 @@ SKIV_Image_TonemapToSDR (const DirectX::Image& image, DirectX::ScratchImage& fin

if (Y_out + Y_in > 0.0f)
{
float I0 = XMVectorGetX (ICtCp);
float I1 = 0.0f;
float I_scale = 0.0f;

ICtCp.m128_f32 [0] *=
std::max ((Y_out / Y_in), 0.0f);

I1 = XMVectorGetX (ICtCp);

if (I0 != 0.0f && I1 != 0.0f)
{
I_scale =
std::min (I0 / I1, I1 / I0);
}

ICtCp.m128_f32 [1] *= I_scale;
ICtCp.m128_f32 [2] *= I_scale;
}

value =
Expand Down Expand Up @@ -1405,8 +1420,23 @@ SKIV_Image_SaveToDisk_SDR (const DirectX::Image& image, const wchar_t* wszFileNa

if (Y_out + Y_in > 0.0f)
{
float I0 = XMVectorGetX (ICtCp);
float I1 = 0.0f;
float I_scale = 0.0f;

ICtCp.m128_f32 [0] *=
std::max ((Y_out / Y_in), 0.0f);

I1 = XMVectorGetX (ICtCp);

if (I0 != 0.0f && I1 != 0.0f)
{
I_scale =
std::min (I0 / I1, I1 / I0);
}

ICtCp.m128_f32 [1] *= I_scale;
ICtCp.m128_f32 [2] *= I_scale;
}

value =
Expand Down Expand Up @@ -1697,7 +1727,7 @@ SKIV_Image_CaptureDesktop (DirectX::ScratchImage& image, POINT point, int flags)

// The list of supported formats should always contain DXGI_FORMAT_B8G8R8A8_UNORM,
// as this is the most common format for the desktop.
DXGI_FORMAT_B8G8R8A8_UNORM
//DXGI_FORMAT_B8G8R8A8_UNORM
};

static constexpr int num_sdr_formats = 4;
Expand Down

0 comments on commit 303ee96

Please sign in to comment.