Skip to content

Bug fix: guard asin/acos inputs outside [-1, 1] in osl#2913

Open
bhouston wants to merge 2 commits into
AcademySoftwareFoundation:mainfrom
bhouston:fix-acos-asin-out-of-bounds-osl
Open

Bug fix: guard asin/acos inputs outside [-1, 1] in osl#2913
bhouston wants to merge 2 commits into
AcademySoftwareFoundation:mainfrom
bhouston:fix-acos-asin-out-of-bounds-osl

Conversation

@bhouston
Copy link
Copy Markdown
Contributor

@bhouston bhouston commented May 11, 2026

I noticed via the https://material-fidelity.ben3d.ca test suite that out of range asin/acos values render different in MaterialX OSL as compared to the GLSL / Metal versions.

Before fix render comparisons:
Screenshot 2026-05-11 at 12 17 56 PM

This updates the genosl stdlib implementations for asin and acos to explicitly guard out-of-domain inputs so that the resulting value matches that produced by materialx glsl.

  • ND_asin_float: asin(in) -> mx_ternary(abs(in) <= 1.0, asin(in), 0.0)
  • ND_acos_float: acos(in) -> mx_ternary(abs(in) <= 1.0, acos(in), 0.0)

Why

In degenerate-but-valid authoring cases, some graphs intentionally feed values outside [-1, 1] into inverse trig nodes. Backend behavior for out-of-domain inputs can differ (NaN propagation, clamping, or undefined results), which causes renderer divergence.

This change makes genosl behavior explicit and deterministic for those edge cases, improving cross-backend consistency.

Validation

After fix render (I also fixed the blender-materialx-importer as well) comparisons:
Screenshot 2026-05-11 at 12 18 36 PM

Notes

This PR is intentionally minimal and only changes genosl source expressions for float asin/acos.

@bhouston bhouston changed the title Bug fix: guard asin/acos inputs outside [-1, 1] in oil Bug fix: guard asin/acos inputs outside [-1, 1] in osl May 11, 2026
Apply the out-of-range asin/acos fallback behavior component-wise for vector2, vector3, and vector4 so the fix is not limited to ND_asin_float and ND_acos_float.
@jstone-lucasfilm
Copy link
Copy Markdown
Member

jstone-lucasfilm commented May 12, 2026

@bhouston This is an important issue to address in the cross-language parity for MaterialX, but I don't think the solution is quite as simple as adding new guards in OSL.

See #2914 (comment) for thoughts on how we might proceed with this category of improvement.

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.

2 participants