OpenShadingLanguage icon indicating copy to clipboard operation
OpenShadingLanguage copied to clipboard

remap function included in the std library

Open emkkla opened this issue 1 year ago • 9 comments

The need for a remap() function (also called efit() in VEX) is very common in shading, and it would be appreciated if the standard library included it natively.

So far, of course, we can remap vectors or floats by simply defining the function manually:

vector vectorRemap(vector input, vector minIn, vector maxIn, vector minOut, vector maxOut) {
    return minOut + (input - minIn) * (maxOut - minOut) / (maxIn - minIn);
}
float floatRemap(float input, float minIn, float maxIn, float minOut, float maxOut) {
    return minOut + (input - minIn) * (maxOut - minOut) / (maxIn - minIn);
}

But, having it part of the std would simplify code and ensure a proper implementation:

type remap(type input, type minIn, type maxIn, type minOut, type maxOut)

emkkla avatar Nov 05 '24 18:11 emkkla