Skip to content

Fix overwriting of alpha values in Viewer colorpicker#2404

Merged
jstone-lucasfilm merged 6 commits into
AcademySoftwareFoundation:mainfrom
mialana:fix-viewer-colorpicker-alpha
May 23, 2025
Merged

Fix overwriting of alpha values in Viewer colorpicker#2404
jstone-lucasfilm merged 6 commits into
AcademySoftwareFoundation:mainfrom
mialana:fix-viewer-colorpicker-alpha

Conversation

@mialana

@mialana mialana commented May 21, 2025

Copy link
Copy Markdown
Contributor

Currently, if an user uses the MaterialXView colorpicker for a Color4 field, the alpha component is automatically overwritten and transformed to a value of 1, regardless of original value. Although it is shown unmodified in the UI, if written out to file, the alpha component is always "1". e.g.

<input name="bias" type="color4" value="0.0908109, 0.0908109, 0.0908109, 1" />

This is because the Nanogui ColorWheel class does not handle color values with 4 components, yet the Nanogui ColorPicker class refers to its color wheel member to set the new picked color (code ref).

To prevent this from happening, I modified the current class EditorColorPicker : public ng::ColorPicker, and created custom callbacks for m_color_wheel and m_pick_button. The logic essentially is -- since we have additional color widget members in our color picker, we instead refer to their values when setting the color value. Then, the alpha component can only be changed via the color widgets, so interacting with the color wheel does not change / overwrite the original alpha component.

The following GIF is a simple visual demonstration of the alpha being correctly preserved and previewed in the PickButton. I've also tested saving out to file to validate the written value.

// Transform sRGBA color picker value to linear space for writing to material
mx::Color3 linearCol = mx::Color3(c.r(), c.g(), c.b()).srgbToLinear();
mx::Vector3 v(linearCol[0], linearCol[1], linearCol[2]);
mx::Vector4 v(linearCol[0], linearCol[1], linearCol[2], c.a());

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Additionally, I realized that in my previous PR to handle color space transformations, I erroneously concatenated all 4D color vectors to 3D when writing to material. This is my mistake, and is fixed in this PR.

@jstone-lucasfilm jstone-lucasfilm requested review from jstone-lucasfilm and lfl-eholthouser and removed request for lfl-eholthouser May 21, 2025 23:40

@jstone-lucasfilm jstone-lucasfilm left a comment

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.

Thanks for these fixes, @mialana!

There's one minor coding style issue in the change, but I'll just make the adjustment on my side before merging.

Signed-off-by: Jonathan Stone <jstone@lucasfilm.com>
Signed-off-by: Jonathan Stone <jstone@lucasfilm.com>
@jstone-lucasfilm jstone-lucasfilm changed the title Fix alpha values being overwritten by MaterialXView colorpicker Fix overwriting of alpha values in Viewer colorpicker May 23, 2025
@jstone-lucasfilm jstone-lucasfilm merged commit 667d309 into AcademySoftwareFoundation:main May 23, 2025
32 checks passed
@mialana

mialana commented May 23, 2025

Copy link
Copy Markdown
Contributor Author

Thank you @jstone-lucasfilm for making the changes on your end -- sorry I missed these notes yesterday!

@mialana mialana deleted the fix-viewer-colorpicker-alpha branch May 14, 2026 23:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants