Skip to content

Bug fix: genmsl image node handling for MaterialX constant texture address#2891

Open
bhouston wants to merge 1 commit into
AcademySoftwareFoundation:mainfrom
bhouston:fix-metal-constant-addressingmode
Open

Bug fix: genmsl image node handling for MaterialX constant texture address#2891
bhouston wants to merge 1 commit into
AcademySoftwareFoundation:mainfrom
bhouston:fix-metal-constant-addressingmode

Conversation

@bhouston

@bhouston bhouston commented May 7, 2026

Copy link
Copy Markdown
Contributor

Metal previously relied on MTLSamplerAddressModeClampToBorderColor for constant addressing. Metal samplers only support opaque black/white border colors, so arbitrary MaterialX image default values, for example bright green-yellow, rendered incorrectly as white.

Fix

  • Added MSL-specific image implementations for all image output types: float, color3, color4, vector2, vector3, and vector4.
  • Added a shared helper, mx_image_coord_out_of_bounds, that checks transformed UVs against [0, 1] only for axes using constant address mode.
  • When out of bounds, the image node now returns its MaterialX default input; otherwise it samples the texture normally.
  • Updated stdlib_genmsl_impl.mtlx to use these MSL image implementations instead of reusing the GLSL versions.

How It Was Realized

This was found through fidelity samples that set uaddressmode and vaddressmode to constant with a non-white default color. GLSL, OSL, Three.js, and Blender produced the expected default color outside the valid UV range, while Metal showed white. Inspecting MetalTextureHandler.mm showed the Metal backend maps constant to sampler border color and chooses only black or white based on defaultColor[0], which cannot represent arbitrary defaults (such as purple in this example.(

Screenshot 2026-05-07 at 2 07 00 PM

Validation

Rendered the focused address-mode samples through materialx-metal:

pnpm cli render --materials "re:image_addressmode_(constant|clamp|periodic|mirror)$" --renderers materialx-metal

All 4 renders succeeded, and the constant-mode sample now shows the expected magenta default region.

Screenshot 2026-05-07 at 2 11 29 PM

@bhouston bhouston changed the title Fixes genmsl image node handling for MaterialX constant texture address Bug fix: genmsl image node handling for MaterialX constant texture address May 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant