MaterialXView: Toggling boolean input on and then back off does not revert the value
Reproduction steps
- Download MyKeywordGraph.mtlx.zip
- Open in MaterialXView
- Open "Property Editor"
- Flip the toggle – note visual output changes, as expected
- Flip the toggle back – note visual output does not change
- Continue flipping the toggle – output will not change ever again until reloading the file
Edit: This works fine in MaterialXGraphEditor and MaterialXWebViewer.
Whoa, good catch -- that's unexpected!
After doing some spelunking, the cause of this issue seems to be a type mismatch between the value created in the editor code and the value type emitted by the Metal shader generator: the editor boxes up the checkbox value as a float, which ultimately gets copied into the uniform buffer down in MslProgram::bindUniformBuffers around here. The type of the property in the shader is bool rather than float. Copying the 4 bytes of float value 1.0f results in a 0x00 byte at the offset where a boolean is expected, so the value seen by the shader can never become true again after the box is toggled off.
I'm not sure what a comprehensive fix looks like, but boxing the checkbox value into a bool value instead of a float value (on line 306 referenced above) fixes this in MaterialXView on macOS when using the Metal rendering pipeline.
The above fix also seems to work (i.e., not break) on the OpenGL path on macOS: there, the uniform binding code bottoms out in a call to glUniform1i rather than glUniform1f with the fix applied, with both having the same (expected) effect. I'm not sure how many other configurations need to be tested, but I'll draft a PR with this suggested fix.