Skip to main content
1 of 3
Bálint
  • 15.1k
  • 2
  • 38
  • 57

map doesn't exist in neither glsl nor hlsl, but it's very easy to implement it.

The five arguments to a usual map function are

float map(float value, float min1, float max1, float min2, float max2) 

it takes the value and converts it from the range defined by min1 and max1 to the equivalent in the range defined by min2 and max2. The implementation would look like this:

// Convert the current value to a percentage // 0% - min1, 100% - max1 float perc = (value - min1) / (max1 - min1); // Do the same operation backwards with min2 and max2 float value = perc * (max2 - min2) + min2; 
Bálint
  • 15.1k
  • 2
  • 38
  • 57