LYGIA Shader Library

map (lygia/v1.1.6/math/map)

Map a v between one range to another.

Use:

map(<float|vec2|vec3|vec4> v, <float|vec2|vec3|vec4> inMin, <float|vec2|vec3|vec4> inMax, <float|vec2|vec3|vec4> outMin, <float|vec2|vec3|vec4> outMax)

Check it on Github


#ifndef FNC_MAP
#define FNC_MAP
float map(float v, float iMin, float iMax ) { return (v-iMin)/(iMax-iMin); }
vec2 map(vec2 v, vec2 iMin, vec2 iMax ) { return (v-iMin)/(iMax-iMin); }
vec3 map(vec3 v, vec3 iMin, vec3 iMax ) { return (v-iMin)/(iMax-iMin); }
vec4 map(vec4 v, vec4 iMin, vec4 iMax ) { return (v-iMin)/(iMax-iMin); }

float map(in float v, in float iMin, in float iMax, in float oMin, in float oMax) { return oMin + (oMax - oMin) * (v - iMin) / (iMax - iMin); }
vec2 map(in vec2 v, in vec2 iMin, in vec2 iMax, in vec2 oMin, in vec2 oMax) { return oMin + (oMax - oMin) * (v - iMin) / (iMax - iMin); }
vec3 map(in vec3 v, in vec3 iMin, in vec3 iMax, in vec3 oMin, in vec3 oMax) { return oMin + (oMax - oMin) * (v - iMin) / (iMax - iMin); }
vec4 map(in vec4 v, in vec4 iMin, in vec4 iMax, in vec4 oMin, in vec4 oMax) { return oMin + (oMax - oMin) * (v - iMin) / (iMax - iMin); }
#endif

Use:

map(<float|float2|float3|float4> value, <float|float2|float3|float4> inMin, <float|float2|float3|float4> inMax, <float|float2|float3|float4> outMin, <float|float2|float3|float4> outMax)

Check it on Github


#ifndef FNC_MAP
#define FNC_MAP

float map( float value, float inMin, float inMax ) { return (value-inMin)/(inMax-inMin); }
float2 map( float2 value, float2 inMin, float2 inMax ) { return (value-inMin)/(inMax-inMin); }
float3 map( float3 value, float3 inMin, float3 inMax ) { return (value-inMin)/(inMax-inMin); }
float4 map( float4 value, float4 inMin, float4 inMax ) { return (value-inMin)/(inMax-inMin); }

float map(in float value, in float inMin, in float inMax, in float outMin, in float outMax) {
    return outMin + (outMax - outMin) * (value - inMin) / (inMax - inMin);
}

float2 map(in float2 value, in float2 inMin, in float2 inMax, in float2 outMin, in float2 outMax) {
    return outMin + (outMax - outMin) * (value - inMin) / (inMax - inMin);
}

float3 map(in float3 value, in float3 inMin, in float3 inMax, in float3 outMin, in float3 outMax) {
    return outMin + (outMax - outMin) * (value - inMin) / (inMax - inMin);
}

float4 map(in float4 value, in float4 inMin, in float4 inMax, in float4 outMin, in float4 outMax) {
    return outMin + (outMax - outMin) * (value - inMin) / (inMax - inMin);
}

#endif

Dependencies:

Use:

map(<float|float2|float3|float4> value, <float|float2|float3|float4> inMin, <float|float2|float3|float4> inMax, <float|float2|float3|float4> outMin, <float|float2|float3|float4> outMax)

Check it on Github



#ifndef FNC_MAP
#define FNC_MAP

inline __host__ __device__ float map( float value, float inMin, float inMax ) { return (value-inMin)/(inMax-inMin); }
inline __host__ __device__ float2 map( float2 value, float2 inMin, float2 inMax ) { return (value-inMin)/(inMax-inMin); }
inline __host__ __device__ float3 map( float3 value, float3 inMin, float3 inMax ) { return (value-inMin)/(inMax-inMin); }
inline __host__ __device__ float4 map( float4 value, float4 inMin, float4 inMax ) { return (value-inMin)/(inMax-inMin); }

inline __host__ __device__ float map(float value, float inMin, float inMax, float outMin, float outMax) {
  return outMin + (outMax - outMin) * (value - inMin) / (inMax - inMin);
}

inline __host__ __device__ float2 map(float2 value, float2 inMin, float2 inMax, float2 outMin, float2 outMax) {
  return outMin + (outMax - outMin) * (value - inMin) / (inMax - inMin);
}

inline __host__ __device__ float3 map(float3 value, float3 inMin, float3 inMax, float3 outMin, float3 outMax) {
  return outMin + (outMax - outMin) * (value - inMin) / (inMax - inMin);
}

inline __host__ __device__ float4 map(float4 value, float4 inMin, float4 inMax, float4 outMin, float4 outMax) {
  return outMin + (outMax - outMin) * (value - inMin) / (inMax - inMin);
}

#endif

Examples

LYGIA is dual-licensed under the Prosperity License and the Patron License for sponsors and contributors.

Sponsors and contributors are automatically added to the Patron License and they can ignore the any non-commercial rule of the Prosperity Licensed software (please take a look to the exception).

It's also possible to get a permanent comercial license hook to a single and specific version of LYGIA.

Get the latest news and releases

Sign up for the news letter bellow, joing the LYGIA's channel on Discord or follow the Github repository