js
function map (value, fromMin, fromMax, toMin, toMax){ return (value - fromMin) / (fromMax - fromMin) * (toMax - toMin) + toMin; }
glsl
float map (float value, float fromMin, float fromMax, float toMin, float toMax){ if(value<fromMin)value=fromMin; if(value>fromMax)value=fromMax; return (value - fromMin) / (fromMax - fromMin) * (toMax - toMin) + toMin; }