|
If the
input_range has a min value of 0.0
and a max value of 1.0 it's range would be 1.0. If the
output_range has a min value of 0.2
and a max value of 0.8 it's range would be 0.6.
For a specific input value, represented by the red line, to be remapped to an
output value, represented by the blue line, the following must be true.
a/input_range
= b/output_range
Consequently, the value of b would be,
b = a/input_range
* output_range
A remapped value would be,
remapped = a/input_range
* output_range + output_min
For example, if the input value is 0.35 it's remapped output value would be,
remapped = 0.35/1.0 * 0.6 + 0.2
remapped = 0.41
Listing 1 uses the arithmetic shown above to implement a float remap shader.
|