Skip to content

Instantly share code, notes, and snippets.

@rutvik110
Forked from mattdesl/lerp.glsl
Created October 15, 2022 18:43
Show Gist options
  • Save rutvik110/eb31409cd6c7830a7ad10fefa0e05e6a to your computer and use it in GitHub Desktop.
Save rutvik110/eb31409cd6c7830a7ad10fefa0e05e6a to your computer and use it in GitHub Desktop.
#pragma glslify: range = require('glsl-range');
void main () {
// Your incoming value
float x = 25.0;
// Map value to 0..1 domain
// (no need if x is already in 0..1 range)
float min = 10.0;
float max = 100.0;
float t = range(min, max, x);
// Now linear interpolate to new domain
float outMin = 0.25;
float outMax = 0.75;
float result = mix(outMin, outMax, t);
// Or, linear scale from one color to another
vec3 colorA = vec3(0.15, 0.5, 1.0);
vec3 colorB = vec3(0.5, 0.0, 0.25);
vec3 color = mix(colorA, colorB, t);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment