Skip to content

Commit 1538a22

Browse files
Use Color3::srgbToLinear in Metal background color conversion
1 parent 0aa974d commit 1538a22

1 file changed

Lines changed: 6 additions & 9 deletions

File tree

source/MaterialXView/RenderPipelineMetal.mm

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -472,17 +472,14 @@
472472
// background color must be converted to linear before being set as the clear color.
473473
// On OpenGL (Windows), the background is stored directly in a non-linear framebuffer
474474
// and no conversion is needed.
475-
auto srgbToLinear = [](float srgb) -> float {
476-
if (srgb <= 0.04045f)
477-
return srgb / 12.92f;
478-
else
479-
return std::pow((srgb + 0.055f) / 1.055f, 2.4f);
480-
};
475+
mx::Color3 bgLinear = mx::Color3(_viewer->m_background[0],
476+
_viewer->m_background[1],
477+
_viewer->m_background[2]).srgbToLinear();
481478

482479
[renderpassDesc.colorAttachments[0] setClearColor:MTLClearColorMake(
483-
srgbToLinear(_viewer->m_background[0]),
484-
srgbToLinear(_viewer->m_background[1]),
485-
srgbToLinear(_viewer->m_background[2]),
480+
bgLinear[0],
481+
bgLinear[1],
482+
bgLinear[2],
486483
_viewer->m_background[3])];
487484
[renderpassDesc.colorAttachments[0] setLoadAction:MTLLoadActionClear];
488485
[renderpassDesc.colorAttachments[0] setStoreAction:MTLStoreActionStore];

0 commit comments

Comments
 (0)