LYGIA Shader Library

inputRange (lygia/v1.1.6/color/levels/inputRange)

Color input range adjustment similar to Levels adjusment tool in Photoshop Adapted from Romain Dura (http://mouaif.wordpress.com/?p=94)

Use:

levelsInputRange(<vec3|vec4> color, <float|vec3> minInput, <float|vec3> maxInput)

Check it on Github


#ifndef FNC_LEVELSINPUTRANGE
#define FNC_LEVELSINPUTRANGE
vec3 levelsInputRange(in vec3 v, in vec3 iMin, in vec3 iMax) { return min(max(v - iMin, vec3(0.)) / (iMax - iMin), vec3(1.)); }
vec4 levelsInputRange(in vec4 v, in vec3 iMin, in vec3 iMax) { return vec4(levelsInputRange(v.rgb, iMin, iMax), v.a); }
vec3 levelsInputRange(in vec3 v, in float iMin, in float iMax) { return levelsInputRange(v, vec3(iMin), vec3(iMax)); }
vec4 levelsInputRange(in vec4 v, in float iMin, in float iMax) { return vec4(levelsInputRange(v.rgb, iMin, iMax), v.a); }
#endif

Use:

levelsInputRange(<float3|float4> color, <float|float3> minInput, <float|float3> maxInput)

Check it on Github


#ifndef FNC_LEVELSINPUTRANGE
#define FNC_LEVELSINPUTRANGE
float3 levelsInputRange(in float3 color, in float3 minInput, in float3 maxInput) {
  return min(max(color - minInput, float3(0., 0., 0.)) / (maxInput - minInput), float3(1., 1., 1.));
}

float4 levelsInputRange(in float4 color, in float3 minInput, in float3 maxInput) {
  return float4(levelsInputRange(color.rgb, minInput, maxInput), color.a);
}

float3 levelsInputRange(in float3 color, in float minInput, in float maxInput) {
  return levelsInputRange(color, float3(minInput, minInput, minInput), float3(maxInput, maxInput, maxInput));
}

float4 levelsInputRange(in float4 color, in float minInput, in float maxInput) {
  return float4(levelsInputRange(color.rgb, minInput, maxInput), color.a);
}
#endif

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