Skip to content

Fix inconsistent background color in MaterialXView on Metal#2800

Merged
jstone-lucasfilm merged 2 commits intoAcademySoftwareFoundation:mainfrom
aabhinavvvvvvv:fix/metal-background-color-srgb
Mar 5, 2026
Merged

Fix inconsistent background color in MaterialXView on Metal#2800
jstone-lucasfilm merged 2 commits intoAcademySoftwareFoundation:mainfrom
aabhinavvvvvvv:fix/metal-background-color-srgb

Conversation

@aabhinavvvvvvv
Copy link
Copy Markdown
Contributor

Summary

Fixes #2606

The MaterialXView background 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 in m_background comes from DEFAULT_SCREEN_COLOR_SRGB = (0.3, 0.3, 0.32) — sRGB-encoded values. Passing these directly to setClearColor on a linear framebuffer causes macOS to gamma-correct them on display (sRGB(0.3) ≈ 0.58), producing a noticeably lighter background.

On Windows/OpenGL, glClearColor writes values into a non-linear framebuffer which the display interprets as sRGB — so the appearance is correct.

The previous code also had a linearToSrgb conversion applied in the wrong direction, converting already-sRGB values further into sRGB and making the discrepancy worse.

Fix

Replace linearToSrgb with srgbToLinear in RenderPipelineMetal.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 is DEFAULT_SCREEN_COLOR_SRGB.srgbToLinear()) resolves the inconsistency.

@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla Bot commented Mar 5, 2026

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: aabhinavvvvvvv / name: Abhinav Kumar Gupta (0aa974d, 1538a22)

Copy link
Copy Markdown
Member

@jstone-lucasfilm jstone-lucasfilm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of this custom lambda, could we use the existing Color3::srgbToLinear in MaterialXCore, so that this math remains centralized?

Copy link
Copy Markdown
Member

@jstone-lucasfilm jstone-lucasfilm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this improvement, @aabhinavvvvvvv!

@jstone-lucasfilm jstone-lucasfilm merged commit 7e91c4d into AcademySoftwareFoundation:main Mar 5, 2026
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inconsistent background color in MaterialXViewer

2 participants