MaterialX icon indicating copy to clipboard operation
MaterialX copied to clipboard

MaterialXView: Toggling boolean input on and then back off does not revert the value

Open hybridherbst opened this issue 6 months ago • 1 comments

Image

Reproduction steps

  1. Download MyKeywordGraph.mtlx.zip
  2. Open in MaterialXView
  3. Open "Property Editor"
  4. Flip the toggle – note visual output changes, as expected
  5. Flip the toggle back – note visual output does not change
  6. Continue flipping the toggle – output will not change ever again until reloading the file

Edit: This works fine in MaterialXGraphEditor and MaterialXWebViewer.

hybridherbst avatar Jun 04 '25 18:06 hybridherbst

Whoa, good catch -- that's unexpected!

jstone-lucasfilm avatar Jun 04 '25 18:06 jstone-lucasfilm

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.

warrenm avatar Jun 26 '25 02:06 warrenm

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.

warrenm avatar Jun 26 '25 03:06 warrenm