Created
November 2, 2018 11:22
-
-
Save mattdesl/cb70225b237c82d2479532bc0464cb3c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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