mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-21 21:30:19 -06:00
Video: implement color correction to match the NTSC and PAL color spaces (and gamma) that GC and Wii targeted.
To further increase the accuracy of the post process phase, I've added (scRGB) HDR support, which is necessary to fully display the PAL and NTSC-J color spaces, and also to improve the quality of post process texture samplings and do them in linear space instead of gamma space (which is very important when playing at low resolutions). For SDR, the quality is also slightly increased, at least if any post process runs, as the buffer is now R10G10B10A2 (on Vulkan, DX11 and DX12) if supported; previously it was R8G8B8A8 but the alpha bits were wasted. Gamma correction is arguably the most important thing as Dolphin on Windows outputted in "sRGB" (implicitly) as that's what Windows expects by default, though sRGB gamma is very different from the gamma commonly used by video standards dating to the pre HDR era (roughly gamma 2.35). Additionally, the addition of HDR support (which is pretty straight forward and minimal), added support for our own custom AutoHDR shaders, which would allow us to achieve decent looking HDR in Dolphin games without having to use SpecialK or Windows 11 AutoHDR. Both of which don't necessarily play nice with older games with strongly different and simpler lighting. HDR should also be supported in Linux. Development of my own AutoHDR shader is almost complete and will come next. This has been carefully tested and there should be no regression in any of the different features that Dolphin offers, like multisampling, stereo rendering, other post processes, etc etc. Fixes: https://bugs.dolphin-emu.org/issues/8941 Co-authored-by: EndlesslyFlowering <EndlesslyFlowering@protonmail.com> Co-authored-by: Dogway <lin_ares@hotmail.com>
This commit is contained in:
@ -154,7 +154,7 @@ bool SwapChain::SelectSurfaceFormat()
|
||||
&format_count, surface_formats.data());
|
||||
ASSERT(res == VK_SUCCESS);
|
||||
|
||||
// If there is a single undefined surface format, the device doesn't care, so we'll just use RGBA
|
||||
// If there is a single undefined surface format, the device doesn't care, so we'll just use RGBA8
|
||||
if (surface_formats[0].format == VK_FORMAT_UNDEFINED)
|
||||
{
|
||||
m_surface_format.format = VK_FORMAT_R8G8B8A8_UNORM;
|
||||
@ -162,22 +162,61 @@ bool SwapChain::SelectSurfaceFormat()
|
||||
return true;
|
||||
}
|
||||
|
||||
// Try to find a suitable format.
|
||||
const VkSurfaceFormatKHR* surface_format_RGBA8 = nullptr;
|
||||
const VkSurfaceFormatKHR* surface_format_BGRA8 = nullptr;
|
||||
const VkSurfaceFormatKHR* surface_format_RGB10_A2 = nullptr;
|
||||
const VkSurfaceFormatKHR* surface_format_RGBA16F_scRGB = nullptr;
|
||||
|
||||
// Try to find all suitable formats.
|
||||
for (const VkSurfaceFormatKHR& surface_format : surface_formats)
|
||||
{
|
||||
// Some drivers seem to return a SRGB format here (Intel Mesa).
|
||||
// This results in gamma correction when presenting to the screen, which we don't want.
|
||||
// Use a linear format instead, if this is the case.
|
||||
// Some drivers seem to return a RGBA8 SRGB format here (Intel Mesa).
|
||||
// Some other drivers return both a RGBA8 SRGB and UNORM formats (Nvidia).
|
||||
// This results in gamma correction when presenting to the screen, which we don't want,
|
||||
// because we already apply gamma ourselves, and we might not use sRGB gamma.
|
||||
// Force using a linear format instead, if this is the case.
|
||||
VkFormat format = VKTexture::GetLinearFormat(surface_format.format);
|
||||
if (format == VK_FORMAT_R8G8B8A8_UNORM)
|
||||
surface_format_RGBA8 = &surface_format;
|
||||
else if (format == VK_FORMAT_B8G8R8A8_UNORM)
|
||||
surface_format_BGRA8 = &surface_format;
|
||||
else if (format == VK_FORMAT_A2B10G10R10_UNORM_PACK32 &&
|
||||
surface_format.colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR)
|
||||
surface_format_RGB10_A2 = &surface_format;
|
||||
else if (format == VK_FORMAT_R16G16B16A16_SFLOAT &&
|
||||
surface_format.colorSpace == VK_COLOR_SPACE_EXTENDED_SRGB_LINEAR_EXT)
|
||||
surface_format_RGBA16F_scRGB = &surface_format;
|
||||
else
|
||||
continue;
|
||||
}
|
||||
|
||||
const VkSurfaceFormatKHR* surface_format = nullptr;
|
||||
|
||||
// Pick the best format.
|
||||
// "g_ActiveConfig" might not have been been updated yet.
|
||||
if (g_Config.bHDR && surface_format_RGBA16F_scRGB)
|
||||
surface_format = surface_format_RGBA16F_scRGB;
|
||||
else if (surface_format_RGB10_A2)
|
||||
surface_format = surface_format_RGB10_A2;
|
||||
else if (surface_format_RGBA8)
|
||||
surface_format = surface_format_RGBA8;
|
||||
else if (surface_format_BGRA8)
|
||||
surface_format = surface_format_BGRA8;
|
||||
|
||||
if (surface_format)
|
||||
{
|
||||
const VkFormat format = VKTexture::GetLinearFormat(surface_format->format);
|
||||
if (format == VK_FORMAT_R8G8B8A8_UNORM)
|
||||
m_texture_format = AbstractTextureFormat::RGBA8;
|
||||
else if (format == VK_FORMAT_B8G8R8A8_UNORM)
|
||||
m_texture_format = AbstractTextureFormat::BGRA8;
|
||||
else
|
||||
continue;
|
||||
else if (format == VK_FORMAT_A2B10G10R10_UNORM_PACK32)
|
||||
m_texture_format = AbstractTextureFormat::RGB10_A2;
|
||||
else if (format == VK_FORMAT_R16G16B16A16_SFLOAT)
|
||||
m_texture_format = AbstractTextureFormat::RGBA16F;
|
||||
|
||||
m_surface_format.format = format;
|
||||
m_surface_format.colorSpace = surface_format.colorSpace;
|
||||
m_surface_format.colorSpace = surface_format->colorSpace;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user