Bug fix: make remap deterministic for degenerate input ranges#2916
Open
bhouston wants to merge 3 commits into
Open
Bug fix: make remap deterministic for degenerate input ranges#2916bhouston wants to merge 3 commits into
bhouston wants to merge 3 commits into
Conversation
ld-kerley
reviewed
May 11, 2026
| float mx_remap(float in, float inLow, float inHigh, float outLow, float outHigh, int doClamp) | ||
| { | ||
| float x = (in - inLow)/(inHigh-inLow); | ||
| float denom = inHigh - inLow; |
Contributor
There was a problem hiding this comment.
It's worth noting that in OSL "divide-by-zero" is not degenerate. It's defined to return 0.
Extend the remap degenerate-range fallback beyond float so color and vector variants also return outlow deterministically when inhigh and inlow collapse.
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Found via https://material-fidelity.ben3d.ca. remap is not deterministic for metal, glsl or osl with them producing different results:
Define deterministic behavior for float
remapwhen the input range is degenerate (inhigh == inlow).IM_remap_float_genglsl), add a guard:abs(inhigh - inlow) <= 1e-8, returnoutlowmx_remap(float, ...)), add the same guard before division.Why
remapwith a zero-width input range is undefined under the raw formula due to division by zero. Different backends were producing different results fornodes/remap_degeneratebecause of NaN/Inf handling differences.This change establishes a stable, cross-backend default:
outlowScope
genglslandgenosl.Validation
Re-rendered
nodes/remap_degeneratewith MaterialX renderers and they all match: