Fix inconsistent background color in MaterialXView on Metal#2800
Merged
jstone-lucasfilm merged 2 commits intoAcademySoftwareFoundation:mainfrom Mar 5, 2026
Merged
Conversation
Member
jstone-lucasfilm
left a comment
There was a problem hiding this comment.
This looks like a valuable improvement, @aabhinavvvvvvv, and I had just one recommendation about using the existing Color3::srgbToLinear instead of a custom lambda.
| // background color must be converted to linear before being set as the clear color. | ||
| // On OpenGL (Windows), the background is stored directly in a non-linear framebuffer | ||
| // and no conversion is needed. | ||
| auto srgbToLinear = [](float srgb) -> float { |
Member
There was a problem hiding this comment.
Instead of this custom lambda, could we use the existing Color3::srgbToLinear in MaterialXCore, so that this math remains centralized?
jstone-lucasfilm
approved these changes
Mar 5, 2026
Member
jstone-lucasfilm
left a comment
There was a problem hiding this comment.
Thanks for this improvement, @aabhinavvvvvvv!
7e91c4d
into
AcademySoftwareFoundation:main
33 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #2606
The
MaterialXViewbackground color appeared lighter on Mac (Metal) than on Windows (OpenGL) due to a color space mismatch in the Metal rendering pipeline.Root Cause
The Metal renderer uses an
MTLPixelFormatRGBA16Float(linear) framebuffer. macOS applies gamma correction when displaying linear float values. The background color stored inm_backgroundcomes fromDEFAULT_SCREEN_COLOR_SRGB = (0.3, 0.3, 0.32)— sRGB-encoded values. Passing these directly tosetClearColoron a linear framebuffer causes macOS to gamma-correct them on display (sRGB(0.3) ≈ 0.58), producing a noticeably lighter background.On Windows/OpenGL,
glClearColorwrites values into a non-linear framebuffer which the display interprets as sRGB — so the appearance is correct.The previous code also had a
linearToSrgbconversion applied in the wrong direction, converting already-sRGB values further into sRGB and making the discrepancy worse.Fix
Replace
linearToSrgbwithsrgbToLinearinRenderPipelineMetal.mm. This converts the sRGB background values to their linear equivalents before storing in the float framebuffer. macOS then gamma-corrects them back on display, producing the intended(0.3, 0.3, 0.32)gray — matching the Windows/OpenGL output.This aligns with the finding in the issue that using
DEFAULT_SCREEN_COLOR_LIN_REC709(which isDEFAULT_SCREEN_COLOR_SRGB.srgbToLinear()) resolves the inconsistency.