Commit 7e91c4d
authored
Fix inconsistent background color in MaterialXView on Metal (#2800)
## 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.1 parent 2cecaad commit 7e91c4d
1 file changed
Lines changed: 12 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
467 | 467 | | |
468 | 468 | | |
469 | 469 | | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
470 | 479 | | |
471 | | - | |
472 | | - | |
473 | | - | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
474 | 483 | | |
475 | 484 | | |
476 | 485 | | |
| |||
0 commit comments