Skip to content

Bug fix: smoothstep should emulate glsl behavior in degenerate cases#2915

Open
bhouston wants to merge 2 commits into
AcademySoftwareFoundation:mainfrom
bhouston:fix-smoothstep-generate-osl
Open

Bug fix: smoothstep should emulate glsl behavior in degenerate cases#2915
bhouston wants to merge 2 commits into
AcademySoftwareFoundation:mainfrom
bhouston:fix-smoothstep-generate-osl

Conversation

@bhouston
Copy link
Copy Markdown
Contributor

Like most of my PRs I noticed via https://material-fidelity.ben3d.ca that smooth step when the bounds are inverted does not replicate glsl behaviour. This PR fixes that.

Summary

Update the float smoothstep implementation in genosl to handle degenerate/inverted bounds explicitly.

  • ND_smoothstep_float now uses:
    • normal smoothstep(low, high, in) when high > low
    • a deterministic fallback when high <= low: hard step at high (in < high ? 0.0 : 1.0)

Why

For inverted bounds, smoothstep behavior can diverge across backends due to undefined/implementation-dependent handling. This caused visible mismatch in materialx-osl for degenerate node tests.

Making the fallback explicit in genosl improves determinism and cross-renderer consistency for these edge cases.

Validation

Renders from OSL, Metal and GLSL now match:

Screenshot 2026-05-11 at 12 38 10 PM

bhouston added 2 commits May 11, 2026 12:36
Apply the inverted/degenerate smoothstep fallback component-wise for vector2, vector3, and vector4 to match the float fix across all smoothstep nodedef variants.
@jstone-lucasfilm
Copy link
Copy Markdown
Member

See #2914 (comment) for recommendations on resolving this category of undefined behaviors through new specification proposals, so that our per-language implementations have an unambiguous reference to match.

@tdavidovicNV
Copy link
Copy Markdown
Contributor

fwiw, there is already a doc change proposal for this, but old by now: AcademySoftwareFoundation/OpenShadingLanguage#1851

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.

3 participants