Fix color space issues with sRGB framebuffer in Graph Editor#2402
Merged
jstone-lucasfilm merged 6 commits intoMay 23, 2025
Merged
Conversation
… for Color3 field
… for Color4 field
…in color space handling
lfl-eholthouser
approved these changes
May 22, 2025
lfl-eholthouser
left a comment
Contributor
There was a problem hiding this comment.
Thanks for fixing this issue @mialana. I think the changes look great!
| ImGui::SameLine(); | ||
| ImGui::ColorEdit3("##color", &temp[0], ImGuiColorEditFlags_NoInputs); | ||
|
|
||
| // read material value in converted display space |
Contributor
There was a problem hiding this comment.
I want to flag that this pr #2395 is also modifying the color3 and color4 section of setConstant()
jstone-lucasfilm
left a comment
Member
There was a problem hiding this comment.
This looks great to me, @mialana, and I've added two minor suggestions to match the coding style of the MaterialX project.
Contributor
Author
|
I have just made the style fixes. Thank you @lfl-eholthouser and @jstone-lucasfilm! |
jstone-lucasfilm
approved these changes
May 23, 2025
c1e7122
into
AcademySoftwareFoundation:main
32 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.
Related issue and Dev Days PR for Viewer
This PR addresses color space discrepancies / logic in MaterialX Graph Editor.
Summary of Problem:
Before, the graph editor used an sRGB framebuffer (i.e.
glEnable(GL_FRAMEBUFFER_SRGB)) for the entire GUI, meaning both the rendered material (with its color values given in linear space) and the ImGUI components had an automatic "to-sRGB" transformation applied to them.Although this is desired for the material preview, which is a rendered, PBR result and needs to be color corrected to display space, it has adverse results on ImGUI components that handle color. This is because currently, ImGUI is not completely compatible with sRGB-enabled framebuffers (ref: 578, 1724, 2943 4890, 6583). To exemplify a problem that arises, alpha-blending is calculated incorrectly when using an sRGB framebuffer.
Compare a "correct" color picker rendered w/o sRGB-enabled framebuffer with a color picker rendered w/ sRGB-enabled framebuffer, which is how it was done before this PR. I gave it the same color value, but in linear space:
There is clearly a non-negligible difference in both the color ramp and the overall canvas (which is the result of a completely different blending equation being applied, as commented on here). This calculation error results in the color picker UI component being in a nonlinear display space and should be avoided.
Resolution Implemented:
ImGui::GetWindowDrawList()->AddCallback()function to to inject a call toglEnable(GL_FRAMEBUFFER_SRGB)into ImGUI's iterative draw list right before the materialview texture is drawn, and disable it immediately after.This effectively maintains the original material render result, but solves the color problems in the UI.
Color3::linearToSrgb()andColor3::srgbToLinear()are used to transform between color spaces. The result is below.Before: User previews rendered material and color picker swatch in display space, but the actual color value numbers are actually in the linear range. These values will not match up in other applications, such as Adobe products, which is misleading.

After: User always interacts with color in display space (pick + view), but behind-the-scenes, the color is written / stored in linear space.

Rendered material result is successfully maintained:
Please let me know if I can clarify on any of the points I mentioned above. I tried to balance digital color principles / correctness with overall UI experience in these changes. Thanks!