File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 467467 {
468468 [renderpassDesc.colorAttachments[0 ] setTexture: MTL (currentFramebuffer ())->getColorTexture ()];
469469 }
470+ // The Metal framebuffer stores linear color values (MTLPixelFormatRGBA16Float).
471+ // macOS applies gamma correction when displaying linear float values, so the sRGB
472+ // background color must be converted to linear before being set as the clear color.
473+ // On OpenGL (Windows), the background is stored directly in a non-linear framebuffer
474+ // 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+ };
481+
470482 [renderpassDesc.colorAttachments[0 ] setClearColor: MTLClearColorMake (
471- _viewer->m_background[0 ],
472- _viewer->m_background[1 ],
473- _viewer->m_background[2 ],
483+ srgbToLinear ( _viewer->m_background[0 ]) ,
484+ srgbToLinear ( _viewer->m_background[1 ]) ,
485+ srgbToLinear ( _viewer->m_background[2 ]) ,
474486 _viewer->m_background[3 ])];
475487 [renderpassDesc.colorAttachments[0 ] setLoadAction: MTLLoadActionClear ];
476488 [renderpassDesc.colorAttachments[0 ] setStoreAction: MTLStoreActionStore ];
You can’t perform that action at this time.
0 commit comments