提交 8c0e220b 编写于 作者: M Matt Pharr

Film: clamp RGB values to avoid infinite values in fp16 EXR files

上级 f7019fbe
......@@ -241,6 +241,7 @@ void ImageTileIntegrator::Render() {
waveEnd = std::min(spp, waveEnd + nextWaveSize);
if (!referenceImage)
nextWaveSize = std::min(2 * nextWaveSize, 64);
if (waveStart == spp) progress.Done();
// Optionally write current image to disk
if (waveStart == spp || Options->writePartialImages || referenceImage) {
......@@ -267,7 +268,6 @@ void ImageTileIntegrator::Render() {
if (mseOutFile)
fclose(mseOutFile);
progress.Done();
DisconnectFromDisplayServer();
LOG_VERBOSE("Rendering finished");
}
......
......@@ -550,13 +550,24 @@ Image RGBFilm::GetImage(ImageMetadata *metadata, Float splatScale) {
PixelFormat format = writeFP16 ? PixelFormat::Half : PixelFormat::Float;
Image image(format, Point2i(pixelBounds.Diagonal()), {"R", "G", "B"});
std::atomic<int> nClamped{0};
ParallelFor2D(pixelBounds, [&](Point2i p) {
RGB rgb = GetPixelRGB(p, splatScale);
if (writeFP16 && std::max({rgb.r, rgb.g, rgb.b}) > 65504) {
if (rgb.r > 65504) rgb.r = 65504;
if (rgb.g > 65504) rgb.g = 65504;
if (rgb.b > 65504) rgb.b = 65504;
++nClamped;
}
Point2i pOffset(p.x - pixelBounds.pMin.x, p.y - pixelBounds.pMin.y);
image.SetChannels(pOffset, {rgb[0], rgb[1], rgb[2]});
});
if (nClamped.load() > 0)
Warning("%d pixel values clamped to maximum fp16 value.", nClamped.load());
metadata->pixelBounds = pixelBounds;
metadata->fullResolution = fullResolution;
metadata->colorSpace = colorSpace;
......@@ -712,6 +723,7 @@ Image GBufferFilm::GetImage(ImageMetadata *metadata, Float splatScale) {
ImageChannelDesc relVarianceDesc = image.GetChannelDesc(
{"RelativeVariance.R", "RelativeVariance.G", "RelativeVariance.B"});
std::atomic<int> nClamped{0};
ParallelFor2D(pixelBounds, [&](Point2i p) {
Pixel &pixel = pixels[p];
RGB rgb(pixel.rgbSum[0], pixel.rgbSum[1], pixel.rgbSum[2]);
......@@ -735,6 +747,13 @@ Image GBufferFilm::GetImage(ImageMetadata *metadata, Float splatScale) {
rgb = outputRGBFromSensorRGB * rgb;
if (writeFP16 && std::max({rgb.r, rgb.g, rgb.b}) > 65504) {
if (rgb.r > 65504) rgb.r = 65504;
if (rgb.g > 65504) rgb.g = 65504;
if (rgb.b > 65504) rgb.b = 65504;
++nClamped;
}
Point2i pOffset(p.x - pixelBounds.pMin.x, p.y - pixelBounds.pMin.y);
image.SetChannels(pOffset, rgbDesc, {rgb[0], rgb[1], rgb[2]});
image.SetChannels(pOffset, albedoRgbDesc,
......@@ -758,6 +777,9 @@ Image GBufferFilm::GetImage(ImageMetadata *metadata, Float splatScale) {
pixel.varianceEstimator[2].RelativeVariance()});
});
if (nClamped.load() > 0)
Warning("%d pixel values clamped to maximum fp16 value.", nClamped.load());
metadata->pixelBounds = pixelBounds;
metadata->fullResolution = fullResolution;
metadata->colorSpace = colorSpace;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册