Fix precision loss when downcasting to HDR/EXR identified by @iOrange

* When outputting to a format supporting more than 8-bit data, we don't want to
  lose precision by downcasting e.g. D32S8 to RGBA8, instead use RGBA32.
This commit is contained in:
baldurk
2020-01-16 23:06:23 +00:00
parent 892abb686f
commit 08b2572554
+15 -3
View File
@@ -748,9 +748,21 @@ bool ReplayController::SaveTexture(const TextureSave &saveData, const char *path
if(downcast)
{
// if the source and destination are more than 1 byte per component, remap to RGBA32
if(td.format.compByteWidth > 1 && (sd.destType == FileType::DDS ||
sd.destType == FileType::HDR || sd.destType == FileType::EXR))
const bool destHDR = (sd.destType == FileType::DDS || sd.destType == FileType::HDR ||
sd.destType == FileType::EXR);
const bool sourceHDR =
td.format.compByteWidth > 1 || td.format.type == ResourceFormatType::D16S8 ||
td.format.type == ResourceFormatType::D24S8 || td.format.type == ResourceFormatType::D32S8 ||
td.format.type == ResourceFormatType::R11G11B10 ||
td.format.type == ResourceFormatType::R10G10B10A2 ||
td.format.type == ResourceFormatType::R9G9B9E5 || td.format.type == ResourceFormatType::BC6 ||
td.format.type == ResourceFormatType::BC7 || td.format.type == ResourceFormatType::YUV10 ||
td.format.type == ResourceFormatType::YUV12 || td.format.type == ResourceFormatType::YUV16;
// if the source and destination have more than 1 byte per component, remap to RGBA32 to avoid
// precision loss
if(sourceHDR && destHDR)
{
remap = RemapTexture::RGBA32;
td.format.compByteWidth = 4;